From 781cecdc239a1598b1925c0e126c41fe42ead46f Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Tue, 27 Jun 2023 20:05:39 +0200 Subject: [PATCH] Enable filtering `InputEvent`-sending in `SubViewportContainer` Introduce an user overridable function, that allows filtering, if an `InputEvent` should be sent to `SubViewport` children. --- doc/classes/SubViewportContainer.xml | 9 +++++++++ scene/gui/subviewport_container.cpp | 16 ++++++++++++++++ scene/gui/subviewport_container.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/doc/classes/SubViewportContainer.xml b/doc/classes/SubViewportContainer.xml index 08e7ca23f74a..e7d7883c786f 100644 --- a/doc/classes/SubViewportContainer.xml +++ b/doc/classes/SubViewportContainer.xml @@ -10,6 +10,15 @@ + + + + + + Virtual method to be implemented by the user. If it returns [code]true[/code], the [param event] is propagated to [SubViewport] children. Propagation doesn't happen if it returns [code]false[/code]. If the function is not implemented, all events are propagated to SubViewports. + + + diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp index 851a94b32f2f..0d33774e2087 100644 --- a/scene/gui/subviewport_container.cpp +++ b/scene/gui/subviewport_container.cpp @@ -190,6 +190,13 @@ void SubViewportContainer::_propagate_nonpositional_event(const Ref return; } + bool send; + if (GDVIRTUAL_CALL(_propagate_input_event, p_event, send)) { + if (!send) { + return; + } + } + _send_event_to_viewports(p_event); } @@ -204,6 +211,13 @@ void SubViewportContainer::gui_input(const Ref &p_event) { return; } + bool send; + if (GDVIRTUAL_CALL(_propagate_input_event, p_event, send)) { + if (!send) { + return; + } + } + if (stretch && shrink > 1) { Transform2D xform; xform.scale(Vector2(1, 1) / shrink); @@ -275,6 +289,8 @@ void SubViewportContainer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stretch"), "set_stretch", "is_stretch_enabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_shrink"), "set_stretch_shrink", "get_stretch_shrink"); + + GDVIRTUAL_BIND(_propagate_input_event, "event"); } SubViewportContainer::SubViewportContainer() { diff --git a/scene/gui/subviewport_container.h b/scene/gui/subviewport_container.h index 3c6cd09d6660..06420de7303b 100644 --- a/scene/gui/subviewport_container.h +++ b/scene/gui/subviewport_container.h @@ -50,6 +50,8 @@ class SubViewportContainer : public Container { virtual void add_child_notify(Node *p_child) override; virtual void remove_child_notify(Node *p_child) override; + GDVIRTUAL1RC(bool, _propagate_input_event, Ref); + public: void set_stretch(bool p_enable); bool is_stretch_enabled() const;