view_panner.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #pragma once
  31. #include "core/object/ref_counted.h"
  32. class InputEvent;
  33. class Shortcut;
  34. class Viewport;
  35. class ViewPanner : public RefCounted {
  36. GDCLASS(ViewPanner, RefCounted);
  37. public:
  38. enum ControlScheme {
  39. SCROLL_ZOOMS,
  40. SCROLL_PANS,
  41. };
  42. enum PanAxis {
  43. PAN_AXIS_BOTH,
  44. PAN_AXIS_HORIZONTAL,
  45. PAN_AXIS_VERTICAL,
  46. };
  47. enum DragType {
  48. DRAG_TYPE_NONE,
  49. DRAG_TYPE_PAN,
  50. DRAG_TYPE_ZOOM,
  51. };
  52. enum ZoomStyle {
  53. ZOOM_VERTICAL,
  54. ZOOM_HORIZONTAL,
  55. };
  56. private:
  57. int scroll_speed = 32;
  58. float scroll_zoom_factor = 1.1;
  59. PanAxis pan_axis = PAN_AXIS_BOTH;
  60. bool pan_key_pressed = false;
  61. bool force_drag = false;
  62. DragType drag_type = DragType::DRAG_TYPE_NONE;
  63. ZoomStyle zoom_style = ZoomStyle::ZOOM_VERTICAL;
  64. Vector2 drag_zoom_position;
  65. float drag_zoom_sensitivity_factor = -0.01f;
  66. bool enable_rmb = false;
  67. bool simple_panning_enabled = false;
  68. Ref<Shortcut> pan_view_shortcut;
  69. Callable pan_callback;
  70. Callable zoom_callback;
  71. ControlScheme control_scheme = SCROLL_ZOOMS;
  72. Viewport *warped_panning_viewport = nullptr;
  73. public:
  74. void set_callbacks(Callable p_pan_callback, Callable p_zoom_callback);
  75. void set_control_scheme(ControlScheme p_scheme);
  76. void set_enable_rmb(bool p_enable);
  77. void set_pan_shortcut(Ref<Shortcut> p_shortcut);
  78. void set_simple_panning_enabled(bool p_enabled);
  79. void set_scroll_speed(int p_scroll_speed);
  80. void set_scroll_zoom_factor(float p_scroll_zoom_factor);
  81. void set_pan_axis(PanAxis p_pan_axis);
  82. void set_zoom_style(ZoomStyle p_zoom_style);
  83. void setup(ControlScheme p_scheme, Ref<Shortcut> p_shortcut, bool p_simple_panning);
  84. void setup_warped_panning(Viewport *p_viewport, bool p_allowed);
  85. bool is_panning() const;
  86. void set_force_drag(bool p_force);
  87. bool gui_input(const Ref<InputEvent> &p_ev, Rect2 p_canvas_rect = Rect2());
  88. void release_pan_key();
  89. ViewPanner();
  90. };