Skip to content

Commit

Permalink
Merge pull request #78762 from Sauermann/fix-svc-event-filter
Browse files Browse the repository at this point in the history
Enable `InputEvent`-filtering in `SubViewportContainer`
  • Loading branch information
akien-mga committed Oct 3, 2023
2 parents e64fce3 + 781cecd commit 9e8a93a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/classes/SubViewportContainer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
16 changes: 16 additions & 0 deletions scene/gui/subviewport_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/subviewport_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputEvent>);

public:
void set_stretch(bool p_enable);
bool is_stretch_enabled() const;
Expand Down

0 comments on commit 9e8a93a

Please sign in to comment.