Debian Codegraph @

scene/2d/camera_2d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* camera_2d.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 "scene/2d/node_2d.h"
34
35 class Camera2D : public Node2D {
36 GDCLASS(Camera2D, Node2D);
37
38 public:
39 enum AnchorMode {
40 ANCHOR_MODE_FIXED_TOP_LEFT,
41 ANCHOR_MODE_DRAG_CENTER
42 };
43
44 enum Camera2DProcessCallback {
45 CAMERA2D_PROCESS_PHYSICS,
46 CAMERA2D_PROCESS_IDLE
47 };
48
49 protected:
50 Point2 camera_pos;
51 Point2 smoothed_camera_pos;
52 bool first = true;
53 bool just_exited_tree = false;
54
55 ObjectID custom_viewport_id; // To check validity.
56 Viewport *custom_viewport = nullptr;
57 Viewport *viewport = nullptr;
58
59 StringName group_name;
60 StringName canvas_group_name;
61 RID canvas;
62 Vector2 offset;
63 Vector2 zoom = Vector2(1, 1);
64 Vector2 zoom_scale = Vector2(1, 1);
65 AnchorMode anchor_mode = ANCHOR_MODE_DRAG_CENTER;
66 bool ignore_rotation = true;
67 bool enabled = true;
68 real_t position_smoothing_speed = 5.0;
69 bool position_smoothing_enabled = false;
70
71 real_t camera_angle = 0.0;
72 real_t rotation_smoothing_speed = 5.0;
73 bool rotation_smoothing_enabled = false;
74
75 bool limit_enabled = true;
76 int limit[4] = { -10000000, -10000000, 10000000, 10000000 }; // Left, top, right, bottom.
77 bool limit_smoothing_enabled = false;
78
79 real_t drag_margin[4] = { 0.2, 0.2, 0.2, 0.2 };
80 bool drag_horizontal_enabled = false;
81 bool drag_vertical_enabled = false;
82 real_t drag_horizontal_offset = 0.0;
83 real_t drag_vertical_offset = 0.0;
84 bool drag_horizontal_offset_changed = false;
85 bool drag_vertical_offset_changed = false;
86
87 Point2 camera_screen_center;
88 bool _is_editing_in_editor() const;
89 void _update_process_callback();
90 void _update_scroll();
91
92 #ifdef TOOLS_ENABLED
93 void _project_settings_changed();
94 #endif
95
96 void _make_current(Object *p_which);
97 void _reset_just_exited() { just_exited_tree = false; }
98
99 void _update_process_internal_for_smoothing();
100
101 bool screen_drawing_enabled = true;
102 bool limit_drawing_enabled = false;
103 bool margin_drawing_enabled = false;
104
105 Camera2DProcessCallback process_callback = CAMERA2D_PROCESS_IDLE;
106
107 struct InterpolationData {
108 Transform2D xform_curr;
109 Transform2D xform_prev;
110 uint32_t last_update_physics_tick = UINT32_MAX; // Ensure tick 0 is detected as a change.
111
112 // Camera2D can only call get_camera_transform() without flagging warnings after setting up viewports
113 // during NOTIFICATION_ENTER_TREE, so we reject resets outside this lifetime.
114 bool accepting_resets = false;
115 } _interpolation_data;
116
117 void _ensure_update_interpolation_data();
118
119 Size2 _get_camera_screen_size() const;
120
121 protected:
122 virtual Transform2D get_camera_transform();
123
124 void _notification(int p_what);
125 static void _bind_methods();
126
127 public:
128 void set_limit_rect(const Rect2i &p_limit_rect);
129 Rect2i get_limit_rect() const;
130
131 void set_offset(const Vector2 &p_offset);
132 Vector2 get_offset() const;
133
134 void set_anchor_mode(AnchorMode p_anchor_mode);
135 AnchorMode get_anchor_mode() const;
136
137 void set_ignore_rotation(bool p_ignore);
138 bool is_ignoring_rotation() const;
139
140 void set_limit_enabled(bool p_limit_enabled);
141 bool is_limit_enabled() const;
142
143 void set_limit(Side p_side, int p_limit);
144 int get_limit(Side p_side) const;
145
146 void set_limit_smoothing_enabled(bool p_enabled);
147 bool is_limit_smoothing_enabled() const;
148
149 void set_drag_horizontal_enabled(bool p_enabled);
150 bool is_drag_horizontal_enabled() const;
151
152 void set_drag_vertical_enabled(bool p_enabled);
153 bool is_drag_vertical_enabled() const;
154
155 void set_drag_margin(Side p_side, real_t p_drag_margin);
156 real_t get_drag_margin(Side p_side) const;
157
158 void set_drag_horizontal_offset(real_t p_offset);
159 real_t get_drag_horizontal_offset() const;
160
161 void set_drag_vertical_offset(real_t p_offset);
162 real_t get_drag_vertical_offset() const;
163
164 void set_position_smoothing_enabled(bool p_enabled);
165 bool is_position_smoothing_enabled() const;
166
167 void set_position_smoothing_speed(real_t p_speed);
168 real_t get_position_smoothing_speed() const;
169
170 void set_rotation_smoothing_speed(real_t p_speed);
171 real_t get_rotation_smoothing_speed() const;
172
173 void set_rotation_smoothing_enabled(bool p_enabled);
174 bool is_rotation_smoothing_enabled() const;
175
176 void set_process_callback(Camera2DProcessCallback p_mode);
177 Camera2DProcessCallback get_process_callback() const;
178
179 void set_enabled(bool p_enabled);
180 bool is_enabled() const;
181
182 void make_current();
183 void clear_current();
184 bool is_current() const;
185
186 void set_zoom(const Vector2 &p_zoom);
187 Vector2 get_zoom() const;
188
189 Point2 get_camera_screen_center() const;
190 real_t get_screen_rotation() const;
191
192 void set_custom_viewport(Node *p_viewport);
193 Node *get_custom_viewport() const;
194
195 Vector2 get_camera_position() const;
196 void force_update_scroll();
197 void reset_smoothing();
198 void align();
199
200 void set_screen_drawing_enabled(bool p_enabled);
201 bool is_screen_drawing_enabled() const;
202
203 void set_limit_drawing_enabled(bool p_enabled);
204 bool is_limit_drawing_enabled() const;
205
206 void set_margin_drawing_enabled(bool p_enabled);
207 bool is_margin_drawing_enabled() const;
208
209 Camera2D();
210 };
211
212 VARIANT_ENUM_CAST(Camera2D::AnchorMode);
213 VARIANT_ENUM_CAST(Camera2D::Camera2DProcessCallback);