canvas_item_editor_plugin.h 21 KB

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