Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable InputEvent-filtering in SubViewportContainer #78762

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading