diff options
Diffstat (limited to 'scene/gui/texture_frame.cpp')
| -rw-r--r-- | scene/gui/texture_frame.cpp | 112 |
1 files changed, 52 insertions, 60 deletions
diff --git a/scene/gui/texture_frame.cpp b/scene/gui/texture_frame.cpp index 278fff996..86c6cd6a6 100644 --- a/scene/gui/texture_frame.cpp +++ b/scene/gui/texture_frame.cpp @@ -31,67 +31,65 @@ void TextureFrame::_notification(int p_what) { - if (p_what==NOTIFICATION_DRAW) { + if (p_what == NOTIFICATION_DRAW) { if (texture.is_null()) return; - - switch(stretch_mode) { + switch (stretch_mode) { case STRETCH_SCALE_ON_EXPAND: { - Size2 s=expand?get_size():texture->get_size(); - draw_texture_rect(texture,Rect2(Point2(),s),false,modulate); + Size2 s = expand ? get_size() : texture->get_size(); + draw_texture_rect(texture, Rect2(Point2(), s), false, modulate); } break; case STRETCH_SCALE: { - draw_texture_rect(texture,Rect2(Point2(),get_size()),false,modulate); + draw_texture_rect(texture, Rect2(Point2(), get_size()), false, modulate); } break; case STRETCH_TILE: { - draw_texture_rect(texture,Rect2(Point2(),get_size()),true,modulate); + draw_texture_rect(texture, Rect2(Point2(), get_size()), true, modulate); } break; case STRETCH_KEEP: { - draw_texture_rect(texture,Rect2(Point2(),texture->get_size()),false,modulate); + draw_texture_rect(texture, Rect2(Point2(), texture->get_size()), false, modulate); } break; case STRETCH_KEEP_CENTERED: { - Vector2 ofs = (get_size() - texture->get_size())/2; - draw_texture_rect(texture,Rect2(ofs,texture->get_size()),false,modulate); + 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(); + 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(); + 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; + 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),false,modulate); + draw_texture_rect(texture, Rect2(ofs_x, ofs_y, tex_width, tex_height), false, modulate); } 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 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); + draw_texture_rect_region(texture, Rect2(Point2(), size), Rect2(ofs, size / scale), modulate); } break; } - } } @@ -104,35 +102,33 @@ Size2 TextureFrame::get_minimum_size() const { } void TextureFrame::_bind_methods() { + ObjectTypeDB::bind_method(_MD("set_texture", "texture"), &TextureFrame::set_texture); + ObjectTypeDB::bind_method(_MD("get_texture"), &TextureFrame::get_texture); + ObjectTypeDB::bind_method(_MD("set_modulate", "modulate"), &TextureFrame::set_modulate); + ObjectTypeDB::bind_method(_MD("get_modulate"), &TextureFrame::get_modulate); + ObjectTypeDB::bind_method(_MD("set_expand", "enable"), &TextureFrame::set_expand); + ObjectTypeDB::bind_method(_MD("has_expand"), &TextureFrame::has_expand); + ObjectTypeDB::bind_method(_MD("set_stretch_mode", "stretch_mode"), &TextureFrame::set_stretch_mode); + ObjectTypeDB::bind_method(_MD("get_stretch_mode"), &TextureFrame::get_stretch_mode); - ObjectTypeDB::bind_method(_MD("set_texture","texture"), & TextureFrame::set_texture ); - ObjectTypeDB::bind_method(_MD("get_texture"), & TextureFrame::get_texture ); - ObjectTypeDB::bind_method(_MD("set_modulate","modulate"), & TextureFrame::set_modulate ); - ObjectTypeDB::bind_method(_MD("get_modulate"), & TextureFrame::get_modulate ); - ObjectTypeDB::bind_method(_MD("set_expand","enable"), & TextureFrame::set_expand ); - ObjectTypeDB::bind_method(_MD("has_expand"), & TextureFrame::has_expand ); - ObjectTypeDB::bind_method(_MD("set_stretch_mode","stretch_mode"), & TextureFrame::set_stretch_mode ); - ObjectTypeDB::bind_method(_MD("get_stretch_mode"), & TextureFrame::get_stretch_mode ); - - 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,Keep Aspect Covered"), _SCS("set_stretch_mode"),_SCS("get_stretch_mode") ); + 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,Keep Aspect Covered"), _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 ); - BIND_CONSTANT( STRETCH_KEEP_ASPECT_COVERED ); + 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); + BIND_CONSTANT(STRETCH_KEEP_ASPECT_COVERED); } +void TextureFrame::set_texture(const Ref<Texture> &p_tex) { -void TextureFrame::set_texture(const Ref<Texture>& p_tex) { - - texture=p_tex; + texture = p_tex; update(); //if (texture.is_valid()) // texture->set_flags(texture->get_flags()&(~Texture::FLAG_REPEAT)); //remove repeat from texture, it looks bad in sprites @@ -144,21 +140,20 @@ Ref<Texture> TextureFrame::get_texture() const { return texture; } -void TextureFrame::set_modulate(const Color& p_tex) { +void TextureFrame::set_modulate(const Color &p_tex) { - modulate=p_tex; + modulate = p_tex; update(); } -Color TextureFrame::get_modulate() const{ +Color TextureFrame::get_modulate() const { return modulate; } - void TextureFrame::set_expand(bool p_expand) { - expand=p_expand; + expand = p_expand; update(); minimum_size_changed(); } @@ -169,7 +164,7 @@ bool TextureFrame::has_expand() const { void TextureFrame::set_stretch_mode(StretchMode p_mode) { - stretch_mode=p_mode; + stretch_mode = p_mode; update(); } @@ -180,14 +175,11 @@ TextureFrame::StretchMode TextureFrame::get_stretch_mode() const { TextureFrame::TextureFrame() { - - expand=false; - modulate=Color(1,1,1,1); + expand = false; + modulate = Color(1, 1, 1, 1); set_ignore_mouse(true); - stretch_mode=STRETCH_SCALE_ON_EXPAND; + stretch_mode = STRETCH_SCALE_ON_EXPAND; } - -TextureFrame::~TextureFrame() -{ +TextureFrame::~TextureFrame() { } |
