view_panner.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**************************************************************************/
  2. /* view_panner.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef VIEW_PANNER_H
  31. #define VIEW_PANNER_H
  32. #include "core/object/ref_counted.h"
  33. class InputEvent;
  34. class Shortcut;
  35. class Viewport;
  36. class ViewPanner : public RefCounted {
  37. GDCLASS(ViewPanner, RefCounted);
  38. public:
  39. enum ControlScheme {
  40. SCROLL_ZOOMS,
  41. SCROLL_PANS,
  42. };
  43. enum PanAxis {
  44. PAN_AXIS_BOTH,
  45. PAN_AXIS_HORIZONTAL,
  46. PAN_AXIS_VERTICAL,
  47. };
  48. private:
  49. int scroll_speed = 32;
  50. float scroll_zoom_factor = 1.1;
  51. PanAxis pan_axis = PAN_AXIS_BOTH;
  52. bool is_dragging = false;
  53. bool pan_key_pressed = false;
  54. bool force_drag = false;
  55. bool enable_rmb = false;
  56. bool simple_panning_enabled = false;
  57. Ref<Shortcut> pan_view_shortcut;
  58. Callable pan_callback;
  59. Callable zoom_callback;
  60. ControlScheme control_scheme = SCROLL_ZOOMS;
  61. Viewport *warped_panning_viewport = nullptr;
  62. public:
  63. void set_callbacks(Callable p_pan_callback, Callable p_zoom_callback);
  64. void set_control_scheme(ControlScheme p_scheme);
  65. void set_enable_rmb(bool p_enable);
  66. void set_pan_shortcut(Ref<Shortcut> p_shortcut);
  67. void set_simple_panning_enabled(bool p_enabled);
  68. void set_scroll_speed(int p_scroll_speed);
  69. void set_scroll_zoom_factor(float p_scroll_zoom_factor);
  70. void set_pan_axis(PanAxis p_pan_axis);
  71. void setup(ControlScheme p_scheme, Ref<Shortcut> p_shortcut, bool p_simple_panning);
  72. void setup_warped_panning(Viewport *p_viewport, bool p_allowed);
  73. bool is_panning() const;
  74. void set_force_drag(bool p_force);
  75. bool gui_input(const Ref<InputEvent> &p_ev, Rect2 p_canvas_rect = Rect2());
  76. void release_pan_key();
  77. ViewPanner();
  78. };
  79. #endif // VIEW_PANNER_H