Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/canvas_item_editor_plugin.h
9896 views
1
/**************************************************************************/
2
/* canvas_item_editor_plugin.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 "editor/plugins/editor_plugin.h"
34
#include "scene/gui/box_container.h"
35
36
class AcceptDialog;
37
class Button;
38
class ButtonGroup;
39
class CanvasItemEditorViewport;
40
class ConfirmationDialog;
41
class EditorData;
42
class EditorSelection;
43
class EditorZoomWidget;
44
class HScrollBar;
45
class HSplitContainer;
46
class MenuButton;
47
class PanelContainer;
48
class StyleBoxTexture;
49
class ViewPanner;
50
class VScrollBar;
51
class VSeparator;
52
class VSplitContainer;
53
54
class CanvasItemEditorSelectedItem : public Object {
55
GDCLASS(CanvasItemEditorSelectedItem, Object);
56
57
public:
58
Transform2D prev_xform;
59
Rect2 prev_rect;
60
Vector2 prev_pivot;
61
real_t prev_anchors[4] = { (real_t)0.0 };
62
63
Transform2D pre_drag_xform;
64
Rect2 pre_drag_rect;
65
66
List<real_t> pre_drag_bones_length;
67
List<Dictionary> pre_drag_bones_undo_state;
68
69
Dictionary undo_state;
70
};
71
72
class CanvasItemEditor : public VBoxContainer {
73
GDCLASS(CanvasItemEditor, VBoxContainer);
74
75
public:
76
enum Tool {
77
TOOL_SELECT,
78
TOOL_LIST_SELECT,
79
TOOL_MOVE,
80
TOOL_SCALE,
81
TOOL_ROTATE,
82
TOOL_EDIT_PIVOT,
83
TOOL_PAN,
84
TOOL_RULER,
85
TOOL_MAX
86
};
87
88
enum AddNodeOption {
89
ADD_NODE,
90
ADD_INSTANCE,
91
ADD_PASTE,
92
ADD_MOVE,
93
};
94
95
private:
96
enum SnapTarget {
97
SNAP_TARGET_NONE = 0,
98
SNAP_TARGET_PARENT,
99
SNAP_TARGET_SELF_ANCHORS,
100
SNAP_TARGET_SELF,
101
SNAP_TARGET_OTHER_NODE,
102
SNAP_TARGET_GUIDE,
103
SNAP_TARGET_GRID,
104
SNAP_TARGET_PIXEL
105
};
106
107
enum MenuOption {
108
SNAP_USE,
109
SNAP_USE_NODE_PARENT,
110
SNAP_USE_NODE_ANCHORS,
111
SNAP_USE_NODE_SIDES,
112
SNAP_USE_NODE_CENTER,
113
SNAP_USE_OTHER_NODES,
114
SNAP_USE_GRID,
115
SNAP_USE_GUIDES,
116
SNAP_USE_ROTATION,
117
SNAP_USE_SCALE,
118
SNAP_RELATIVE,
119
SNAP_CONFIGURE,
120
SNAP_USE_PIXEL,
121
SHOW_HELPERS,
122
SHOW_RULERS,
123
SHOW_GUIDES,
124
SHOW_ORIGIN,
125
SHOW_VIEWPORT,
126
SHOW_POSITION_GIZMOS,
127
SHOW_LOCK_GIZMOS,
128
SHOW_GROUP_GIZMOS,
129
SHOW_TRANSFORMATION_GIZMOS,
130
LOCK_SELECTED,
131
UNLOCK_SELECTED,
132
GROUP_SELECTED,
133
UNGROUP_SELECTED,
134
ANIM_INSERT_KEY,
135
ANIM_INSERT_KEY_EXISTING,
136
ANIM_INSERT_POS,
137
ANIM_INSERT_ROT,
138
ANIM_INSERT_SCALE,
139
ANIM_COPY_POSE,
140
ANIM_PASTE_POSE,
141
ANIM_CLEAR_POSE,
142
CLEAR_GUIDES,
143
VIEW_CENTER_TO_SELECTION,
144
VIEW_FRAME_TO_SELECTION,
145
PREVIEW_CANVAS_SCALE,
146
SKELETON_MAKE_BONES,
147
SKELETON_SHOW_BONES
148
};
149
150
enum DragType {
151
DRAG_NONE,
152
DRAG_BOX_SELECTION,
153
DRAG_LEFT,
154
DRAG_TOP_LEFT,
155
DRAG_TOP,
156
DRAG_TOP_RIGHT,
157
DRAG_RIGHT,
158
DRAG_BOTTOM_RIGHT,
159
DRAG_BOTTOM,
160
DRAG_BOTTOM_LEFT,
161
DRAG_ANCHOR_TOP_LEFT,
162
DRAG_ANCHOR_TOP_RIGHT,
163
DRAG_ANCHOR_BOTTOM_RIGHT,
164
DRAG_ANCHOR_BOTTOM_LEFT,
165
DRAG_ANCHOR_ALL,
166
DRAG_QUEUED,
167
DRAG_MOVE,
168
DRAG_MOVE_X,
169
DRAG_MOVE_Y,
170
DRAG_SCALE_X,
171
DRAG_SCALE_Y,
172
DRAG_SCALE_BOTH,
173
DRAG_ROTATE,
174
DRAG_PIVOT,
175
DRAG_TEMP_PIVOT,
176
DRAG_V_GUIDE,
177
DRAG_H_GUIDE,
178
DRAG_DOUBLE_GUIDE,
179
DRAG_KEY_MOVE
180
};
181
182
enum GridVisibility {
183
GRID_VISIBILITY_SHOW,
184
GRID_VISIBILITY_SHOW_WHEN_SNAPPING,
185
GRID_VISIBILITY_HIDE,
186
};
187
188
const String locked_transform_warning = TTRC("All selected CanvasItems are either invisible or locked in some way and can't be transformed.");
189
190
bool selection_menu_additive_selection = false;
191
192
Tool tool = TOOL_SELECT;
193
Control *viewport = nullptr;
194
Control *viewport_scrollable = nullptr;
195
196
HScrollBar *h_scroll = nullptr;
197
VScrollBar *v_scroll = nullptr;
198
199
// Used for secondary menu items which are displayed depending on the currently selected node
200
// (such as MeshInstance's "Mesh" menu).
201
PanelContainer *context_toolbar_panel = nullptr;
202
HBoxContainer *context_toolbar_hbox = nullptr;
203
HashMap<Control *, VSeparator *> context_toolbar_separators;
204
205
void _update_context_toolbar();
206
207
Transform2D transform;
208
GridVisibility grid_visibility = GRID_VISIBILITY_SHOW_WHEN_SNAPPING;
209
bool show_rulers = true;
210
bool show_guides = true;
211
bool show_origin = true;
212
bool show_viewport = true;
213
bool show_helpers = false;
214
bool show_position_gizmos = true;
215
bool show_lock_gizmos = true;
216
bool show_group_gizmos = true;
217
bool show_transformation_gizmos = true;
218
219
real_t zoom = 1.0;
220
Point2 view_offset;
221
Point2 previous_update_view_offset;
222
223
bool selected_from_canvas = false;
224
225
// Defaults are defined in clear().
226
Point2 grid_offset;
227
Point2 grid_step;
228
Vector2i primary_grid_step;
229
int grid_step_multiplier = 0;
230
231
real_t snap_rotation_step = 0.0;
232
real_t snap_rotation_offset = 0.0;
233
real_t snap_scale_step = 0.0;
234
bool smart_snap_active = false;
235
bool grid_snap_active = false;
236
237
bool snap_node_parent = true;
238
bool snap_node_anchors = true;
239
bool snap_node_sides = true;
240
bool snap_node_center = true;
241
bool snap_other_nodes = true;
242
bool snap_guides = true;
243
bool snap_rotation = false;
244
bool snap_scale = false;
245
bool snap_relative = false;
246
// Enable pixel snapping even if pixel snap rendering is disabled in the Project Settings.
247
// This results in crisper visuals by preventing 2D nodes from being placed at subpixel coordinates.
248
bool snap_pixel = true;
249
250
bool key_pos = true;
251
bool key_rot = true;
252
bool key_scale = false;
253
254
bool pan_pressed = false;
255
Vector2 temp_pivot = Vector2(Math::INF, Math::INF);
256
257
bool ruler_tool_active = false;
258
Point2 ruler_tool_origin;
259
real_t ruler_width_scaled = 16.0;
260
int ruler_font_size = 8;
261
Point2 node_create_position;
262
263
MenuOption last_option;
264
265
struct _SelectResult {
266
CanvasItem *item = nullptr;
267
real_t z_index = 0;
268
bool has_z = true;
269
_FORCE_INLINE_ bool operator<(const _SelectResult &p_rr) const {
270
return has_z && p_rr.has_z ? p_rr.z_index < z_index : p_rr.has_z;
271
}
272
};
273
Vector<_SelectResult> selection_results;
274
Vector<_SelectResult> selection_results_menu;
275
276
struct _HoverResult {
277
Point2 position;
278
Ref<Texture2D> icon;
279
String name;
280
};
281
Vector<_HoverResult> hovering_results;
282
283
struct BoneList {
284
Transform2D xform;
285
real_t length = 0;
286
uint64_t last_pass = 0;
287
};
288
289
uint64_t bone_last_frame = 0;
290
291
struct BoneKey {
292
ObjectID from;
293
ObjectID to;
294
_FORCE_INLINE_ bool operator<(const BoneKey &p_key) const {
295
if (from == p_key.from) {
296
return to < p_key.to;
297
} else {
298
return from < p_key.from;
299
}
300
}
301
};
302
303
HashMap<BoneKey, BoneList> bone_list;
304
MenuButton *skeleton_menu = nullptr;
305
306
struct PoseClipboard {
307
Vector2 pos;
308
Vector2 scale;
309
real_t rot = 0;
310
ObjectID id;
311
};
312
List<PoseClipboard> pose_clipboard;
313
314
Button *select_button = nullptr;
315
316
Button *move_button = nullptr;
317
Button *scale_button = nullptr;
318
Button *rotate_button = nullptr;
319
320
Button *list_select_button = nullptr;
321
Button *pivot_button = nullptr;
322
Button *pan_button = nullptr;
323
324
Button *ruler_button = nullptr;
325
326
Button *smart_snap_button = nullptr;
327
Button *grid_snap_button = nullptr;
328
MenuButton *snap_config_menu = nullptr;
329
PopupMenu *smartsnap_config_popup = nullptr;
330
331
Button *lock_button = nullptr;
332
Button *unlock_button = nullptr;
333
334
Button *group_button = nullptr;
335
Button *ungroup_button = nullptr;
336
337
MenuButton *view_menu = nullptr;
338
PopupMenu *grid_menu = nullptr;
339
PopupMenu *theme_menu = nullptr;
340
PopupMenu *gizmos_menu = nullptr;
341
HBoxContainer *animation_hb = nullptr;
342
MenuButton *animation_menu = nullptr;
343
344
Button *key_loc_button = nullptr;
345
Button *key_rot_button = nullptr;
346
Button *key_scale_button = nullptr;
347
Button *key_insert_button = nullptr;
348
Button *key_auto_insert_button = nullptr;
349
350
PopupMenu *selection_menu = nullptr;
351
PopupMenu *add_node_menu = nullptr;
352
353
Control *top_ruler = nullptr;
354
Control *left_ruler = nullptr;
355
356
Point2 drag_start_origin;
357
DragType drag_type = DRAG_NONE;
358
Point2 drag_from;
359
Point2 drag_to;
360
Point2 drag_rotation_center;
361
List<CanvasItem *> drag_selection;
362
int dragged_guide_index = -1;
363
Point2 dragged_guide_pos;
364
bool is_hovering_h_guide = false;
365
bool is_hovering_v_guide = false;
366
367
bool updating_value_dialog = false;
368
Transform2D original_transform;
369
370
Point2 box_selecting_to;
371
CursorShape cursor_shape_override = CURSOR_ARROW;
372
373
Ref<StyleBoxTexture> select_sb;
374
Ref<Texture2D> select_handle;
375
Ref<Texture2D> anchor_handle;
376
377
Ref<Shortcut> drag_pivot_shortcut;
378
Ref<Shortcut> set_pivot_shortcut;
379
Ref<Shortcut> multiply_grid_step_shortcut;
380
Ref<Shortcut> divide_grid_step_shortcut;
381
382
Ref<ViewPanner> panner;
383
void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
384
void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
385
386
bool _is_node_locked(const Node *p_node) const;
387
bool _is_node_movable(const Node *p_node, bool p_popup_warning = false);
388
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());
389
void _get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, bool p_allow_locked = false);
390
391
void _find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_node, List<CanvasItem *> *r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
392
bool _select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append);
393
394
ConfirmationDialog *snap_dialog = nullptr;
395
396
CanvasItem *ref_item = nullptr;
397
398
void _save_canvas_item_state(const List<CanvasItem *> &p_canvas_items, bool save_bones = false);
399
void _restore_canvas_item_state(const List<CanvasItem *> &p_canvas_items, bool restore_bones = false);
400
void _commit_canvas_item_state(const List<CanvasItem *> &p_canvas_items, const String &action_name, bool commit_bones = false);
401
402
Vector2 _anchor_to_position(const Control *p_control, Vector2 anchor);
403
Vector2 _position_to_anchor(const Control *p_control, Vector2 position);
404
405
void _prepare_view_menu();
406
void _popup_callback(int p_op);
407
bool updating_scroll = false;
408
void _update_scroll(real_t);
409
void _update_scrollbars();
410
void _snap_changed();
411
void _selection_result_pressed(int);
412
void _selection_menu_hide();
413
void _add_node_pressed(int p_result);
414
void _adjust_new_node_position(Node *p_node);
415
void _reset_create_position();
416
void _update_editor_settings();
417
bool _is_grid_visible() const;
418
void _prepare_grid_menu();
419
void _on_grid_menu_id_pressed(int p_id);
420
421
public:
422
enum ThemePreviewMode {
423
THEME_PREVIEW_PROJECT,
424
THEME_PREVIEW_EDITOR,
425
THEME_PREVIEW_DEFAULT,
426
427
THEME_PREVIEW_MAX // The number of options for enumerating.
428
};
429
430
private:
431
ThemePreviewMode theme_preview = THEME_PREVIEW_PROJECT;
432
void _switch_theme_preview(int p_mode);
433
434
List<CanvasItem *> _get_edited_canvas_items(bool p_retrieve_locked = false, bool p_remove_canvas_item_if_parent_in_selection = true, bool *r_has_locked_items = nullptr) const;
435
Rect2 _get_encompassing_rect_from_list(const List<CanvasItem *> &p_list);
436
void _expand_encompassing_rect_using_children(Rect2 &r_rect, const Node *p_node, bool &r_first, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D(), bool include_locked_nodes = true);
437
Rect2 _get_encompassing_rect(const Node *p_node);
438
439
Object *_get_editor_data(Object *p_what);
440
441
void _insert_animation_keys(bool p_location, bool p_rotation, bool p_scale, bool p_on_existing);
442
443
void _keying_changed();
444
445
virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
446
447
void _draw_text_at_position(Point2 p_position, const String &p_string, Side p_side);
448
void _draw_margin_at_position(int p_value, Point2 p_position, Side p_side);
449
void _draw_percentage_at_position(real_t p_value, Point2 p_position, Side p_side);
450
void _draw_straight_line(Point2 p_from, Point2 p_to, Color p_color);
451
452
void _draw_smart_snapping();
453
void _draw_rulers();
454
void _draw_guides();
455
void _draw_focus();
456
void _draw_grid();
457
void _draw_ruler_tool();
458
void _draw_control_anchors(Control *control);
459
void _draw_control_helpers(Control *control);
460
void _draw_selection();
461
void _draw_axis();
462
void _draw_invisible_nodes_positions(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
463
void _draw_locks_and_groups(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
464
void _draw_hover();
465
void _draw_message();
466
467
void _draw_viewport();
468
469
bool _gui_input_anchors(const Ref<InputEvent> &p_event);
470
bool _gui_input_move(const Ref<InputEvent> &p_event);
471
bool _gui_input_open_scene_on_double_click(const Ref<InputEvent> &p_event);
472
bool _gui_input_scale(const Ref<InputEvent> &p_event);
473
bool _gui_input_pivot(const Ref<InputEvent> &p_event);
474
bool _gui_input_resize(const Ref<InputEvent> &p_event);
475
bool _gui_input_rotate(const Ref<InputEvent> &p_event);
476
bool _gui_input_select(const Ref<InputEvent> &p_event);
477
bool _gui_input_ruler_tool(const Ref<InputEvent> &p_event);
478
bool _gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bool p_already_accepted);
479
bool _gui_input_rulers_and_guides(const Ref<InputEvent> &p_event);
480
bool _gui_input_hover(const Ref<InputEvent> &p_event);
481
482
void _gui_input_viewport(const Ref<InputEvent> &p_event);
483
void _update_cursor();
484
void _update_lock_and_group_button();
485
486
void _selection_changed();
487
void _focus_selection(int p_op);
488
void _reset_drag();
489
490
void _project_settings_changed();
491
492
SnapTarget snap_target[2];
493
Transform2D snap_transform;
494
void _snap_if_closer_float(
495
const real_t p_value,
496
real_t &r_current_snap, SnapTarget &r_current_snap_target,
497
const real_t p_target_value, const SnapTarget p_snap_target,
498
const real_t p_radius = 10.0);
499
void _snap_if_closer_point(
500
Point2 p_value,
501
Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2],
502
Point2 p_target_value, const SnapTarget p_snap_target,
503
const real_t rotation = 0.0,
504
const real_t p_radius = 10.0);
505
void _snap_other_nodes(
506
const Point2 p_value,
507
const Transform2D p_transform_to_snap,
508
Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2],
509
const SnapTarget p_snap_target, List<const CanvasItem *> p_exceptions,
510
const Node *p_current);
511
512
VBoxContainer *controls_vb = nullptr;
513
Button *button_center_view = nullptr;
514
EditorZoomWidget *zoom_widget = nullptr;
515
void _update_zoom(real_t p_zoom);
516
void _shortcut_zoom_set(real_t p_zoom);
517
void _zoom_on_position(real_t p_zoom, Point2 p_position = Point2());
518
void _button_toggle_smart_snap(bool p_status);
519
void _button_toggle_grid_snap(bool p_status);
520
void _button_tool_select(int p_index);
521
522
HSplitContainer *left_panel_split = nullptr;
523
HSplitContainer *right_panel_split = nullptr;
524
VSplitContainer *bottom_split = nullptr;
525
526
void _set_owner_for_node_and_children(Node *p_node, Node *p_owner);
527
528
friend class CanvasItemEditorPlugin;
529
530
protected:
531
void _notification(int p_what);
532
533
static void _bind_methods();
534
535
static CanvasItemEditor *singleton;
536
537
public:
538
enum SnapMode {
539
SNAP_GRID = 1 << 0,
540
SNAP_GUIDES = 1 << 1,
541
SNAP_PIXEL = 1 << 2,
542
SNAP_NODE_PARENT = 1 << 3,
543
SNAP_NODE_ANCHORS = 1 << 4,
544
SNAP_NODE_SIDES = 1 << 5,
545
SNAP_NODE_CENTER = 1 << 6,
546
SNAP_OTHER_NODES = 1 << 7,
547
548
SNAP_DEFAULT = SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL,
549
};
550
551
String message;
552
553
Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, unsigned int p_forced_modes = 0, const CanvasItem *p_self_canvas_item = nullptr, const List<CanvasItem *> &p_other_nodes_exceptions = List<CanvasItem *>());
554
real_t snap_angle(real_t p_target, real_t p_start = 0) const;
555
556
Transform2D get_canvas_transform() const { return transform; }
557
558
static CanvasItemEditor *get_singleton() { return singleton; }
559
Dictionary get_state() const;
560
void set_state(const Dictionary &p_state);
561
void clear();
562
563
void add_control_to_menu_panel(Control *p_control);
564
void remove_control_from_menu_panel(Control *p_control);
565
566
void add_control_to_left_panel(Control *p_control);
567
void remove_control_from_left_panel(Control *p_control);
568
569
void add_control_to_right_panel(Control *p_control);
570
void remove_control_from_right_panel(Control *p_control);
571
572
VSplitContainer *get_bottom_split();
573
574
Control *get_viewport_control() { return viewport; }
575
576
Control *get_controls_container() { return controls_vb; }
577
578
void update_viewport();
579
580
Tool get_current_tool() { return tool; }
581
void set_current_tool(Tool p_tool);
582
583
void edit(CanvasItem *p_canvas_item);
584
585
void focus_selection();
586
void center_at(const Point2 &p_pos);
587
588
void set_cursor_shape_override(CursorShape p_shape = CURSOR_ARROW);
589
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
590
591
ThemePreviewMode get_theme_preview() const { return theme_preview; }
592
593
EditorSelection *editor_selection = nullptr;
594
595
CanvasItemEditor();
596
};
597
598
class CanvasItemEditorPlugin : public EditorPlugin {
599
GDCLASS(CanvasItemEditorPlugin, EditorPlugin);
600
601
CanvasItemEditor *canvas_item_editor = nullptr;
602
603
protected:
604
void _notification(int p_what);
605
606
public:
607
virtual String get_plugin_name() const override { return TTRC("2D"); }
608
bool has_main_screen() const override { return true; }
609
virtual void edit(Object *p_object) override;
610
virtual bool handles(Object *p_object) const override;
611
virtual void make_visible(bool p_visible) override;
612
virtual Dictionary get_state() const override;
613
virtual void set_state(const Dictionary &p_state) override;
614
virtual void clear() override;
615
616
CanvasItemEditor *get_canvas_item_editor() { return canvas_item_editor; }
617
618
CanvasItemEditorPlugin();
619
};
620
621
class CanvasItemEditorViewport : public Control {
622
GDCLASS(CanvasItemEditorViewport, Control);
623
624
// The type of node that will be created when dropping texture into the viewport.
625
String default_texture_node_type;
626
// Node types that are available to select from when dropping texture into viewport.
627
Vector<String> texture_node_types;
628
629
Vector<String> selected_files;
630
Node *target_node = nullptr;
631
Point2 drop_pos;
632
633
CanvasItemEditor *canvas_item_editor = nullptr;
634
Control *preview_node = nullptr;
635
AcceptDialog *accept = nullptr;
636
AcceptDialog *texture_node_type_selector = nullptr;
637
Label *label = nullptr;
638
Label *label_desc = nullptr;
639
Ref<ButtonGroup> button_group;
640
641
void _on_mouse_exit();
642
void _on_select_texture_node_type(Object *selected);
643
void _on_change_type_confirmed();
644
void _on_change_type_closed();
645
646
void _create_preview(const Vector<String> &files) const;
647
void _remove_preview();
648
649
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) const;
650
bool _is_any_texture_selected() const;
651
void _create_texture_node(Node *p_parent, Node *p_child, const String &p_path, const Point2 &p_point);
652
void _create_audio_node(Node *p_parent, const String &p_path, const Point2 &p_point);
653
bool _create_instance(Node *p_parent, const String &p_path, const Point2 &p_point);
654
void _perform_drop_data();
655
void _show_texture_node_type_selector();
656
void _update_theme();
657
658
protected:
659
void _notification(int p_what);
660
661
public:
662
virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
663
virtual void drop_data(const Point2 &p_point, const Variant &p_data) override;
664
665
CanvasItemEditorViewport(CanvasItemEditor *p_canvas_item_editor);
666
~CanvasItemEditorViewport();
667
};
668
669