summaryrefslogtreecommitdiff
path: root/scene/gui/menu_button.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/menu_button.cpp')
-rw-r--r--scene/gui/menu_button.cpp56
1 files changed, 27 insertions, 29 deletions
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index 67a36240a2..786f23873e 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -36,23 +36,16 @@
void MenuButton::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
- if (!_is_focus_owner_in_shortcut_context()) {
+ if (disable_shortcuts) {
return;
}
- if (disable_shortcuts) {
+ if (p_event->is_pressed() && !p_event->is_echo() && !is_disabled() && is_visible_in_tree() && popup->activate_item_by_event(p_event, false)) {
+ accept_event();
return;
}
- if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event) || Object::cast_to<InputEventShortcut>(*p_event))) {
- if (!get_parent() || !is_visible_in_tree() || is_disabled()) {
- return;
- }
-
- if (popup->activate_item_by_event(p_event, false)) {
- accept_event();
- }
- }
+ Button::shortcut_input(p_event);
}
void MenuButton::_popup_visibility_changed(bool p_visible) {
@@ -64,19 +57,19 @@ void MenuButton::_popup_visibility_changed(bool p_visible) {
}
if (switch_on_hover) {
- Window *window = Object::cast_to<Window>(get_viewport());
- if (window) {
- mouse_pos_adjusted = window->get_position();
-
- if (window->is_embedded()) {
- Window *window_parent = Object::cast_to<Window>(window->get_parent()->get_viewport());
- while (window_parent) {
- if (!window_parent->is_embedded()) {
- mouse_pos_adjusted += window_parent->get_position();
+ Window *wnd = Object::cast_to<Window>(get_viewport());
+ if (wnd) {
+ mouse_pos_adjusted = wnd->get_position();
+
+ if (wnd->is_embedded()) {
+ Window *wnd_parent = Object::cast_to<Window>(wnd->get_parent()->get_viewport());
+ while (wnd_parent) {
+ if (!wnd_parent->is_embedded()) {
+ mouse_pos_adjusted += wnd_parent->get_position();
break;
}
- window_parent = Object::cast_to<Window>(window_parent->get_parent()->get_viewport());
+ wnd_parent = Object::cast_to<Window>(wnd_parent->get_parent()->get_viewport());
}
}
@@ -91,6 +84,18 @@ void MenuButton::pressed() {
return;
}
+ show_popup();
+}
+
+PopupMenu *MenuButton::get_popup() const {
+ return popup;
+}
+
+void MenuButton::show_popup() {
+ if (!get_viewport()) {
+ return;
+ }
+
emit_signal(SNAME("about_to_popup"));
Size2 size = get_size() * get_viewport()->get_canvas_transform().get_scale();
@@ -116,14 +121,6 @@ void MenuButton::pressed() {
popup->popup();
}
-void MenuButton::gui_input(const Ref<InputEvent> &p_event) {
- BaseButton::gui_input(p_event);
-}
-
-PopupMenu *MenuButton::get_popup() const {
- return popup;
-}
-
void MenuButton::set_switch_on_hover(bool p_enabled) {
switch_on_hover = p_enabled;
}
@@ -226,6 +223,7 @@ void MenuButton::_get_property_list(List<PropertyInfo> *p_list) const {
void MenuButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_popup"), &MenuButton::get_popup);
+ ClassDB::bind_method(D_METHOD("show_popup"), &MenuButton::show_popup);
ClassDB::bind_method(D_METHOD("set_switch_on_hover", "enable"), &MenuButton::set_switch_on_hover);
ClassDB::bind_method(D_METHOD("is_switch_on_hover"), &MenuButton::is_switch_on_hover);
ClassDB::bind_method(D_METHOD("set_disable_shortcuts", "disabled"), &MenuButton::set_disable_shortcuts);