summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-06-11 18:49:35 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-06-11 18:49:35 -0300
commitd5e2b59c84d8cc60dd042c1567cd1d74a654dc6e (patch)
tree63c41a5f0c5128dc4d6e45e262ca1a736ee3c908
parent9ddc13a5ccdfdb67950bb198a6e56868f64e8852 (diff)
Added options to keep scale and keep aspect centered to TextureFrame, closes #5114
-rw-r--r--scene/gui/texture_frame.cpp28
-rw-r--r--scene/gui/texture_frame.h3
2 files changed, 30 insertions, 1 deletions
diff --git a/scene/gui/texture_frame.cpp b/scene/gui/texture_frame.cpp
index 2fe8735fda..6b35d5da0a 100644
--- a/scene/gui/texture_frame.cpp
+++ b/scene/gui/texture_frame.cpp
@@ -60,6 +60,29 @@ void TextureFrame::_notification(int p_what) {
Vector2 ofs = (get_size() - texture->get_size())/2;
draw_texture_rect(texture,Rect2(ofs,texture->get_size()),false,modulate);
} break;
+ case STRETCH_KEEP_ASPECT_CENTERED:
+ case STRETCH_KEEP_ASPECT: {
+
+ Size2 size=get_size();
+ int tex_width = texture->get_width() * size.height / texture ->get_height();
+ int tex_height = size.height;
+
+ if (tex_width>size.width) {
+ tex_width=size.width;
+ tex_height=texture->get_height() * tex_width / texture->get_width();
+ }
+
+ int ofs_x = 0;
+ int ofs_y = 0;
+
+ if (stretch_mode==STRETCH_KEEP_ASPECT_CENTERED) {
+ ofs_x+=(size.width - tex_width)/2;
+ ofs_y+=(size.height - tex_height)/2;
+ }
+
+ draw_texture_rect(texture,Rect2(ofs_x,ofs_y,tex_width,tex_height));
+ } break;
+
}
@@ -104,13 +127,16 @@ void TextureFrame::_bind_methods() {
ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"),_SCS("get_texture") );
ADD_PROPERTYNO( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate") );
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "expand" ), _SCS("set_expand"),_SCS("has_expand") );
- ADD_PROPERTYNO( PropertyInfo( Variant::INT, "stretch_mode",PROPERTY_HINT_ENUM,"Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered"), _SCS("set_stretch_mode"),_SCS("get_stretch_mode") );
+ ADD_PROPERTYNO( PropertyInfo( Variant::INT, "stretch_mode",PROPERTY_HINT_ENUM,"Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered,Scale Keep Aspect,Scale Keep Aspect Centered"), _SCS("set_stretch_mode"),_SCS("get_stretch_mode") );
BIND_CONSTANT( STRETCH_SCALE_ON_EXPAND );
BIND_CONSTANT( STRETCH_SCALE );
BIND_CONSTANT( STRETCH_TILE );
BIND_CONSTANT( STRETCH_KEEP );
BIND_CONSTANT( STRETCH_KEEP_CENTERED );
+ BIND_CONSTANT( STRETCH_KEEP_ASPECT );
+ BIND_CONSTANT( STRETCH_KEEP_ASPECT_CENTERED );
+
}
diff --git a/scene/gui/texture_frame.h b/scene/gui/texture_frame.h
index a4acf588ea..0b47202532 100644
--- a/scene/gui/texture_frame.h
+++ b/scene/gui/texture_frame.h
@@ -43,6 +43,9 @@ public:
STRETCH_TILE,
STRETCH_KEEP,
STRETCH_KEEP_CENTERED,
+ STRETCH_KEEP_ASPECT,
+ STRETCH_KEEP_ASPECT_CENTERED,
+
};
private:
bool expand;