Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless Viewport::gui.key_input_accepted #96867

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 14 additions & 47 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputEvent> &p_input) {
bool stopped = false;
void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_input) {
Ref<InputEvent> ev = p_input;

// Returns true if an event should be impacted by a control's mouse filter.
Expand All @@ -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()) {
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;
}

Expand All @@ -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.
ci = ci->get_parent_item();
}
return stopped;
}

void Viewport::_gui_call_notification(Control *p_control, int p_what) {
Expand Down Expand Up @@ -1736,8 +1730,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {

Ref<InputEventMouseButton> 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());
Expand Down Expand Up @@ -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 (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) {
Expand Down Expand Up @@ -1835,16 +1826,14 @@ void Viewport::_gui_input_event(Ref<InputEvent> 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<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
gui.key_event_accepted = false;
Point2 mpos = mm->get_position();

// Drag & drop.
Expand Down Expand Up @@ -1979,9 +1968,8 @@ void Viewport::_gui_input_event(Ref<InputEvent> 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);
}
}

Expand Down Expand Up @@ -2097,31 +2085,23 @@ void Viewport::_gui_input_event(Ref<InputEvent> 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<Control>(ObjectDB::get_instance(control_id)) : nullptr;
if (over && 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);
}
gui.touch_focus.erase(touch_index);
return;
Expand All @@ -2130,23 +2110,17 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {

Ref<InputEventGesture> 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;
}
Expand All @@ -2161,7 +2135,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> 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());
Expand All @@ -2174,12 +2147,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> 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;
}
}
Expand Down Expand Up @@ -2208,13 +2178,11 @@ void Viewport::_gui_input_event(Ref<InputEvent> 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;
}
}
Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 1 addition & 2 deletions scene/main/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ class Viewport : public Node {

struct GUI {
bool mouse_in_viewport = false;
bool key_event_accepted = false;
HashMap<int, ObjectID> touch_focus;
Control *mouse_focus = nullptr;
Control *mouse_click_grabber = nullptr;
Expand Down Expand Up @@ -401,7 +400,7 @@ class Viewport : public Node {

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_sort_roots();
Expand Down
Loading