Skip to content

Commit 391849d

Browse files
committed
Merge pull request godotengine#96867 from L2750558108/remove-gui-key-event-accepted-shit
Remove useless `Viewport::gui.key_input_accepted`
2 parents 89cf031 + ccc6e5d commit 391849d

File tree

2 files changed

+15
-49
lines changed

2 files changed

+15
-49
lines changed

scene/main/viewport.cpp

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,8 +1550,7 @@ void Viewport::_gui_show_tooltip() {
15501550
gui.tooltip_popup->child_controls_changed();
15511551
}
15521552

1553-
bool Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_input) {
1554-
bool stopped = false;
1553+
void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_input) {
15551554
Ref<InputEvent> ev = p_input;
15561555

15571556
// Returns true if an event should be impacted by a control's mouse filter.
@@ -1575,19 +1574,15 @@ bool Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
15751574
if (!control->is_inside_tree() || control->is_set_as_top_level()) {
15761575
break;
15771576
}
1578-
if (gui.key_event_accepted) {
1579-
stopped = true;
1580-
break;
1581-
}
15821577
if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP && is_pointer_event && !(is_scroll_event && control->data.force_pass_scroll_events)) {
15831578
// Mouse, ScreenDrag and ScreenTouch events are stopped by default with MOUSE_FILTER_STOP, unless we have a scroll event and force_pass_scroll_events set to true
1584-
stopped = true;
1579+
set_input_as_handled();
15851580
break;
15861581
}
15871582
}
15881583

15891584
if (is_input_handled()) {
1590-
// Break after Physics Picking in SubViewport.
1585+
// Break when the event is set to handled in a child Control node or after physics picking in SubViewport.
15911586
break;
15921587
}
15931588

@@ -1598,7 +1593,6 @@ bool Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
15981593
ev = ev->xformed_by(ci->get_transform()); // Transform event upwards.
15991594
ci = ci->get_parent_item();
16001595
}
1601-
return stopped;
16021596
}
16031597

