Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp
- index ac5e6020ebc22cd000f10e343c2be5f782c57242..bc8bfa09334f7928c0a9465055cb32d5e59223d0 100644
- --- a/scene/gui/viewport_container.cpp
- +++ b/scene/gui/viewport_container.cpp
- @@ -165,9 +165,35 @@ void ViewportContainer::_input(const Ref<InputEvent> &p_event) {
- }
- }
- +void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
- +
- + if (Engine::get_singleton()->is_editor_hint())
- + return;
- +
- + Transform2D xform = get_global_transform();
- +
- + if (stretch) {
- + Transform2D scale_xf;
- + scale_xf.scale(Vector2(shrink, shrink));
- + xform *= scale_xf;
- + }
- +
- + Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());
- +
- + for (int i = 0; i < get_child_count(); i++) {
- +
- + Viewport *c = Object::cast_to<Viewport>(get_child(i));
- + if (!c || c->is_input_disabled())
- + continue;
- +
- + c->unhandled_input(ev);
- + }
- +}
- +
- void ViewportContainer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_input", "event"), &ViewportContainer::_input);
- + ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &ViewportContainer::_unhandled_input);
- ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch);
- ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled);
- @@ -183,4 +209,5 @@ ViewportContainer::ViewportContainer() {
- stretch = false;
- shrink = 1;
- set_process_input(true);
- + set_process_unhandled_input(true);
- }
- diff --git a/scene/gui/viewport_container.h b/scene/gui/viewport_container.h
- index 45c4cd03a1b94a3dcc1dbe7d9ec50d070b202681..60aec259599dde6c1228cd980e487247642eb3b7 100644
- --- a/scene/gui/viewport_container.h
- +++ b/scene/gui/viewport_container.h
- @@ -49,6 +49,7 @@ public:
- bool is_stretch_enabled() const;
- void _input(const Ref<InputEvent> &p_event);
- + void _unhandled_input(const Ref<InputEvent> &p_event);
- void set_stretch_shrink(int p_shrink);
- int get_stretch_shrink() const;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement