Advertisement
Guest User

Physic Picking Events

a guest
Aug 5th, 2018
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp
  2. index ac5e6020ebc22cd000f10e343c2be5f782c57242..bc8bfa09334f7928c0a9465055cb32d5e59223d0 100644
  3. --- a/scene/gui/viewport_container.cpp
  4. +++ b/scene/gui/viewport_container.cpp
  5. @@ -165,9 +165,35 @@ void ViewportContainer::_input(const Ref<InputEvent> &p_event) {
  6.     }
  7.  }
  8.  
  9. +void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
  10. +
  11. +   if (Engine::get_singleton()->is_editor_hint())
  12. +       return;
  13. +
  14. +   Transform2D xform = get_global_transform();
  15. +
  16. +   if (stretch) {
  17. +       Transform2D scale_xf;
  18. +       scale_xf.scale(Vector2(shrink, shrink));
  19. +       xform *= scale_xf;
  20. +   }
  21. +
  22. +   Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());
  23. +
  24. +   for (int i = 0; i < get_child_count(); i++) {
  25. +
  26. +       Viewport *c = Object::cast_to<Viewport>(get_child(i));
  27. +       if (!c || c->is_input_disabled())
  28. +           continue;
  29. +
  30. +       c->unhandled_input(ev);
  31. +   }
  32. +}
  33. +
  34.  void ViewportContainer::_bind_methods() {
  35.  
  36.     ClassDB::bind_method(D_METHOD("_input", "event"), &ViewportContainer::_input);
  37. +   ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &ViewportContainer::_unhandled_input);
  38.     ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch);
  39.     ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled);
  40.  
  41. @@ -183,4 +209,5 @@ ViewportContainer::ViewportContainer() {
  42.     stretch = false;
  43.     shrink = 1;
  44.     set_process_input(true);
  45. +   set_process_unhandled_input(true);
  46.  }
  47. diff --git a/scene/gui/viewport_container.h b/scene/gui/viewport_container.h
  48. index 45c4cd03a1b94a3dcc1dbe7d9ec50d070b202681..60aec259599dde6c1228cd980e487247642eb3b7 100644
  49. --- a/scene/gui/viewport_container.h
  50. +++ b/scene/gui/viewport_container.h
  51. @@ -49,6 +49,7 @@ public:
  52.     bool is_stretch_enabled() const;
  53.  
  54.     void _input(const Ref<InputEvent> &p_event);
  55. +   void _unhandled_input(const Ref<InputEvent> &p_event);
  56.     void set_stretch_shrink(int p_shrink);
  57.     int get_stretch_shrink() const;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement