mirror of
https://github.com/godotengine/godot.git
synced 2024-11-10 14:12:51 +00:00
Enable filtering InputEvent
-sending in SubViewportContainer
Introduce an user overridable function, that allows filtering, if an `InputEvent` should be sent to `SubViewport` children.
This commit is contained in:
parent
0ca8542329
commit
781cecdc23
@ -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">
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user