diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index de2332125f5..d10576db9ff 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1548,8 +1548,7 @@ void Viewport::_gui_show_tooltip() { gui.tooltip_popup->child_controls_changed(); } -bool Viewport::_gui_call_input(Control *p_control, const Ref &p_input) { - bool stopped = false; +void Viewport::_gui_call_input(Control *p_control, const Ref &p_input) { Ref ev = p_input; // Returns true if an event should be impacted by a control's mouse filter. @@ -1573,19 +1572,15 @@ bool Viewport::_gui_call_input(Control *p_control, const Ref &p_inpu if (!control->is_inside_tree() || control->is_set_as_top_level()) { break; } - if (gui.key_event_accepted) { - stopped = true; - break; - } if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP && is_pointer_event && !(is_scroll_event && control->data.force_pass_scroll_events)) { // 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 - stopped = true; + set_input_as_handled(); break; } } if (is_input_handled()) { - // Break after Physics Picking in SubViewport. + // Break when the event is set to handled in a child Control node or after physics picking in SubViewport. break; } @@ -1596,7 +1591,6 @@ bool Viewport::_gui_call_input(Control *p_control, const Ref &p_inpu ev = ev->xformed_by(ci->get_transform()); // Transform event upwards. ci = ci->get_parent_item(); } - return stopped; } void Viewport::_gui_call_notification(Control *p_control, int p_what) { @@ -1736,8 +1730,6 @@ void Viewport::_gui_input_event(Ref p_event) { Ref mb = p_event; if (mb.is_valid()) { - gui.key_event_accepted = false; - Point2 mpos = mb->get_position(); if (mb->is_pressed()) { MouseButtonMask button_mask = mouse_button_to_mask(mb->get_button_index()); @@ -1799,9 +1791,8 @@ void Viewport::_gui_input_event(Ref p_event) { } } - bool stopped = gui.mouse_focus && gui.mouse_focus->can_process() && _gui_call_input(gui.mouse_focus, mb); - if (stopped) { - set_input_as_handled(); + if (gui.mouse_focus && gui.mouse_focus->can_process()) { + _gui_call_input(gui.mouse_focus, mb); } if (gui.dragging && mb->get_button_index() == MouseButton::LEFT) { @@ -1835,16 +1826,14 @@ void Viewport::_gui_input_event(Ref p_event) { gui.mouse_focus = nullptr; } - bool stopped = mouse_focus && mouse_focus->can_process() && _gui_call_input(mouse_focus, mb); - if (stopped) { - set_input_as_handled(); + if (mouse_focus && mouse_focus->can_process()) { + _gui_call_input(mouse_focus, mb); } } } Ref mm = p_event; if (mm.is_valid()) { - gui.key_event_accepted = false; Point2 mpos = mm->get_position(); // Drag & drop. @@ -1979,9 +1968,8 @@ void Viewport::_gui_input_event(Ref p_event) { ds_cursor_shape = (DisplayServer::CursorShape)cursor_shape; - bool stopped = over->can_process() && _gui_call_input(over, mm); - if (stopped) { - set_input_as_handled(); + if (over->can_process()) { + _gui_call_input(over, mm); } } @@ -2097,20 +2085,15 @@ void Viewport::_gui_input_event(Ref p_event) { Control *over = gui_find_control(pos); if (over) { gui.touch_focus[touch_index] = over->get_instance_id(); - bool stopped = false; if (over->can_process()) { touch_event = touch_event->xformed_by(Transform2D()); // Make a copy. pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos); touch_event->set_position(pos); - stopped = _gui_call_input(over, touch_event); - } - if (stopped) { - set_input_as_handled(); + _gui_call_input(over, touch_event); } return; } } else { - bool stopped = false; ObjectID control_id = gui.touch_focus[touch_index]; Control *over = control_id.is_valid() ? Object::cast_to(ObjectDB::get_instance(control_id)) : nullptr; if (over && over->can_process()) { @@ -2118,10 +2101,7 @@ void Viewport::_gui_input_event(Ref p_event) { pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos); touch_event->set_position(pos); - stopped = _gui_call_input(over, touch_event); - } - if (stopped) { - set_input_as_handled(); + _gui_call_input(over, touch_event); } gui.touch_focus.erase(touch_index); return; @@ -2130,23 +2110,17 @@ void Viewport::_gui_input_event(Ref p_event) { Ref gesture_event = p_event; if (gesture_event.is_valid()) { - gui.key_event_accepted = false; - _gui_cancel_tooltip(); Size2 pos = gesture_event->get_position(); Control *over = gui_find_control(pos); if (over) { - bool stopped = false; if (over->can_process()) { gesture_event = gesture_event->xformed_by(Transform2D()); // Make a copy. pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos); gesture_event->set_position(pos); - stopped = _gui_call_input(over, gesture_event); - } - if (stopped) { - set_input_as_handled(); + _gui_call_input(over, gesture_event); } return; } @@ -2161,7 +2135,6 @@ void Viewport::_gui_input_event(Ref p_event) { over = gui_find_control(drag_event->get_position()); } if (over) { - bool stopped = false; if (over->can_process()) { Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse(); Size2 pos = localizer.xform(drag_event->get_position()); @@ -2174,12 +2147,9 @@ void Viewport::_gui_input_event(Ref p_event) { drag_event->set_relative(rel); drag_event->set_position(pos); - stopped = _gui_call_input(over, drag_event); + _gui_call_input(over, drag_event); } - if (stopped) { - set_input_as_handled(); - } return; } } @@ -2208,13 +2178,11 @@ void Viewport::_gui_input_event(Ref p_event) { } if (gui.key_focus) { - gui.key_event_accepted = false; if (gui.key_focus->can_process()) { gui.key_focus->_call_gui_input(p_event); } - if (gui.key_event_accepted) { - set_input_as_handled(); + if (is_input_handled()) { return; } } @@ -2558,7 +2526,6 @@ void Viewport::_gui_control_grab_focus(Control *p_control) { } void Viewport::_gui_accept_event() { - gui.key_event_accepted = true; if (is_inside_tree()) { set_input_as_handled(); } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index faa36851e98..ee5c85614d8 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -350,7 +350,6 @@ private: struct GUI { bool mouse_in_viewport = false; - bool key_event_accepted = false; HashMap touch_focus; Control *mouse_focus = nullptr; Control *mouse_click_grabber = nullptr; @@ -401,7 +400,7 @@ private: bool disable_input = false; - bool _gui_call_input(Control *p_control, const Ref &p_input); + void _gui_call_input(Control *p_control, const Ref &p_input); void _gui_call_notification(Control *p_control, int p_what); void _gui_sort_roots();