16041598
void Viewport::_gui_call_notification(Control *p_control, int p_what) {
@@ -1739,8 +1733,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
17391733

17401734
Ref<InputEventMouseButton> mb = p_event;
17411735
if (mb.is_valid()) {
1742-
gui.key_event_accepted = false;
1743-
17441736
Point2 mpos = mb->get_position();
17451737
if (mb->is_pressed()) {
17461738
MouseButtonMask button_mask = mouse_button_to_mask(mb->get_button_index());
@@ -1804,9 +1796,8 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
18041796
}
18051797
}
18061798

1807-
bool stopped = gui.mouse_focus && gui.mouse_focus->can_process() && _gui_call_input(gui.mouse_focus, mb);
1808-
if (stopped) {
1809-
set_input_as_handled();
1799+
if (gui.mouse_focus && gui.mouse_focus->can_process()) {
1800+
_gui_call_input(gui.mouse_focus, mb);
18101801
}
18111802

18121803
if (gui.dragging && mb->get_button_index() == MouseButton::LEFT) {
@@ -1840,16 +1831,14 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
18401831
gui.mouse_focus = nullptr;
18411832
}
18421833

1843-
bool stopped = mouse_focus && mouse_focus->can_process() && _gui_call_input(mouse_focus, mb);
1844-
if (stopped) {
1845-
set_input_as_handled();
1834+
if (mouse_focus && mouse_focus->can_process()) {
1835+
_gui_call_input(mouse_focus, mb);
18461836
}
18471837
}
18481838
}
18491839

18501840
Ref<InputEventMouseMotion> mm = p_event;
18511841
if (mm.is_valid()) {
1852-
gui.key_event_accepted = false;
18531842
Point2 mpos = mm->get_position();
18541843

18551844
// Drag & drop.
@@ -1986,9 +1975,8 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
19861975

19871976
ds_cursor_shape = (DisplayServer::CursorShape)cursor_shape;
19881977

1989-
bool stopped = over->can_process() && _gui_call_input(over, mm);
1990-
if (stopped) {
1991-
set_input_as_handled();
1978+
if (over->can_process()) {
1979+
_gui_call_input(over, mm);
19921980
}
19931981
}
19941982

@@ -2028,31 +2016,23 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
20282016
Control *over = gui_find_control(pos);
20292017
if (over) {
20302018
gui.touch_focus[touch_index] = over->get_instance_id();
2031-
bool stopped = false;
20322019
if (over->can_process()) {
20332020
touch_event = touch_event->xformed_by(Transform2D()); // Make a copy.
20342021
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
20352022
touch_event->set_position(pos);
2036-
stopped = _gui_call_input(over, touch_event);
2037-
}
2038-
if (stopped) {
2039-
set_input_as_handled();
2023+
_gui_call_input(over, touch_event);
20402024
}
20412025
return;
20422026
}
20432027
} else {
2044-
bool stopped = false;
20452028
ObjectID control_id = gui.touch_focus[touch_index];
20462029
Control *over = control_id.is_valid() ? Object::cast_to<Control>(ObjectDB::get_instance(control_id)) : nullptr;
20472030
if (over && over->can_process()) {
20482031
touch_event = touch_event->xformed_by(Transform2D()); // Make a copy.
20492032
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
20502033
touch_event->set_position(pos);
20512034

2052-
stopped = _gui_call_input(over, touch_event);
2053-
}
2054-
if (stopped) {
2055-
set_input_as_handled();
2035+
_gui_call_input(over, touch_event);
20562036
}
20572037
gui.touch_focus.erase(touch_index);
20582038
return;
@@ -2061,23 +2041,17 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
20612041

20622042
Ref<InputEventGesture> gesture_event = p_event;
20632043
if (gesture_event.is_valid()) {
2064-
gui.key_event_accepted = false;
2065-
20662044
_gui_cancel_tooltip();
20672045

20682046
Size2 pos = gesture_event->get_position();
20692047

20702048
Control *over = gui_find_control(pos);
20712049
if (over) {
2072-
bool stopped = false;
20732050
if (over->can_process()) {
20742051
gesture_event = gesture_event->xformed_by(Transform2D()); // Make a copy.
20752052
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
20762053
gesture_event->set_position(pos);
2077-
stopped = _gui_call_input(over, gesture_event);
2078-
}
2079-
if (stopped) {
2080-
set_input_as_handled();
2054+
_gui_call_input(over, gesture_event);
20812055
}
20822056
return;
20832057
}
@@ -2092,7 +2066,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
20922066
over = gui_find_control(drag_event->get_position());
20932067
}
20942068
if (over) {
2095-
bool stopped = false;
20962069
if (over->can_process()) {
20972070
Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse();
20982071
Size2 pos = localizer.xform(drag_event->get_position());
@@ -2105,12 +2078,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
21052078
drag_event->set_relative(rel);
21062079
drag_event->set_position(pos);
21072080

2108-
stopped = _gui_call_input(over, drag_event);
2081+
_gui_call_input(over, drag_event);
21092082
}
21102083

2111-
if (stopped) {
2112-
set_input_as_handled();
2113-
}
21142084
return;
21152085
}
21162086
}
@@ -2139,13 +2109,11 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
21392109
}
21402110

21412111
if (gui.key_focus) {
2142-
gui.key_event_accepted = false;
21432112
if (gui.key_focus->can_process()) {
21442113
gui.key_focus->_call_gui_input(p_event);
21452114
}
21462115

2147-
if (gui.key_event_accepted) {
2148-
set_input_as_handled();
2116+
if (is_input_handled()) {
21492117
return;
21502118
}
21512119
}
@@ -2493,7 +2461,6 @@ void Viewport::_gui_control_grab_focus(Control *p_control) {
24932461
}
24942462

24952463
void Viewport::_gui_accept_event() {
2496-
gui.key_event_accepted = true;
24972464
if (is_inside_tree()) {
24982465
set_input_as_handled();
24992466
}

scene/main/viewport.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ class Viewport : public Node {
350350

351351
struct GUI {
352352
bool mouse_in_viewport = false;
353-
bool key_event_accepted = false;
354353
HashMap<int, ObjectID> touch_focus;
355354
Control *mouse_focus = nullptr;
356355
Control *mouse_click_grabber = nullptr;
@@ -402,7 +401,7 @@ class Viewport : public Node {
402401

403402
bool disable_input = false;
404403

405-
bool _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input);
404+
void _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input);
406405
void _gui_call_notification(Control *p_control, int p_what);
407406

408407
void _gui_sort_roots();

0 commit comments

Comments
 (0)