From 8836f2160ab3a501ca35bc4ac753557ca2a6b611 Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Thu, 31 Mar 2022 11:53:47 +0200 Subject: [PATCH] Move call of `push_unhandled_input` from `Window` to `Viewport` This solves the problem, that mouse events get sent to SubViewports even if they are outside of the visible area of the SubViewport. This changes makes SubViewportContainer::unhandled_input redundand. Shortcut Events now need to be distributed via push_input, in order for them to be able to reach SubViewports. --- doc/classes/Viewport.xml | 4 ++++ editor/editor_command_palette.cpp | 4 ++-- scene/gui/subviewport_container.cpp | 28 ---------------------------- scene/gui/subviewport_container.h | 1 - scene/main/viewport.cpp | 4 ++++ scene/main/window.cpp | 4 ---- 6 files changed, 10 insertions(+), 35 deletions(-) diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index b7d41f41e40..7538dba201c 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -158,7 +158,11 @@ Calling this method will propagate calls to child nodes for following methods in the given order: - [method Node._input] - [method Control._gui_input] for [Control] nodes + - [method Node._shortcut_input] + - [method Node._unhandled_input] + - [method Node._unhandled_key_input] If an earlier method marks the input as handled via [method set_input_as_handled], any later method in this list will not be called. + If none of the methods handle the event and [member physics_object_picking] is [code]true[/code], the event is used for physics object picking. diff --git a/editor/editor_command_palette.cpp b/editor/editor_command_palette.cpp index 1c598277dda..77ae3e026c3 100644 --- a/editor/editor_command_palette.cpp +++ b/editor/editor_command_palette.cpp @@ -256,7 +256,7 @@ void EditorCommandPalette::register_shortcuts_as_command() { ev.instantiate(); ev->set_shortcut(shortcut); String shortcut_text = String(shortcut->get_as_text()); - add_command(command_name, E.key, callable_mp(EditorNode::get_singleton()->get_viewport(), &Viewport::push_unhandled_input), varray(ev, false), shortcut_text); + add_command(command_name, E.key, callable_mp(EditorNode::get_singleton()->get_viewport(), &Viewport::push_input), varray(ev, false), shortcut_text); } unregistered_shortcuts.clear(); @@ -277,7 +277,7 @@ Ref EditorCommandPalette::add_shortcut_command(const String &p_command ev.instantiate(); ev->set_shortcut(p_shortcut); String shortcut_text = String(p_shortcut->get_as_text()); - add_command(p_command, p_key, callable_mp(EditorNode::get_singleton()->get_viewport(), &Viewport::push_unhandled_input), varray(ev, false), shortcut_text); + add_command(p_command, p_key, callable_mp(EditorNode::get_singleton()->get_viewport(), &Viewport::push_input), varray(ev, false), shortcut_text); } else { const String key_name = String(p_key); const String command_name = String(p_command); diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp index f9e96a44edb..91058374869 100644 --- a/scene/gui/subviewport_container.cpp +++ b/scene/gui/subviewport_container.cpp @@ -221,33 +221,6 @@ bool SubViewportContainer::_is_propagated_in_gui_input(const Ref &p_ return false; } -void SubViewportContainer::unhandled_input(const Ref &p_event) { - ERR_FAIL_COND(p_event.is_null()); - - if (Engine::get_singleton()->is_editor_hint()) { - return; - } - - Transform2D xform = get_global_transform_with_canvas(); - - if (stretch) { - Transform2D scale_xf; - scale_xf.scale(Vector2(shrink, shrink)); - xform *= scale_xf; - } - - Ref ev = p_event->xformed_by(xform.affine_inverse()); - - for (int i = 0; i < get_child_count(); i++) { - SubViewport *c = Object::cast_to(get_child(i)); - if (!c || c->is_input_disabled()) { - continue; - } - - c->push_unhandled_input(ev); - } -} - void SubViewportContainer::add_child_notify(Node *p_child) { if (Object::cast_to(p_child)) { queue_redraw(); @@ -290,5 +263,4 @@ void SubViewportContainer::_bind_methods() { SubViewportContainer::SubViewportContainer() { set_process_input(true); - set_process_unhandled_input(true); } diff --git a/scene/gui/subviewport_container.h b/scene/gui/subviewport_container.h index c1a74e5b988..8e5f5d157db 100644 --- a/scene/gui/subviewport_container.h +++ b/scene/gui/subviewport_container.h @@ -55,7 +55,6 @@ public: virtual void input(const Ref &p_event) override; virtual void gui_input(const Ref &p_event) override; - virtual void unhandled_input(const Ref &p_event) override; void set_stretch_shrink(int p_shrink); int get_stretch_shrink() const; void recalc_force_viewport_sizes(); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 8cd57536bf0..d0dc53edc2a 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2837,6 +2837,10 @@ void Viewport::push_input(const Ref &p_event, bool p_local_coords) { _gui_cleanup_internal_state(ev); } + if (!is_input_handled()) { + push_unhandled_input(ev, true); + } + event_count++; } diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 5d3173a2a54..8137592e995 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -1368,10 +1368,6 @@ void Window::_window_input(const Ref &p_ev) { if (is_inside_tree()) { push_input(p_ev); } - - if (!is_input_handled() && is_inside_tree()) { - push_unhandled_input(p_ev); - } } void Window::_window_input_text(const String &p_text) {