Remove Useless Viewport::gui.key_input_accepted

This commit is contained in:
2750558108 2024-09-11 23:50:31 +08:00
parent 4788f54d97
commit ccc6e5d25f
2 changed files with 15 additions and 49 deletions

View file

@ -1548,8 +1548,7 @@ void Viewport::_gui_show_tooltip() {
gui.tooltip_popup->child_controls_changed(); gui.tooltip_popup->child_controls_changed();
} }
bool Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_input) { void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_input) {
bool stopped = false;
Ref<InputEvent> ev = p_input; Ref<InputEvent> ev = p_input;
// Returns true if an event should be impacted by a control's mouse filter. // 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<InputEvent> &p_inpu
if (!control->is_inside_tree() || control->is_set_as_top_level()) { if (!control->is_inside_tree() || control->is_set_as_top_level()) {
break; 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)) { 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 // 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; break;
} }
} }
if (is_input_handled()) { 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; break;
} }
@ -1596,7 +1591,6 @@ bool Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
ev = ev->xformed_by(ci->get_transform()); // Transform event upwards. ev = ev->xformed_by(ci->get_transform()); // Transform event upwards.
ci = ci->get_parent_item(); ci = ci->get_parent_item();
} }
return stopped;
} }
void Viewport::_gui_call_notification(Control *p_control, int p_what) { void Viewport::_gui_call_notification(Control *p_control, int p_what) {
@ -1736,8 +1730,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> mb = p_event; Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) { if (mb.is_valid()) {
gui.key_event_accepted = false;
Point2 mpos = mb->get_position(); Point2 mpos = mb->get_position();
if (mb->is_pressed()) { if (mb->is_pressed()) {
MouseButtonMask button_mask = mouse_button_to_mask(mb->get_button_index()); MouseButtonMask button_mask = mouse_button_to_mask(mb->get_button_index());
@ -1799,9 +1791,8 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
} }
} }
bool stopped = gui.mouse_focus && gui.mouse_focus->can_process() && _gui_call_input(gui.mouse_focus, mb); if (gui.mouse_focus && gui.mouse_focus->can_process()) {
if (stopped) { _gui_call_input(gui.mouse_focus, mb);
set_input_as_handled();
} }
if (gui.dragging && mb->get_button_index() == MouseButton::LEFT) { if (gui.dragging && mb->get_button_index() == MouseButton::LEFT) {
@ -1835,16 +1826,14 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.mouse_focus = nullptr; gui.mouse_focus = nullptr;
} }
bool stopped = mouse_focus && mouse_focus->can_process() && _gui_call_input(mouse_focus, mb); if (mouse_focus && mouse_focus->can_process()) {
if (stopped) { _gui_call_input(mouse_focus, mb);
set_input_as_handled();
} }
} }
} }
Ref<InputEventMouseMotion> mm = p_event; Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) { if (mm.is_valid()) {
gui.key_event_accepted = false;
Point2 mpos = mm->get_position(); Point2 mpos = mm->get_position();
// Drag & drop. // Drag & drop.
@ -1979,9 +1968,8 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
ds_cursor_shape = (DisplayServer::CursorShape)cursor_shape; ds_cursor_shape = (DisplayServer::CursorShape)cursor_shape;
bool stopped = over->can_process() && _gui_call_input(over, mm); if (over->can_process()) {
if (stopped) { _gui_call_input(over, mm);
set_input_as_handled();
} }
} }
@ -2097,20 +2085,15 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Control *over = gui_find_control(pos); Control *over = gui_find_control(pos);
if (over) { if (over) {
gui.touch_focus[touch_index] = over->get_instance_id(); gui.touch_focus[touch_index] = over->get_instance_id();
bool stopped = false;
if (over->can_process()) { if (over->can_process()) {
touch_event = touch_event->xformed_by(Transform2D()); // Make a copy. touch_event = touch_event->xformed_by(Transform2D()); // Make a copy.
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos); pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
touch_event->set_position(pos); touch_event->set_position(pos);
stopped = _gui_call_input(over, touch_event); _gui_call_input(over, touch_event);
}
if (stopped) {
set_input_as_handled();
} }
return; return;
} }
} else { } else {
bool stopped = false;
ObjectID control_id = gui.touch_focus[touch_index]; ObjectID control_id = gui.touch_focus[touch_index];
Control *over = control_id.is_valid() ? Object::cast_to<Control>(ObjectDB::get_instance(control_id)) : nullptr; Control *over = control_id.is_valid() ? Object::cast_to<Control>(ObjectDB::get_instance(control_id)) : nullptr;
if (over && over->can_process()) { if (over && over->can_process()) {
@ -2118,10 +2101,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos); pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
touch_event->set_position(pos); touch_event->set_position(pos);
stopped = _gui_call_input(over, touch_event); _gui_call_input(over, touch_event);
}
if (stopped) {
set_input_as_handled();
} }
gui.touch_focus.erase(touch_index); gui.touch_focus.erase(touch_index);
return; return;
@ -2130,23 +2110,17 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Ref<InputEventGesture> gesture_event = p_event; Ref<InputEventGesture> gesture_event = p_event;
if (gesture_event.is_valid()) { if (gesture_event.is_valid()) {
gui.key_event_accepted = false;
_gui_cancel_tooltip(); _gui_cancel_tooltip();
Size2 pos = gesture_event->get_position(); Size2 pos = gesture_event->get_position();
Control *over = gui_find_control(pos); Control *over = gui_find_control(pos);
if (over) { if (over) {
bool stopped = false;
if (over->can_process()) { if (over->can_process()) {
gesture_event = gesture_event->xformed_by(Transform2D()); // Make a copy. gesture_event = gesture_event->xformed_by(Transform2D()); // Make a copy.
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos); pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
gesture_event->set_position(pos); gesture_event->set_position(pos);
stopped = _gui_call_input(over, gesture_event); _gui_call_input(over, gesture_event);
}
if (stopped) {
set_input_as_handled();
} }
return; return;
} }
@ -2161,7 +2135,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
over = gui_find_control(drag_event->get_position()); over = gui_find_control(drag_event->get_position());
} }
if (over) { if (over) {
bool stopped = false;
if (over->can_process()) { if (over->can_process()) {
Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse(); Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse();
Size2 pos = localizer.xform(drag_event->get_position()); Size2 pos = localizer.xform(drag_event->get_position());
@ -2174,12 +2147,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
drag_event->set_relative(rel); drag_event->set_relative(rel);
drag_event->set_position(pos); 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; return;
} }
} }
@ -2208,13 +2178,11 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
} }
if (gui.key_focus) { if (gui.key_focus) {
gui.key_event_accepted = false;
if (gui.key_focus->can_process()) { if (gui.key_focus->can_process()) {
gui.key_focus->_call_gui_input(p_event); gui.key_focus->_call_gui_input(p_event);
} }
if (gui.key_event_accepted) { if (is_input_handled()) {
set_input_as_handled();
return; return;
} }
} }
@ -2558,7 +2526,6 @@ void Viewport::_gui_control_grab_focus(Control *p_control) {
} }
void Viewport::_gui_accept_event() { void Viewport::_gui_accept_event() {
gui.key_event_accepted = true;
if (is_inside_tree()) { if (is_inside_tree()) {
set_input_as_handled(); set_input_as_handled();
} }

View file

@ -350,7 +350,6 @@ private:
struct GUI { struct GUI {
bool mouse_in_viewport = false; bool mouse_in_viewport = false;
bool key_event_accepted = false;
HashMap<int, ObjectID> touch_focus; HashMap<int, ObjectID> touch_focus;
Control *mouse_focus = nullptr; Control *mouse_focus = nullptr;
Control *mouse_click_grabber = nullptr; Control *mouse_click_grabber = nullptr;
@ -401,7 +400,7 @@ private:
bool disable_input = false; bool disable_input = false;
bool _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input); void _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input);
void _gui_call_notification(Control *p_control, int p_what); void _gui_call_notification(Control *p_control, int p_what);
void _gui_sort_roots(); void _gui_sort_roots();