diff options
-rw-r--r-- | scene/gui/base_button.cpp | 6 | ||||
-rw-r--r-- | scene/gui/base_button.h | 2 | ||||
-rw-r--r-- | scene/gui/menu_button.cpp | 4 | ||||
-rw-r--r-- | scene/gui/option_button.cpp | 3 |
4 files changed, 10 insertions, 5 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 4bc2fe6ed9..87a7355bb2 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -64,6 +64,8 @@ void BaseButton::gui_input(const Ref<InputEvent> &p_event) { bool button_masked = mouse_button.is_valid() && (mouse_button_to_mask(mouse_button->get_button_index()) & button_mask) != MouseButton::NONE; if (button_masked || ui_accept) { + was_mouse_pressed = button_masked; + on_action_event(p_event); return; } @@ -417,6 +419,10 @@ bool BaseButton::_is_focus_owner_in_shortcut_context() const { return ctx_node && vp_focus && (ctx_node == vp_focus || ctx_node->is_ancestor_of(vp_focus)); } +bool BaseButton::_was_pressed_by_mouse() const { + return was_mouse_pressed; +} + void BaseButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &BaseButton::set_pressed); ClassDB::bind_method(D_METHOD("is_pressed"), &BaseButton::is_pressed); diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index 68f26b13fd..c83b08aadf 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -49,6 +49,7 @@ private: MouseButton button_mask = MouseButton::MASK_LEFT; bool toggle_mode = false; bool shortcut_in_tooltip = true; + bool was_mouse_pressed = false; bool keep_pressed_outside = false; Ref<Shortcut> shortcut; ObjectID shortcut_context; @@ -81,6 +82,7 @@ protected: void _notification(int p_what); bool _is_focus_owner_in_shortcut_context() const; + bool _was_pressed_by_mouse() const; GDVIRTUAL0(_pressed) GDVIRTUAL1(_toggled, bool) diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index b11a51df44..a03db82332 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -99,9 +99,7 @@ void MenuButton::pressed() { popup->set_parent_rect(Rect2(Point2(gp - popup->get_position()), size)); // If not triggered by the mouse, start the popup with its first item selected. - if (popup->get_item_count() > 0 && - ((get_action_mode() == ActionMode::ACTION_MODE_BUTTON_PRESS && Input::get_singleton()->is_action_just_pressed("ui_accept")) || - (get_action_mode() == ActionMode::ACTION_MODE_BUTTON_RELEASE && Input::get_singleton()->is_action_just_released("ui_accept")))) { + if (popup->get_item_count() > 0 && !_was_pressed_by_mouse()) { popup->set_current_index(0); } diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index a5a6240e27..931dffe3bb 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -204,8 +204,7 @@ void OptionButton::pressed() { // If not triggered by the mouse, start the popup with the checked item selected. if (popup->get_item_count() > 0) { - if ((get_action_mode() == ActionMode::ACTION_MODE_BUTTON_PRESS && Input::get_singleton()->is_action_just_pressed("ui_accept")) || - (get_action_mode() == ActionMode::ACTION_MODE_BUTTON_RELEASE && Input::get_singleton()->is_action_just_released("ui_accept"))) { + if (!_was_pressed_by_mouse()) { popup->set_current_index(current > -1 ? current : 0); } else { popup->scroll_to_item(current > -1 ? current : 0); |