Forráskód Böngészése

Enable filtering `InputEvent`-sending in `SubViewportContainer`

Introduce an user overridable function, that allows filtering, if
an `InputEvent` should be sent to `SubViewport` children.
Markus Sauermann 2 éve
szülő
commit
781cecdc23

+ 9 - 0
doc/classes/SubViewportContainer.xml

@@ -10,6 +10,15 @@
 	</description>
 	<tutorials>
 	</tutorials>
+	<methods>
+		<method name="_propagate_input_event" qualifiers="virtual const">
+			<return type="bool" />
+			<param index="0" name="event" type="InputEvent" />
+			<description>
+				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.
+			</description>
+		</method>
+	</methods>
 	<members>
 		<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" overrides="Control" enum="Control.FocusMode" default="1" />
 		<member name="stretch" type="bool" setter="set_stretch" getter="is_stretch_enabled" default="false">

+ 16 - 0
scene/gui/subviewport_container.cpp

@@ -190,6 +190,13 @@ void SubViewportContainer::_propagate_nonpositional_event(const Ref<InputEvent>
 		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<InputEvent> &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() {

+ 2 - 0
scene/gui/subviewport_container.h

@@ -50,6 +50,8 @@ protected:
 	virtual void add_child_notify(Node *p_child) override;
 	virtual void remove_child_notify(Node *p_child) override;
 
+	GDVIRTUAL1RC(bool, _propagate_input_event, Ref<InputEvent>);
+
 public:
 	void set_stretch(bool p_enable);
 	bool is_stretch_enabled() const;