diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/base_button.cpp | 6 | ||||
-rw-r--r-- | scene/gui/control.cpp | 5 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 59 | ||||
-rw-r--r-- | scene/gui/popup_menu.h | 1 |
4 files changed, 34 insertions, 37 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 0f1681a24e..d765248cca 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -539,15 +539,15 @@ BaseButton::BaseButton() { set_focus_mode(FOCUS_ALL); enabled_focus_mode = FOCUS_ALL; action_mode = ACTION_MODE_BUTTON_RELEASE; +} + +BaseButton::~BaseButton() { if (button_group.is_valid()) { button_group->buttons.erase(this); } } -BaseButton::~BaseButton() { -} - void ButtonGroup::get_buttons(List<BaseButton *> *r_buttons) { for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) { diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 6419659741..979a65f455 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -861,6 +861,8 @@ Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName & class_name = ClassDB::get_parent_class_nocheck(class_name); } + class_name = type; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) @@ -869,8 +871,6 @@ Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName & theme_owner = NULL; } - class_name = type; - while (class_name != StringName()) { if (Theme::get_default()->has_stylebox(p_name, class_name)) return Theme::get_default()->get_stylebox(p_name, class_name); @@ -2155,6 +2155,7 @@ void Control::set_theme(const Ref<Theme> &p_theme) { data.theme = p_theme; if (!p_theme.is_null()) { + data.theme_owner = this; _propagate_theme_changed(this, this); } else { diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 276df827d5..d7987d4a19 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -189,6 +189,26 @@ void PopupMenu::_submenu_timeout() { submenu_over = -1; } +void PopupMenu::_scroll(float p_factor, const Point2 &p_over) { + + const float global_y = get_global_position().y; + + int vseparation = get_constant("vseparation"); + Ref<Font> font = get_font("font"); + + float dy = (vseparation + font->get_height()) * 3 * p_factor; + if (dy > 0 && global_y < 0) + dy = MIN(dy, -global_y - 1); + else if (dy < 0 && global_y + get_size().y > get_viewport_rect().size.y) + dy = -MIN(-dy, global_y + get_size().y - get_viewport_rect().size.y - 1); + set_position(get_position() + Vector2(0, dy)); + + Ref<InputEventMouseMotion> ie; + ie.instance(); + ie->set_position(p_over - Vector2(0, dy)); + _gui_input(ie); +} + void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; @@ -285,41 +305,11 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { case BUTTON_WHEEL_DOWN: { - if (get_global_position().y + get_size().y > get_viewport_rect().size.y) { - - int vseparation = get_constant("vseparation"); - Ref<Font> font = get_font("font"); - - Point2 pos = get_position(); - int s = (vseparation + font->get_height()) * 3; - pos.y -= (s * b->get_factor()); - set_position(pos); - - //update hover - Ref<InputEventMouseMotion> ie; - ie.instance(); - ie->set_position(b->get_position() + Vector2(0, s)); - _gui_input(ie); - } + _scroll(-b->get_factor(), b->get_position()); } break; case BUTTON_WHEEL_UP: { - if (get_global_position().y < 0) { - - int vseparation = get_constant("vseparation"); - Ref<Font> font = get_font("font"); - - Point2 pos = get_position(); - int s = (vseparation + font->get_height()) * 3; - pos.y += (s * b->get_factor()); - set_position(pos); - - //update hover - Ref<InputEventMouseMotion> ie; - ie.instance(); - ie->set_position(b->get_position() - Vector2(0, s)); - _gui_input(ie); - } + _scroll(b->get_factor(), b->get_position()); } break; case BUTTON_LEFT: { @@ -387,6 +377,11 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { update(); } } + + Ref<InputEventPanGesture> pan_gesture = p_event; + if (pan_gesture.is_valid()) { + _scroll(-pan_gesture->get_delta().y, pan_gesture->get_position()); + } } bool PopupMenu::has_point(const Point2 &p_point) const { diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index 321dae1bd2..60f36e95ec 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -84,6 +84,7 @@ class PopupMenu : public Popup { String _get_accel_text(int p_item) const; int _get_mouse_over(const Point2 &p_over) const; virtual Size2 get_minimum_size() const; + void _scroll(float p_factor, const Point2 &p_over); void _gui_input(const Ref<InputEvent> &p_event); void _activate_submenu(int over); void _submenu_timeout(); |