Skip to content

Commit dae536a

Browse files
committed
Merge pull request #120864 from syntaxerror247/button-press
Fix duplicated button press event on touch input
2 parents 73b66bb + 15ac72e commit dae536a

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

scene/gui/base_button.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,34 @@ void BaseButton::gui_input(const Ref<InputEvent> &p_event) {
6464
return;
6565
}
6666

67-
if (p_event->get_device() != InputEvent::DEVICE_ID_EMULATION) {
68-
Ref<InputEventScreenTouch> touch = p_event;
69-
if (touch.is_valid()) {
70-
if (status.touch_index == -1) {
71-
if (touch->is_pressed()) {
72-
status.touch_index = touch->get_index();
73-
status.press_attempt = true;
74-
status.pressing_inside = has_point(touch->get_position());
75-
on_action_event(p_event);
76-
}
77-
} else if (touch->get_index() == status.touch_index) {
78-
if (!touch->is_pressed()) {
79-
status.touch_index = -1;
80-
on_action_event(p_event);
81-
}
67+
if (p_event->get_device() == InputEvent::DEVICE_ID_EMULATION) {
68+
return;
69+
}
70+
71+
Ref<InputEventScreenTouch> touch = p_event;
72+
if (touch.is_valid()) {
73+
if (status.touch_index == -1) {
74+
if (touch->is_pressed()) {
75+
status.touch_index = touch->get_index();
76+
status.press_attempt = true;
77+
status.pressing_inside = has_point(touch->get_position());
78+
on_action_event(p_event);
79+
}
80+
} else if (touch->get_index() == status.touch_index) {
81+
if (!touch->is_pressed()) {
82+
status.touch_index = -1;
83+
on_action_event(p_event);
8284
}
8385
}
86+
}
8487

85-
Ref<InputEventScreenDrag> drag = p_event;
86-
if (drag.is_valid() && drag->get_index() == status.touch_index && status.press_attempt) {
87-
bool last_press_inside = status.pressing_inside;
88-
status.pressing_inside = has_point(drag->get_position());
88+
Ref<InputEventScreenDrag> drag = p_event;
89+
if (drag.is_valid() && drag->get_index() == status.touch_index && status.press_attempt) {
90+
bool last_press_inside = status.pressing_inside;
91+
status.pressing_inside = has_point(drag->get_position());
8992

90-
if (last_press_inside != status.pressing_inside) {
91-
queue_redraw();
92-
}
93+
if (last_press_inside != status.pressing_inside) {
94+
queue_redraw();
9395
}
9496
}
9597

0 commit comments

Comments
 (0)