aboutsummaryrefslogtreecommitdiff
path: root/scene/gui/texture_frame.cpp
diff options
context:
space:
mode:
authorgeequlim2017-02-04 14:26:50 +0800
committergeequlim2017-02-04 14:26:50 +0800
commit0c1c34ef22e50fd83747358de645ac021fba660d (patch)
tree2d6b2e335f46756ee830ddffd3deadb5036c2c20 /scene/gui/texture_frame.cpp
parent34b6caa43303c46f178e0375aa50bfaf5ac903e7 (diff)
downloadgodot-0c1c34ef22e50fd83747358de645ac021fba660d.tar.gz
godot-0c1c34ef22e50fd83747358de645ac021fba660d.tar.zst
godot-0c1c34ef22e50fd83747358de645ac021fba660d.zip
Add Keep Covered texture resize mode
Diffstat (limited to 'scene/gui/texture_frame.cpp')
-rw-r--r--scene/gui/texture_frame.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/scene/gui/texture_frame.cpp b/scene/gui/texture_frame.cpp
index 571aafdbf..bc30737cb 100644
--- a/scene/gui/texture_frame.cpp
+++ b/scene/gui/texture_frame.cpp
@@ -79,7 +79,17 @@ void TextureFrame::_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), modulate);
+ } break;
}
}
@@ -107,7 +117,7 @@ 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,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 );
@@ -116,7 +126,7 @@ void TextureFrame::_bind_methods() {
BIND_CONSTANT( STRETCH_KEEP_CENTERED );
BIND_CONSTANT( STRETCH_KEEP_ASPECT );
BIND_CONSTANT( STRETCH_KEEP_ASPECT_CENTERED );
-
+ BIND_CONSTANT( STRETCH_KEEP_ASPECT_COVERED );
}