Merge pull request #78762 from Sauermann/fix-svc-event-filter

Enable `InputEvent`-filtering in `SubViewportContainer`
This commit is contained in:
Rémi Verschelde 2023-10-03 17:10:34 +02:00
commit 9e8a93a5a9
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 27 additions and 0 deletions

View file

@ -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">

View file

@ -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() {

View file

@ -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;