Debian Codegraph @

scene/gui/view_panner.h

raw symbols SCIP
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 #pragma once
32
33 #include "core/object/ref_counted.h"
34
35 class InputEvent;
36 class Shortcut;
37 class Viewport;
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 enum DragType {
55 DRAG_TYPE_NONE,
56 DRAG_TYPE_PAN,
57 DRAG_TYPE_ZOOM,
58 };
59
60 enum ZoomStyle {
61 ZOOM_VERTICAL,
62 ZOOM_HORIZONTAL,
63 };
64
65 private:
66 int scroll_speed = 32;
67 float scroll_zoom_factor = 1.1;
68 PanAxis pan_axis = PAN_AXIS_BOTH;
69
70 bool pan_key_pressed = false;
71 bool force_drag = false;
72
73 DragType drag_type = DragType::DRAG_TYPE_NONE;
74
75 ZoomStyle zoom_style = ZoomStyle::ZOOM_VERTICAL;
76
77 Vector2 drag_zoom_position;
78 float drag_zoom_sensitivity_factor = -0.01f;
79
80 bool enable_rmb = false;
81 bool simple_panning_enabled = false;
82
83 Ref<Shortcut> pan_view_shortcut;
84
85 Callable pan_callback;
86 Callable zoom_callback;
87
88 ControlScheme control_scheme = SCROLL_ZOOMS;
89 Viewport *warped_panning_viewport = nullptr;
90
91 public:
92 void set_callbacks(Callable p_pan_callback, Callable p_zoom_callback);
93 void set_control_scheme(ControlScheme p_scheme);
94 void set_enable_rmb(bool p_enable);
95 void set_pan_shortcut(Ref<Shortcut> p_shortcut);
96 void set_simple_panning_enabled(bool p_enabled);
97 void set_scroll_speed(int p_scroll_speed);
98 void set_scroll_zoom_factor(float p_scroll_zoom_factor);
99 void set_pan_axis(PanAxis p_pan_axis);
100 void set_zoom_style(ZoomStyle p_zoom_style);
101
102 void setup(ControlScheme p_scheme, Ref<Shortcut> p_shortcut, bool p_simple_panning);
103 void setup_warped_panning(Viewport *p_viewport, bool p_allowed);
104
105 bool is_panning() const;
106 void set_force_drag(bool p_force);
107
108 bool gui_input(const Ref<InputEvent> &p_ev, Rect2 p_canvas_rect = Rect2());
109 void release_pan_key();
110
111 ViewPanner();
112 };