Skip to content

Commit

Permalink
Merge pull request #57894 from Sauermann/fix-subviewport-1
Browse files Browse the repository at this point in the history
Fix unrestricted mouse-event propagation to SubViewports for Physics-Picking
  • Loading branch information
akien-mga committed May 9, 2023
2 parents 6980b2b + 8836f21 commit 72323a5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 35 deletions.
4 changes: 4 additions & 0 deletions doc/classes/Viewport.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,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.
</description>
</method>
<method name="push_text_input">
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_command_palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,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();

Expand All @@ -283,7 +283,7 @@ Ref<Shortcut> 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);
Expand Down
28 changes: 0 additions & 28 deletions scene/gui/subviewport_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,33 +221,6 @@ bool SubViewportContainer::_is_propagated_in_gui_input(const Ref<InputEvent> &p_
return false;
}

void SubViewportContainer::unhandled_input(const Ref<InputEvent> &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<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());

for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(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<SubViewport>(p_child)) {
queue_redraw();
Expand Down Expand Up @@ -290,5 +263,4 @@ void SubViewportContainer::_bind_methods() {

SubViewportContainer::SubViewportContainer() {
set_process_input(true);
set_process_unhandled_input(true);
}
1 change: 0 additions & 1 deletion scene/gui/subviewport_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class SubViewportContainer : public Container {

virtual void input(const Ref<InputEvent> &p_event) override;
virtual void gui_input(const Ref<InputEvent> &p_event) override;
virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
void set_stretch_shrink(int p_shrink);
int get_stretch_shrink() const;
void recalc_force_viewport_sizes();
Expand Down
4 changes: 4 additions & 0 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2907,6 +2907,10 @@ void Viewport::push_input(const Ref<InputEvent> &p_event, bool p_local_coords) {
_gui_cleanup_internal_state(ev);
}

if (!is_input_handled()) {
push_unhandled_input(ev, true);
}

event_count++;
}

Expand Down
4 changes: 0 additions & 4 deletions scene/main/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,10 +1384,6 @@ void Window::_window_input(const Ref<InputEvent> &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) {
Expand Down

0 comments on commit 72323a5

Please sign in to comment.