summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorPouleyKetchoupp <pouleyketchoup@gmail.com>2019-02-03 02:24:05 +0100
committerPouleyKetchoupp <pouleyketchoup@gmail.com>2019-06-20 09:13:23 +0200
commit1e6fa5d1a553fdf76840762024420fba3a720e70 (patch)
treeb79a504859c4427fdf47d2679a1ba0e906bbfb96 /scene/gui
parentd2f38dbb28053e47cd6a0f8b368ade5c19d5ca70 (diff)
Fixed shortcut events in BaseButton (now acts the same as ui_accept action)
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp75
-rw-r--r--scene/gui/base_button.h2
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<InputEvent> 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<InputEvent> 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<ShortCut> BaseButton::get_shortcut() const {
void BaseButton::_unhandled_input(Ref<InputEvent> 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<InputEvent> p_event);
+
protected:
virtual void pressed();
virtual void toggled(bool p_pressed);