From 1e6fa5d1a553fdf76840762024420fba3a720e70 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Sun, 3 Feb 2019 02:24:05 +0100 Subject: Fixed shortcut events in BaseButton (now acts the same as ui_accept action) --- scene/gui/base_button.cpp | 75 ++++++++++++++++++++++++----------------------- scene/gui/base_button.h | 2 ++ 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index fadf5e432c..52fcea2a71 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -61,37 +61,7 @@ void BaseButton::_gui_input(Ref p_event) { bool button_masked = mouse_button.is_valid() && ((1 << (mouse_button->get_button_index() - 1)) & button_mask) > 0; if (button_masked || ui_accept) { - if (p_event->is_pressed()) { - status.press_attempt = true; - status.pressing_inside = true; - emit_signal("button_down"); - } - - if (status.press_attempt && status.pressing_inside) { - if (toggle_mode) { - if ((p_event->is_pressed() && action_mode == ACTION_MODE_BUTTON_PRESS) || (!p_event->is_pressed() && action_mode == ACTION_MODE_BUTTON_RELEASE)) { - if (action_mode == ACTION_MODE_BUTTON_PRESS) { - status.press_attempt = false; - status.pressing_inside = false; - } - status.pressed = !status.pressed; - _unpress_group(); - _toggled(status.pressed); - _pressed(); - } - } else { - if (!p_event->is_pressed()) { - _pressed(); - } - } - } - - if (!p_event->is_pressed()) { // pressed state should be correct with button_up signal - emit_signal("button_up"); - status.press_attempt = false; - } - - update(); + on_action_event(p_event); return; } @@ -177,6 +147,41 @@ void BaseButton::_toggled(bool p_pressed) { emit_signal("toggled", p_pressed); } +void BaseButton::on_action_event(Ref p_event) { + + if (p_event->is_pressed()) { + status.press_attempt = true; + status.pressing_inside = true; + emit_signal("button_down"); + } + + if (status.press_attempt && status.pressing_inside) { + if (toggle_mode) { + if ((p_event->is_pressed() && action_mode == ACTION_MODE_BUTTON_PRESS) || (!p_event->is_pressed() && action_mode == ACTION_MODE_BUTTON_RELEASE)) { + if (action_mode == ACTION_MODE_BUTTON_PRESS) { + status.press_attempt = false; + status.pressing_inside = false; + } + status.pressed = !status.pressed; + _unpress_group(); + _toggled(status.pressed); + _pressed(); + } + } else { + if (!p_event->is_pressed()) { + _pressed(); + } + } + } + + if (!p_event->is_pressed()) { // pressed state should be correct with button_up signal + emit_signal("button_up"); + status.press_attempt = false; + } + + update(); +} + void BaseButton::pressed() { } @@ -345,16 +350,12 @@ Ref BaseButton::get_shortcut() const { void BaseButton::_unhandled_input(Ref p_event) { - if (!is_disabled() && is_visible_in_tree() && p_event->is_pressed() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { + if (!is_disabled() && is_visible_in_tree() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)) return; //ignore because of modal window - if (is_toggle_mode()) { - set_pressed(!is_pressed()); // Also calls _toggled() internally. - } - - _pressed(); + on_action_event(p_event); } } diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index abb3f58d6b..a76e073668 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -74,6 +74,8 @@ private: void _pressed(); void _toggled(bool p_pressed); + void on_action_event(Ref p_event); + protected: virtual void pressed(); virtual void toggled(bool p_pressed); -- cgit v1.2.3