view_panner.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 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. private:
  48. int scroll_speed = 32;
  49. float scroll_zoom_factor = 1.1;
  50. PanAxis pan_axis = PAN_AXIS_BOTH;
  51. bool is_dragging = false;
  52. bool pan_key_pressed = false;
  53. bool force_drag = false;
  54. bool enable_rmb = false;
  55. bool simple_panning_enabled = false;
  56. Ref<Shortcut> pan_view_shortcut;
  57. Callable pan_callback;
  58. Callable zoom_callback;
  59. ControlScheme control_scheme = SCROLL_ZOOMS;
  60. public:
  61. void set_callbacks(Callable p_pan_callback, Callable p_zoom_callback);
  62. void set_control_scheme(ControlScheme p_scheme);
  63. void set_enable_rmb(bool p_enable);
  64. void set_pan_shortcut(Ref<Shortcut> p_shortcut);
  65. void set_simple_panning_enabled(bool p_enabled);
  66. void set_scroll_speed(int p_scroll_speed);
  67. void set_scroll_zoom_factor(float p_scroll_zoom_factor);
  68. void set_pan_axis(PanAxis p_pan_axis);
  69. void setup(ControlScheme p_scheme, Ref<Shortcut> p_shortcut, bool p_simple_panning);
  70. bool is_panning() const;
  71. void set_force_drag(bool p_force);
  72. bool gui_input(const Ref<InputEvent> &p_ev, Rect2 p_canvas_rect = Rect2());
  73. void release_pan_key();
  74. ViewPanner();
  75. };
  76. #endif // VIEW_PANNER_H