diff options
Diffstat (limited to 'scene/gui/texture_button.cpp')
-rw-r--r-- | scene/gui/texture_button.cpp | 71 |
1 files changed, 34 insertions, 37 deletions
diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 5f2e4cf58e..6e86f0f299 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -33,33 +33,34 @@ #include <stdlib.h> Size2 TextureButton::get_minimum_size() const { - Size2 rscale = Control::get_minimum_size(); if (!expand) { if (normal.is_null()) { if (pressed.is_null()) { - if (hover.is_null()) - if (click_mask.is_null()) + if (hover.is_null()) { + if (click_mask.is_null()) { rscale = Size2(); - else + } else { rscale = click_mask->get_size(); - else + } + } else { rscale = hover->get_size(); - } else + } + } else { rscale = pressed->get_size(); + } - } else + } else { rscale = normal->get_size(); + } } return rscale.abs(); } bool TextureButton::has_point(const Point2 &p_point) const { - if (click_mask.is_valid()) { - Point2 point = p_point; Rect2 rect = Rect2(); Size2 mask_size = click_mask->get_size(); @@ -116,9 +117,7 @@ bool TextureButton::has_point(const Point2 &p_point) const { } void TextureButton::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_DRAW: { DrawMode draw_mode = get_draw_mode(); @@ -126,40 +125,44 @@ void TextureButton::_notification(int p_what) { switch (draw_mode) { case DRAW_NORMAL: { - - if (normal.is_valid()) + if (normal.is_valid()) { texdraw = normal; + } } break; case DRAW_HOVER_PRESSED: case DRAW_PRESSED: { - if (pressed.is_null()) { if (hover.is_null()) { - if (normal.is_valid()) + if (normal.is_valid()) { texdraw = normal; - } else + } + } else { texdraw = hover; + } - } else + } else { texdraw = pressed; + } } break; case DRAW_HOVER: { - if (hover.is_null()) { - if (pressed.is_valid() && is_pressed()) + if (pressed.is_valid() && is_pressed()) { texdraw = pressed; - else if (normal.is_valid()) + } else if (normal.is_valid()) { texdraw = normal; - } else + } + } else { texdraw = hover; + } } break; case DRAW_DISABLED: { - if (disabled.is_null()) { - if (normal.is_valid()) + if (normal.is_valid()) { texdraw = normal; - } else + } + } else { texdraw = disabled; + } } break; } @@ -232,7 +235,6 @@ void TextureButton::_notification(int p_what) { } void TextureButton::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_normal_texture", "texture"), &TextureButton::set_normal_texture); ClassDB::bind_method(D_METHOD("set_pressed_texture", "texture"), &TextureButton::set_pressed_texture); ClassDB::bind_method(D_METHOD("set_hover_texture", "texture"), &TextureButton::set_hover_texture); @@ -271,61 +273,56 @@ void TextureButton::_bind_methods() { } void TextureButton::set_normal_texture(const Ref<Texture2D> &p_normal) { - normal = p_normal; update(); minimum_size_changed(); } void TextureButton::set_pressed_texture(const Ref<Texture2D> &p_pressed) { - pressed = p_pressed; update(); } -void TextureButton::set_hover_texture(const Ref<Texture2D> &p_hover) { +void TextureButton::set_hover_texture(const Ref<Texture2D> &p_hover) { hover = p_hover; update(); } -void TextureButton::set_disabled_texture(const Ref<Texture2D> &p_disabled) { +void TextureButton::set_disabled_texture(const Ref<Texture2D> &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; update(); } Ref<Texture2D> TextureButton::get_normal_texture() const { - return normal; } -Ref<Texture2D> TextureButton::get_pressed_texture() const { +Ref<Texture2D> TextureButton::get_pressed_texture() const { return pressed; } -Ref<Texture2D> TextureButton::get_hover_texture() const { +Ref<Texture2D> TextureButton::get_hover_texture() const { return hover; } -Ref<Texture2D> TextureButton::get_disabled_texture() const { +Ref<Texture2D> TextureButton::get_disabled_texture() const { return disabled; } -Ref<BitMap> TextureButton::get_click_mask() const { +Ref<BitMap> TextureButton::get_click_mask() const { return click_mask; } Ref<Texture2D> TextureButton::get_focused_texture() const { - return focused; }; void TextureButton::set_focused_texture(const Ref<Texture2D> &p_focused) { - focused = p_focused; }; |