summaryrefslogtreecommitdiff
path: root/scene/gui/texture_button.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/texture_button.cpp')
-rw-r--r--scene/gui/texture_button.cpp141
1 files changed, 67 insertions, 74 deletions
diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp
index 2f10de054a..54f09cbf68 100644
--- a/scene/gui/texture_button.cpp
+++ b/scene/gui/texture_button.cpp
@@ -37,27 +37,27 @@ Size2 TextureButton::get_minimum_size() const {
if (pressed.is_null()) {
if (hover.is_null())
if (click_mask.is_null())
- rscale= Size2();
+ rscale = Size2();
else
- rscale= click_mask->get_size();
+ rscale = click_mask->get_size();
else
- rscale= hover->get_size();
+ rscale = hover->get_size();
} else
- rscale=pressed->get_size();
+ rscale = pressed->get_size();
} else
- rscale= normal->get_size();
+ rscale = normal->get_size();
}
return rscale.abs();
}
-bool TextureButton::has_point(const Point2& p_point) const {
+bool TextureButton::has_point(const Point2 &p_point) const {
if (click_mask.is_valid()) {
- Point2i p =p_point;
- if (p.x<0 || p.x>=click_mask->get_size().width || p.y<0 || p.y>=click_mask->get_size().height)
+ Point2i p = p_point;
+ if (p.x < 0 || p.x >= click_mask->get_size().width || p.y < 0 || p.y >= click_mask->get_size().height)
return false;
return click_mask->get_bit(p);
@@ -68,7 +68,7 @@ bool TextureButton::has_point(const Point2& p_point) const {
void TextureButton::_notification(int p_what) {
- switch( p_what ) {
+ switch (p_what) {
case NOTIFICATION_DRAW: {
DrawMode draw_mode = get_draw_mode();
@@ -79,37 +79,37 @@ void TextureButton::_notification(int p_what) {
case DRAW_NORMAL: {
if (normal.is_valid())
- texdraw=normal;
+ texdraw = normal;
} break;
case DRAW_PRESSED: {
if (pressed.is_null()) {
if (hover.is_null()) {
if (normal.is_valid())
- texdraw=normal;
+ texdraw = normal;
} else
- texdraw=hover;
+ texdraw = hover;
} else
- texdraw=pressed;
+ texdraw = pressed;
} break;
case DRAW_HOVER: {
if (hover.is_null()) {
if (pressed.is_valid() && is_pressed())
- texdraw=pressed;
+ texdraw = pressed;
else if (normal.is_valid())
- texdraw=normal;
+ texdraw = normal;
} else
- texdraw=hover;
+ texdraw = hover;
} break;
case DRAW_DISABLED: {
if (disabled.is_null()) {
if (normal.is_valid())
- texdraw=normal;
+ texdraw = normal;
} else
- texdraw=disabled;
+ texdraw = disabled;
} break;
}
@@ -131,12 +131,12 @@ void TextureButton::_notification(int p_what) {
tile = true;
break;
case STRETCH_KEEP_CENTERED:
- ofs = (get_size() - texdraw->get_size())/2;
+ ofs = (get_size() - texdraw->get_size()) / 2;
size = texdraw->get_size();
break;
case STRETCH_KEEP_ASPECT_CENTERED:
case STRETCH_KEEP_ASPECT: {
- Size2 _size=get_size();
+ Size2 _size = get_size();
float tex_width = texdraw->get_width() * _size.height / texdraw->get_height();
float tex_height = _size.height;
@@ -145,34 +145,33 @@ void TextureButton::_notification(int p_what) {
tex_height = texdraw->get_height() * tex_width / texdraw->get_width();
}
- 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;
}
size.width = tex_width;
size.height = tex_height;
} break;
- case STRETCH_KEEP_ASPECT_COVERED:{
+ case STRETCH_KEEP_ASPECT_COVERED: {
size = get_size();
Size2 tex_size = texdraw->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;
- tex_regin = Rect2(ofs, size/scale);
+ tex_regin = Rect2(ofs, size / scale);
} break;
}
}
if (tile)
- draw_texture_rect(texdraw,Rect2(ofs,size),tile);
+ draw_texture_rect(texdraw, Rect2(ofs, size), tile);
else
draw_texture_rect_region(texdraw, Rect2(ofs, size), tex_regin);
}
if (has_focus() && focused.is_valid()) {
Rect2 drect(Point2(), get_size());
- draw_texture_rect(focused,drect,false);
-
+ draw_texture_rect(focused, drect, false);
};
} break;
}
@@ -180,33 +179,33 @@ void TextureButton::_notification(int p_what) {
void TextureButton::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_normal_texture","texture:Texture"),&TextureButton::set_normal_texture);
- ClassDB::bind_method(D_METHOD("set_pressed_texture","texture:Texture"),&TextureButton::set_pressed_texture);
- ClassDB::bind_method(D_METHOD("set_hover_texture","texture:Texture"),&TextureButton::set_hover_texture);
- ClassDB::bind_method(D_METHOD("set_disabled_texture","texture:Texture"),&TextureButton::set_disabled_texture);
- ClassDB::bind_method(D_METHOD("set_focused_texture","texture:Texture"),&TextureButton::set_focused_texture);
- ClassDB::bind_method(D_METHOD("set_click_mask","mask:BitMap"),&TextureButton::set_click_mask);
- ClassDB::bind_method(D_METHOD("set_expand","p_expand"),&TextureButton::set_expand);
- ClassDB::bind_method(D_METHOD("set_stretch_mode","p_mode"),&TextureButton::set_stretch_mode);
-
- ClassDB::bind_method(D_METHOD("get_normal_texture:Texture"),&TextureButton::get_normal_texture);
- ClassDB::bind_method(D_METHOD("get_pressed_texture:Texture"),&TextureButton::get_pressed_texture);
- ClassDB::bind_method(D_METHOD("get_hover_texture:Texture"),&TextureButton::get_hover_texture);
- ClassDB::bind_method(D_METHOD("get_disabled_texture:Texture"),&TextureButton::get_disabled_texture);
- ClassDB::bind_method(D_METHOD("get_focused_texture:Texture"),&TextureButton::get_focused_texture);
- ClassDB::bind_method(D_METHOD("get_click_mask:BitMap"),&TextureButton::get_click_mask);
- ClassDB::bind_method(D_METHOD("get_expand"),&TextureButton::get_expand);
- ClassDB::bind_method(D_METHOD("get_stretch_mode"),&TextureButton::get_stretch_mode);
-
- ADD_GROUP("Textures","texture_");
- ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"texture_normal",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), "set_normal_texture", "get_normal_texture");
- ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"texture_pressed",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), "set_pressed_texture", "get_pressed_texture");
- ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"texture_hover",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), "set_hover_texture", "get_hover_texture");
- ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"texture_disabled",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), "set_disabled_texture", "get_disabled_texture");
- ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"texture_focused",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), "set_focused_texture", "get_focused_texture");
- ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"texture_click_mask",PROPERTY_HINT_RESOURCE_TYPE,"BitMap"), "set_click_mask", "get_click_mask") ;
- ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL,"expand",PROPERTY_HINT_RESOURCE_TYPE,"bool"), "set_expand", "get_expand") ;
- ADD_PROPERTYNO(PropertyInfo(Variant::INT,"stretch_mode",PROPERTY_HINT_ENUM,"Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), "set_stretch_mode", "get_stretch_mode");
+ ClassDB::bind_method(D_METHOD("set_normal_texture", "texture:Texture"), &TextureButton::set_normal_texture);
+ ClassDB::bind_method(D_METHOD("set_pressed_texture", "texture:Texture"), &TextureButton::set_pressed_texture);
+ ClassDB::bind_method(D_METHOD("set_hover_texture", "texture:Texture"), &TextureButton::set_hover_texture);
+ ClassDB::bind_method(D_METHOD("set_disabled_texture", "texture:Texture"), &TextureButton::set_disabled_texture);
+ ClassDB::bind_method(D_METHOD("set_focused_texture", "texture:Texture"), &TextureButton::set_focused_texture);
+ ClassDB::bind_method(D_METHOD("set_click_mask", "mask:BitMap"), &TextureButton::set_click_mask);
+ ClassDB::bind_method(D_METHOD("set_expand", "p_expand"), &TextureButton::set_expand);
+ ClassDB::bind_method(D_METHOD("set_stretch_mode", "p_mode"), &TextureButton::set_stretch_mode);
+
+ ClassDB::bind_method(D_METHOD("get_normal_texture:Texture"), &TextureButton::get_normal_texture);
+ ClassDB::bind_method(D_METHOD("get_pressed_texture:Texture"), &TextureButton::get_pressed_texture);
+ ClassDB::bind_method(D_METHOD("get_hover_texture:Texture"), &TextureButton::get_hover_texture);
+ ClassDB::bind_method(D_METHOD("get_disabled_texture:Texture"), &TextureButton::get_disabled_texture);
+ ClassDB::bind_method(D_METHOD("get_focused_texture:Texture"), &TextureButton::get_focused_texture);
+ ClassDB::bind_method(D_METHOD("get_click_mask:BitMap"), &TextureButton::get_click_mask);
+ ClassDB::bind_method(D_METHOD("get_expand"), &TextureButton::get_expand);
+ ClassDB::bind_method(D_METHOD("get_stretch_mode"), &TextureButton::get_stretch_mode);
+
+ ADD_GROUP("Textures", "texture_");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture_normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_normal_texture", "get_normal_texture");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture_pressed", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_pressed_texture", "get_pressed_texture");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture_hover", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_hover_texture", "get_hover_texture");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture_disabled", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_disabled_texture", "get_disabled_texture");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture_focused", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_focused_texture", "get_focused_texture");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture_click_mask", PROPERTY_HINT_RESOURCE_TYPE, "BitMap"), "set_click_mask", "get_click_mask");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "expand", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_expand", "get_expand");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "stretch_mode", PROPERTY_HINT_ENUM, "Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), "set_stretch_mode", "get_stretch_mode");
BIND_CONSTANT(STRETCH_SCALE);
BIND_CONSTANT(STRETCH_TILE);
@@ -215,39 +214,33 @@ void TextureButton::_bind_methods() {
BIND_CONSTANT(STRETCH_KEEP_ASPECT);
BIND_CONSTANT(STRETCH_KEEP_ASPECT_CENTERED);
BIND_CONSTANT(STRETCH_KEEP_ASPECT_COVERED);
-
}
+void TextureButton::set_normal_texture(const Ref<Texture> &p_normal) {
-void TextureButton::set_normal_texture(const Ref<Texture>& p_normal) {
-
- normal=p_normal;
+ normal = p_normal;
update();
minimum_size_changed();
-
}
-void TextureButton::set_pressed_texture(const Ref<Texture>& p_pressed) {
+void TextureButton::set_pressed_texture(const Ref<Texture> &p_pressed) {
- pressed=p_pressed;
+ pressed = p_pressed;
update();
-
}
-void TextureButton::set_hover_texture(const Ref<Texture>& p_hover) {
+void TextureButton::set_hover_texture(const Ref<Texture> &p_hover) {
- hover=p_hover;
+ hover = p_hover;
update();
-
}
-void TextureButton::set_disabled_texture(const Ref<Texture>& p_disabled) {
+void TextureButton::set_disabled_texture(const Ref<Texture> &p_disabled) {
- disabled=p_disabled;
+ disabled = p_disabled;
update();
-
}
-void TextureButton::set_click_mask(const Ref<BitMap>& p_click_mask) {
+void TextureButton::set_click_mask(const Ref<BitMap> &p_click_mask) {
- click_mask=p_click_mask;
+ click_mask = p_click_mask;
update();
}
@@ -277,7 +270,7 @@ Ref<Texture> TextureButton::get_focused_texture() const {
return focused;
};
-void TextureButton::set_focused_texture(const Ref<Texture>& p_focused) {
+void TextureButton::set_focused_texture(const Ref<Texture> &p_focused) {
focused = p_focused;
};