Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/debugger/runtime_node_select.h
20934 views
1
/**************************************************************************/
2
/* runtime_node_select.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
#ifdef DEBUG_ENABLED
34
35
#include "scene/gui/view_panner.h"
36
#ifndef _3D_DISABLED
37
#include "scene/resources/mesh.h"
38
#endif // _3D_DISABLED
39
40
class Node;
41
class PopupMenu;
42
43
class RuntimeNodeSelect : public Object {
44
GDCLASS(RuntimeNodeSelect, Object);
45
46
public:
47
enum NodeType {
48
NODE_TYPE_NONE,
49
NODE_TYPE_2D,
50
NODE_TYPE_3D,
51
NODE_TYPE_MAX,
52
};
53
54
enum SelectMode {
55
SELECT_MODE_SINGLE,
56
SELECT_MODE_LIST,
57
SELECT_MODE_MAX,
58
};
59
60
private:
61
friend class SceneDebugger;
62
63
NodeType node_select_type = NODE_TYPE_2D;
64
SelectMode node_select_mode = SELECT_MODE_SINGLE;
65
66
struct SelectResult {
67
Node *item = nullptr;
68
real_t order = 0;
69
_FORCE_INLINE_ bool operator<(const SelectResult &p_rr) const { return p_rr.order < order; }
70
};
71
72
const int SELECTION_MIN_AREA = 8 * 8;
73
enum SelectionDragState {
74
SELECTION_DRAG_NONE,
75
SELECTION_DRAG_MOVE,
76
SELECTION_DRAG_END,
77
};
78
SelectionDragState selection_drag_state = SELECTION_DRAG_NONE;
79
80
bool has_selection = false;
81
int max_selection = 1;
82
Point2 selection_position = Point2(Math::INF, Math::INF);
83
Rect2 selection_drag_area;
84
PopupMenu *selection_list = nullptr;
85
Color selection_area_fill;
86
Color selection_area_outline;
87
bool selection_visible = true;
88
bool selection_update_queued = false;
89
90
bool avoid_locked_nodes = false;
91
bool prefer_group_selection = false;
92
93
bool multi_shortcut_pressed = false;
94
bool list_shortcut_pressed = false;
95
RID draw_canvas;
96
RID sel_drag_ci;
97
98
bool camera_override = false;
99
bool camera_first_override = true;
100
101
// Values taken from EditorZoomWidget.
102
const float VIEW_2D_MIN_ZOOM = 1.0 / 128;
103
const float VIEW_2D_MAX_ZOOM = 128;
104
105
Ref<ViewPanner> panner;
106
Vector2 view_2d_offset;
107
real_t view_2d_zoom = 1.0;
108
bool warped_panning = false;
109
110
LocalVector<ObjectID> selected_ci_nodes;
111
real_t sel_2d_grab_dist = 0;
112
int sel_2d_scale = 1;
113
114
RID sbox_2d_ci;
115
116
#ifndef _3D_DISABLED
117
struct Cursor {
118
Vector3 pos;
119
real_t x_rot, y_rot, distance, fov_scale;
120
Vector3 eye_pos; // Used in freelook mode.
121
122
Cursor() {
123
// These rotations place the camera in +X +Y +Z, aka south east, facing north west.
124
x_rot = 0.5;
125
y_rot = -0.5;
126
distance = 4;
127
fov_scale = 1.0;
128
}
129
};
130
Cursor cursor;
131
132
// Values taken from Node3DEditor.
133
const float VIEW_3D_MIN_ZOOM = 0.01;
134
#ifdef REAL_T_IS_DOUBLE
135
const double VIEW_3D_MAX_ZOOM = 1'000'000'000'000;
136
#else
137
const float VIEW_3D_MAX_ZOOM = 10'000;
138
#endif // REAL_T_IS_DOUBLE
139
140
const float CAMERA_MIN_FOV_SCALE = 0.1;
141
const float CAMERA_MAX_FOV_SCALE = 2.5;
142
143
bool camera_freelook = false;
144
145
real_t camera_fov = 0;
146
real_t camera_znear = 0;
147
real_t camera_zfar = 0;
148
149
bool invert_x_axis = false;
150
bool invert_y_axis = false;
151
bool warped_mouse_panning_3d = false;
152
153
real_t freelook_base_speed = 0;
154
real_t freelook_sensitivity = 0;
155
real_t orbit_sensitivity = 0;
156
real_t translation_sensitivity = 0;
157
158
Vector2 previous_mouse_position;
159
160
struct SelectionBox3D : public RefCounted {
161
RID instance;
162
RID instance_ofs;
163
RID instance_xray;
164
RID instance_xray_ofs;
165
166
Transform3D transform;
167
AABB bounds;
168
169
~SelectionBox3D() {
170
if (instance.is_valid()) {
171
RS::get_singleton()->free_rid(instance);
172
RS::get_singleton()->free_rid(instance_ofs);
173
RS::get_singleton()->free_rid(instance_xray);
174
RS::get_singleton()->free_rid(instance_xray_ofs);
175
}
176
}
177
};
178
HashMap<ObjectID, Ref<SelectionBox3D>> selected_3d_nodes;
179
180
Color sbox_3d_color;
181
Ref<ArrayMesh> sbox_3d_mesh;
182
Ref<ArrayMesh> sbox_3d_mesh_xray;
183
RID sbox_3d;
184
RID sbox_3d_ofs;
185
RID sbox_3d_xray;
186
RID sbox_3d_xray_ofs;
187
#endif // _3D_DISABLED
188
189
void _setup(const Dictionary &p_settings);
190
191
void _node_set_type(NodeType p_type);
192
void _select_set_mode(SelectMode p_mode);
193
194
void _set_camera_override_enabled(bool p_enabled);
195
196
void _root_window_input(const Ref<InputEvent> &p_event);
197
void _items_popup_index_pressed(int p_index, PopupMenu *p_popup);
198
void _update_input_state();
199
200
void _process_frame();
201
void _physics_frame();
202
203
void _send_ids(const Vector<Node *> &p_picked_nodes, bool p_invert_new_selections = true);
204
void _set_selected_nodes(const Vector<Node *> &p_nodes);
205
void _queue_selection_update();
206
void _update_selection();
207
void _clear_selection();
208
void _update_selection_drag(const Point2 &p_end_pos = Point2());
209
void _set_selection_visible(bool p_visible);
210
void _set_avoid_locked(bool p_enabled);
211
void _set_prefer_group(bool p_enabled);
212
213
void _open_selection_list(const Vector<SelectResult> &p_items, const Point2 &p_pos);
214
void _close_selection_list();
215
216
void _find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<SelectResult> &r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
217
void _find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_node, Vector<SelectResult> &r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
218
void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
219
void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
220
void _reset_camera_2d();
221
void _update_view_2d();
222
223
#ifndef _3D_DISABLED
224
void _find_3d_items_at_pos(const Point2 &p_pos, Vector<SelectResult> &r_items);
225
void _find_3d_items_at_rect(const Rect2 &p_rect, Vector<SelectResult> &r_items);
226
Vector3 _get_screen_to_space(const Vector3 &p_vector3);
227
228
bool _handle_3d_input(const Ref<InputEvent> &p_event);
229
void _set_camera_freelook_enabled(bool p_enabled);
230
void _cursor_scale_distance(real_t p_scale);
231
void _scale_freelook_speed(real_t p_scale);
232
void _cursor_look(Ref<InputEventWithModifiers> p_event);
233
void _cursor_pan(Ref<InputEventWithModifiers> p_event);
234
void _cursor_orbit(Ref<InputEventWithModifiers> p_event);
235
Point2 _get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_event, Rect2 p_border) const;
236
Transform3D _get_cursor_transform();
237
void _reset_camera_3d();
238
#endif // _3D_DISABLED
239
240
RuntimeNodeSelect() { singleton = this; }
241
242
inline static RuntimeNodeSelect *singleton = nullptr;
243
244
public:
245
static RuntimeNodeSelect *get_singleton();
246
247
~RuntimeNodeSelect();
248
};
249
#endif // DEBUG_ENABLED
250
251