summaryrefslogtreecommitdiff
path: root/scene/gui/texture_rect.cpp
diff options
context:
space:
mode:
authorgeequlim <geequlim@gmail.com>2017-02-09 22:46:35 +0800
committergeequlim <geequlim@gmail.com>2017-02-09 22:52:52 +0800
commitab375117ba4e0549fa0b893c3f96a166042f43b9 (patch)
treec5318c06de7b4be5c6acca5b990370b4bb1b0bfb /scene/gui/texture_rect.cpp
parentb87a232668d9f9f3b32c2fceb60bc5f6ef46df22 (diff)
Add STRETCH_KEEP_ASPECT_COVERED to TextureRect StretchMode
Make TextureButton to the same resize behavior with TextureRect
Diffstat (limited to 'scene/gui/texture_rect.cpp')
-rw-r--r--scene/gui/texture_rect.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp
index 6a4b59c5ec..74240fe98e 100644
--- a/scene/gui/texture_rect.cpp
+++ b/scene/gui/texture_rect.cpp
@@ -79,7 +79,15 @@ void TextureRect::_notification(int p_what) {
draw_texture_rect(texture,Rect2(ofs_x,ofs_y,tex_width,tex_height));
} break;
-
+ case STRETCH_KEEP_ASPECT_COVERED: {
+ Size2 size = get_size();
+ Size2 tex_size = texture->get_size();
+ Size2 scaleSize(size.width/tex_size.width, size.height/tex_size.height);
+ float scale = scaleSize.width > scaleSize.height? scaleSize.width : scaleSize.height;
+ Size2 scaledTexSize = tex_size * scale;
+ Point2 ofs = ((scaledTexSize - size) / scale).abs() / 2.0f;
+ draw_texture_rect_region(texture, Rect2(Point2(), size), Rect2(ofs, size/scale));
+ } break;
}
}
@@ -104,7 +112,7 @@ void TextureRect::_bind_methods() {
ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"),_SCS("get_texture") );
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,Keep Aspect,Keep Aspect 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,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), _SCS("set_stretch_mode"),_SCS("get_stretch_mode") );
BIND_CONSTANT( STRETCH_SCALE_ON_EXPAND );
BIND_CONSTANT( STRETCH_SCALE );
@@ -113,7 +121,7 @@ void TextureRect::_bind_methods() {
BIND_CONSTANT( STRETCH_KEEP_CENTERED );
BIND_CONSTANT( STRETCH_KEEP_ASPECT );
BIND_CONSTANT( STRETCH_KEEP_ASPECT_CENTERED );
-
+ BIND_CONSTANT( STRETCH_KEEP_ASPECT_COVERED );
}