Merge pull request #58334 from Sauermann/fix-to-gui-or-not-to-gui
Fix SubViewportContainer processing Events before other Control-Nodes
This commit is contained in:
commit
3e1925fd00
@ -180,26 +180,53 @@ void SubViewportContainer::input(const Ref<InputEvent> &p_event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D xform = get_global_transform_with_canvas();
|
if (_is_propagated_in_gui_input(p_event)) {
|
||||||
|
return;
|
||||||
if (stretch) {
|
|
||||||
Transform2D scale_xf;
|
|
||||||
scale_xf.scale(Vector2(shrink, shrink));
|
|
||||||
xform *= scale_xf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());
|
_send_event_to_viewports(p_event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubViewportContainer::gui_input(const Ref<InputEvent> &p_event) {
|
||||||
|
ERR_FAIL_COND(p_event.is_null());
|
||||||
|
|
||||||
|
if (Engine::get_singleton()->is_editor_hint()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_is_propagated_in_gui_input(p_event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stretch && shrink > 1) {
|
||||||
|
Transform2D xform;
|
||||||
|
xform.scale(Vector2(1, 1) / shrink);
|
||||||
|
_send_event_to_viewports(p_event->xformed_by(xform));
|
||||||
|
} else {
|
||||||
|
_send_event_to_viewports(p_event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubViewportContainer::_send_event_to_viewports(const Ref<InputEvent> &p_event) {
|
||||||
for (int i = 0; i < get_child_count(); i++) {
|
for (int i = 0; i < get_child_count(); i++) {
|
||||||
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
|
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
|
||||||
if (!c || c->is_input_disabled()) {
|
if (!c || c->is_input_disabled()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
c->push_input(ev);
|
c->push_input(p_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SubViewportContainer::_is_propagated_in_gui_input(const Ref<InputEvent> &p_event) {
|
||||||
|
// Propagation of events with a position property happen in gui_input
|
||||||
|
// Propagation of other events happen in input
|
||||||
|
if (Object::cast_to<InputEventMouse>(*p_event) || Object::cast_to<InputEventScreenDrag>(*p_event) || Object::cast_to<InputEventScreenTouch>(*p_event) || Object::cast_to<InputEventGesture>(*p_event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void SubViewportContainer::unhandled_input(const Ref<InputEvent> &p_event) {
|
void SubViewportContainer::unhandled_input(const Ref<InputEvent> &p_event) {
|
||||||
ERR_FAIL_COND(p_event.is_null());
|
ERR_FAIL_COND(p_event.is_null());
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ class SubViewportContainer : public Container {
|
|||||||
bool stretch = false;
|
bool stretch = false;
|
||||||
int shrink = 1;
|
int shrink = 1;
|
||||||
void _notify_viewports(int p_notification);
|
void _notify_viewports(int p_notification);
|
||||||
|
bool _is_propagated_in_gui_input(const Ref<InputEvent> &p_event);
|
||||||
|
void _send_event_to_viewports(const Ref<InputEvent> &p_event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
@ -52,6 +54,7 @@ public:
|
|||||||
bool is_stretch_enabled() const;
|
bool is_stretch_enabled() const;
|
||||||
|
|
||||||
virtual void input(const Ref<InputEvent> &p_event) override;
|
virtual void input(const Ref<InputEvent> &p_event) override;
|
||||||
|
virtual void gui_input(const Ref<InputEvent> &p_event) override;
|
||||||
virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
|
virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
|
||||||
void set_stretch_shrink(int p_shrink);
|
void set_stretch_shrink(int p_shrink);
|
||||||
int get_stretch_shrink() const;
|
int get_stretch_shrink() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user