| 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 | |
| 31 | #ifndef VIEW_PANNER_H |
| 32 | #define VIEW_PANNER_H |
| 33 | |
| 34 | #include "core/object/ref_counted.h" |
| 35 | |
| 36 | class InputEvent; |
| 37 | class Shortcut; |
| 38 | |
| 39 | class ViewPanner : public RefCounted { |
| 40 | GDCLASS(ViewPanner, RefCounted); |
| 41 | |
| 42 | public: |
| 43 | enum ControlScheme { |
| 44 | SCROLL_ZOOMS, |
| 45 | SCROLL_PANS, |
| 46 | }; |
| 47 | |
| 48 | enum PanAxis { |
| 49 | PAN_AXIS_BOTH, |
| 50 | PAN_AXIS_HORIZONTAL, |
| 51 | PAN_AXIS_VERTICAL, |
| 52 | }; |
| 53 | |
| 54 | private: |
| 55 | int scroll_speed = 32; |
| 56 | float scroll_zoom_factor = 1.1; |
| 57 | PanAxis pan_axis = PAN_AXIS_BOTH; |
| 58 | |
| 59 | bool is_dragging = false; |
| 60 | bool pan_key_pressed = false; |
| 61 | bool force_drag = false; |
| 62 | |
| 63 | bool enable_rmb = false; |
| 64 | bool simple_panning_enabled = false; |
| 65 | |
| 66 | Ref<Shortcut> pan_view_shortcut; |
| 67 | |
| 68 | Callable pan_callback; |
| 69 | Callable zoom_callback; |
| 70 | |
| 71 | void callback_helper(Callable p_callback, Vector<Variant> p_args); |
| 72 | ControlScheme control_scheme = SCROLL_ZOOMS; |
| 73 | |
| 74 | public: |
| 75 | void set_callbacks(Callable p_pan_callback, Callable p_zoom_callback); |
| 76 | void set_control_scheme(ControlScheme p_scheme); |
| 77 | void set_enable_rmb(bool p_enable); |
| 78 | void set_pan_shortcut(Ref<Shortcut> p_shortcut); |
| 79 | void set_simple_panning_enabled(bool p_enabled); |
| 80 | void set_scroll_speed(int p_scroll_speed); |
| 81 | void set_scroll_zoom_factor(float p_scroll_zoom_factor); |
| 82 | void set_pan_axis(PanAxis p_pan_axis); |
| 83 | |
| 84 | void setup(ControlScheme p_scheme, Ref<Shortcut> p_shortcut, bool p_simple_panning); |
| 85 | |
| 86 | bool is_panning() const; |
| 87 | void set_force_drag(bool p_force); |
| 88 | |
| 89 | bool gui_input(const Ref<InputEvent> &p_ev, Rect2 p_canvas_rect = Rect2()); |
| 90 | void release_pan_key(); |
| 91 | |
| 92 | ViewPanner(); |
| 93 | }; |
| 94 | |
| 95 | #endif // VIEW_PANNER_H |
| 96 | |