canvas_item_editor_plugin.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. #ifndef CANVAS_ITEM_EDITOR_PLUGIN_H
  31. #define CANVAS_ITEM_EDITOR_PLUGIN_H
  32. #include "editor/plugins/editor_plugin.h"
  33. #include "scene/gui/base_button.h"
  34. #include "scene/gui/box_container.h"
  35. class AcceptDialog;
  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. CanvasItemEditorSelectedItem() {}
  63. };
  64. class CanvasItemEditor : public VBoxContainer {
  65. GDCLASS(CanvasItemEditor, VBoxContainer);
  66. public:
  67. enum Tool {
  68. TOOL_SELECT,
  69. TOOL_LIST_SELECT,
  70. TOOL_MOVE,
  71. TOOL_SCALE,
  72. TOOL_ROTATE,
  73. TOOL_EDIT_PIVOT,
  74. TOOL_PAN,
  75. TOOL_RULER,
  76. TOOL_MAX
  77. };
  78. enum AddNodeOption {
  79. ADD_NODE,
  80. ADD_INSTANCE,
  81. ADD_PASTE,
  82. ADD_MOVE,
  83. };
  84. private:
  85. enum SnapTarget {
  86. SNAP_TARGET_NONE = 0,
  87. SNAP_TARGET_PARENT,
  88. SNAP_TARGET_SELF_ANCHORS,
  89. SNAP_TARGET_SELF,
  90. SNAP_TARGET_OTHER_NODE,
  91. SNAP_TARGET_GUIDE,
  92. SNAP_TARGET_GRID,
  93. SNAP_TARGET_PIXEL
  94. };
  95. enum MenuOption {
  96. SNAP_USE,
  97. SNAP_USE_NODE_PARENT,
  98. SNAP_USE_NODE_ANCHORS,
  99. SNAP_USE_NODE_SIDES,
  100. SNAP_USE_NODE_CENTER,
  101. SNAP_USE_OTHER_NODES,
  102. SNAP_USE_GRID,
  103. SNAP_USE_GUIDES,
  104. SNAP_USE_ROTATION,
  105. SNAP_USE_SCALE,
  106. SNAP_RELATIVE,
  107. SNAP_CONFIGURE,
  108. SNAP_USE_PIXEL,
  109. SHOW_HELPERS,
  110. SHOW_RULERS,
  111. SHOW_GUIDES,
  112. SHOW_ORIGIN,
  113. SHOW_VIEWPORT,
  114. SHOW_POSITION_GIZMOS,
  115. SHOW_LOCK_GIZMOS,
  116. SHOW_GROUP_GIZMOS,
  117. SHOW_TRANSFORMATION_GIZMOS,
  118. LOCK_SELECTED,
  119. UNLOCK_SELECTED,
  120. GROUP_SELECTED,
  121. UNGROUP_SELECTED,
  122. ANIM_INSERT_KEY,
  123. ANIM_INSERT_KEY_EXISTING,
  124. ANIM_INSERT_POS,
  125. ANIM_INSERT_ROT,
  126. ANIM_INSERT_SCALE,
  127. ANIM_COPY_POSE,
  128. ANIM_PASTE_POSE,
  129. ANIM_CLEAR_POSE,
  130. CLEAR_GUIDES,
  131. VIEW_CENTER_TO_SELECTION,
  132. VIEW_FRAME_TO_SELECTION,
  133. PREVIEW_CANVAS_SCALE,
  134. SKELETON_MAKE_BONES,
  135. SKELETON_SHOW_BONES
  136. };
  137. enum DragType {
  138. DRAG_NONE,
  139. DRAG_BOX_SELECTION,
  140. DRAG_LEFT,
  141. DRAG_TOP_LEFT,
  142. DRAG_TOP,
  143. DRAG_TOP_RIGHT,
  144. DRAG_RIGHT,
  145. DRAG_BOTTOM_RIGHT,
  146. DRAG_BOTTOM,
  147. DRAG_BOTTOM_LEFT,
  148. DRAG_ANCHOR_TOP_LEFT,
  149. DRAG_ANCHOR_TOP_RIGHT,
  150. DRAG_ANCHOR_BOTTOM_RIGHT,
  151. DRAG_ANCHOR_BOTTOM_LEFT,
  152. DRAG_ANCHOR_ALL,
  153. DRAG_QUEUED,
  154. DRAG_MOVE,
  155. DRAG_MOVE_X,
  156. DRAG_MOVE_Y,
  157. DRAG_SCALE_X,
  158. DRAG_SCALE_Y,
  159. DRAG_SCALE_BOTH,
  160. DRAG_ROTATE,
  161. DRAG_PIVOT,
  162. DRAG_TEMP_PIVOT,
  163. DRAG_V_GUIDE,
  164. DRAG_H_GUIDE,
  165. DRAG_DOUBLE_GUIDE,
  166. DRAG_KEY_MOVE
  167. };
  168. enum GridVisibility {
  169. GRID_VISIBILITY_SHOW,
  170. GRID_VISIBILITY_SHOW_WHEN_SNAPPING,
  171. GRID_VISIBILITY_HIDE,
  172. };
  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(INFINITY, INFINITY);
  227. bool ruler_tool_active = false;
  228. Point2 ruler_tool_origin;
  229. Point2 node_create_position;
  230. MenuOption last_option;
  231. struct _SelectResult {
  232. CanvasItem *item = nullptr;
  233. real_t z_index = 0;
  234. bool has_z = true;
  235. _FORCE_INLINE_ bool operator<(const _SelectResult &p_rr) const {
  236. return has_z && p_rr.has_z ? p_rr.z_index < z_index : p_rr.has_z;
  237. }
  238. };
  239. Vector<_SelectResult> selection_results;
  240. Vector<_SelectResult> selection_results_menu;
  241. struct _HoverResult {
  242. Point2 position;
  243. Ref<Texture2D> icon;
  244. String name;
  245. };
  246. Vector<_HoverResult> hovering_results;
  247. struct BoneList {
  248. Transform2D xform;
  249. real_t length = 0;
  250. uint64_t last_pass = 0;
  251. };
  252. uint64_t bone_last_frame = 0;
  253. struct BoneKey {
  254. ObjectID from;
  255. ObjectID to;
  256. _FORCE_INLINE_ bool operator<(const BoneKey &p_key) const {
  257. if (from == p_key.from) {
  258. return to < p_key.to;
  259. } else {
  260. return from < p_key.from;
  261. }
  262. }
  263. };
  264. HashMap<BoneKey, BoneList> bone_list;
  265. MenuButton *skeleton_menu = nullptr;
  266. struct PoseClipboard {
  267. Vector2 pos;
  268. Vector2 scale;
  269. real_t rot = 0;
  270. ObjectID id;
  271. };
  272. List<PoseClipboard> pose_clipboard;
  273. Button *select_button = nullptr;
  274. Button *move_button = nullptr;
  275. Button *scale_button = nullptr;
  276. Button *rotate_button = nullptr;
  277. Button *list_select_button = nullptr;
  278. Button *pivot_button = nullptr;
  279. Button *pan_button = nullptr;
  280. Button *ruler_button = nullptr;
  281. Button *smart_snap_button = nullptr;
  282. Button *grid_snap_button = nullptr;
  283. MenuButton *snap_config_menu = nullptr;
  284. PopupMenu *smartsnap_config_popup = nullptr;
  285. Button *lock_button = nullptr;
  286. Button *unlock_button = nullptr;
  287. Button *group_button = nullptr;
  288. Button *ungroup_button = nullptr;
  289. Button *override_camera_button = nullptr;
  290. MenuButton *view_menu = nullptr;
  291. PopupMenu *grid_menu = nullptr;
  292. PopupMenu *theme_menu = nullptr;
  293. PopupMenu *gizmos_menu = nullptr;
  294. HBoxContainer *animation_hb = nullptr;
  295. MenuButton *animation_menu = nullptr;
  296. Button *key_loc_button = nullptr;
  297. Button *key_rot_button = nullptr;
  298. Button *key_scale_button = nullptr;
  299. Button *key_insert_button = nullptr;
  300. Button *key_auto_insert_button = nullptr;
  301. PopupMenu *selection_menu = nullptr;
  302. PopupMenu *add_node_menu = nullptr;
  303. Control *top_ruler = nullptr;
  304. Control *left_ruler = nullptr;
  305. Point2 drag_start_origin;
  306. DragType drag_type = DRAG_NONE;
  307. Point2 drag_from;
  308. Point2 drag_to;
  309. Point2 drag_rotation_center;
  310. List<CanvasItem *> drag_selection;
  311. int dragged_guide_index = -1;
  312. Point2 dragged_guide_pos;
  313. bool is_hovering_h_guide = false;
  314. bool is_hovering_v_guide = false;
  315. bool updating_value_dialog = false;
  316. Transform2D original_transform;
  317. Point2 box_selecting_to;
  318. Ref<StyleBoxTexture> select_sb;
  319. Ref<Texture2D> select_handle;
  320. Ref<Texture2D> anchor_handle;
  321. Ref<Shortcut> drag_pivot_shortcut;
  322. Ref<Shortcut> set_pivot_shortcut;
  323. Ref<Shortcut> multiply_grid_step_shortcut;
  324. Ref<Shortcut> divide_grid_step_shortcut;
  325. Ref<ViewPanner> panner;
  326. bool warped_panning = true;
  327. void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
  328. void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
  329. bool _is_node_locked(const Node *p_node) const;
  330. bool _is_node_movable(const Node *p_node, bool p_popup_warning = false);
  331. 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());
  332. void _get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, bool p_allow_locked = false);
  333. 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());
  334. bool _select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append);
  335. ConfirmationDialog *snap_dialog = nullptr;
  336. CanvasItem *ref_item = nullptr;
  337. void _save_canvas_item_state(const List<CanvasItem *> &p_canvas_items, bool save_bones = false);
  338. void _restore_canvas_item_state(const List<CanvasItem *> &p_canvas_items, bool restore_bones = false);
  339. void _commit_canvas_item_state(const List<CanvasItem *> &p_canvas_items, const String &action_name, bool commit_bones = false);
  340. Vector2 _anchor_to_position(const Control *p_control, Vector2 anchor);
  341. Vector2 _position_to_anchor(const Control *p_control, Vector2 position);
  342. void _popup_callback(int p_op);
  343. bool updating_scroll = false;
  344. void _update_scroll(real_t);
  345. void _update_scrollbars();
  346. void _snap_changed();
  347. void _selection_result_pressed(int);
  348. void _selection_menu_hide();
  349. void _add_node_pressed(int p_result);
  350. void _node_created(Node *p_node);
  351. void _reset_create_position();
  352. void _update_editor_settings();
  353. bool _is_grid_visible() const;
  354. void _prepare_grid_menu();
  355. void _on_grid_menu_id_pressed(int p_id);
  356. public:
  357. enum ThemePreviewMode {
  358. THEME_PREVIEW_PROJECT,
  359. THEME_PREVIEW_EDITOR,
  360. THEME_PREVIEW_DEFAULT,
  361. THEME_PREVIEW_MAX // The number of options for enumerating.
  362. };
  363. private:
  364. ThemePreviewMode theme_preview = THEME_PREVIEW_PROJECT;
  365. void _switch_theme_preview(int p_mode);
  366. List<CanvasItem *> _get_edited_canvas_items(bool retrieve_locked = false, bool remove_canvas_item_if_parent_in_selection = true) const;
  367. Rect2 _get_encompassing_rect_from_list(const List<CanvasItem *> &p_list);
  368. 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);
  369. Rect2 _get_encompassing_rect(const Node *p_node);
  370. Object *_get_editor_data(Object *p_what);
  371. void _insert_animation_keys(bool p_location, bool p_rotation, bool p_scale, bool p_on_existing);
  372. void _keying_changed();
  373. virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
  374. void _draw_text_at_position(Point2 p_position, const String &p_string, Side p_side);
  375. void _draw_margin_at_position(int p_value, Point2 p_position, Side p_side);
  376. void _draw_percentage_at_position(real_t p_value, Point2 p_position, Side p_side);
  377. void _draw_straight_line(Point2 p_from, Point2 p_to, Color p_color);
  378. void _draw_smart_snapping();
  379. void _draw_rulers();
  380. void _draw_guides();
  381. void _draw_focus();
  382. void _draw_grid();
  383. void _draw_ruler_tool();
  384. void _draw_control_anchors(Control *control);
  385. void _draw_control_helpers(Control *control);
  386. void _draw_selection();
  387. void _draw_axis();
  388. void _draw_invisible_nodes_positions(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
  389. void _draw_locks_and_groups(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
  390. void _draw_hover();
  391. void _draw_message();
  392. void _draw_viewport();
  393. bool _gui_input_anchors(const Ref<InputEvent> &p_event);
  394. bool _gui_input_move(const Ref<InputEvent> &p_event);
  395. bool _gui_input_open_scene_on_double_click(const Ref<InputEvent> &p_event);
  396. bool _gui_input_scale(const Ref<InputEvent> &p_event);
  397. bool _gui_input_pivot(const Ref<InputEvent> &p_event);
  398. bool _gui_input_resize(const Ref<InputEvent> &p_event);
  399. bool _gui_input_rotate(const Ref<InputEvent> &p_event);
  400. bool _gui_input_select(const Ref<InputEvent> &p_event);
  401. bool _gui_input_ruler_tool(const Ref<InputEvent> &p_event);
  402. bool _gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bool p_already_accepted);
  403. bool _gui_input_rulers_and_guides(const Ref<InputEvent> &p_event);
  404. bool _gui_input_hover(const Ref<InputEvent> &p_event);
  405. void _gui_input_viewport(const Ref<InputEvent> &p_event);
  406. void _update_cursor();
  407. void _update_lock_and_group_button();
  408. void _selection_changed();
  409. void _focus_selection(int p_op);
  410. void _reset_drag();
  411. void _project_settings_changed();
  412. SnapTarget snap_target[2];
  413. Transform2D snap_transform;
  414. void _snap_if_closer_float(
  415. const real_t p_value,
  416. real_t &r_current_snap, SnapTarget &r_current_snap_target,
  417. const real_t p_target_value, const SnapTarget p_snap_target,
  418. const real_t p_radius = 10.0);
  419. void _snap_if_closer_point(
  420. Point2 p_value,
  421. Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2],
  422. Point2 p_target_value, const SnapTarget p_snap_target,
  423. const real_t rotation = 0.0,
  424. const real_t p_radius = 10.0);
  425. void _snap_other_nodes(
  426. const Point2 p_value,
  427. const Transform2D p_transform_to_snap,
  428. Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2],
  429. const SnapTarget p_snap_target, List<const CanvasItem *> p_exceptions,
  430. const Node *p_current);
  431. VBoxContainer *controls_vb = nullptr;
  432. Button *button_center_view = nullptr;
  433. EditorZoomWidget *zoom_widget = nullptr;
  434. void _update_zoom(real_t p_zoom);
  435. void _shortcut_zoom_set(real_t p_zoom);
  436. void _zoom_on_position(real_t p_zoom, Point2 p_position = Point2());
  437. void _button_toggle_smart_snap(bool p_status);
  438. void _button_toggle_grid_snap(bool p_status);
  439. void _button_override_camera(bool p_pressed);
  440. void _button_tool_select(int p_index);
  441. void _update_override_camera_button(bool p_game_running);
  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. virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
  487. ThemePreviewMode get_theme_preview() const { return theme_preview; }
  488. EditorSelection *editor_selection = nullptr;
  489. CanvasItemEditor();
  490. };
  491. class CanvasItemEditorPlugin : public EditorPlugin {
  492. GDCLASS(CanvasItemEditorPlugin, EditorPlugin);
  493. CanvasItemEditor *canvas_item_editor = nullptr;
  494. protected:
  495. void _notification(int p_what);
  496. public:
  497. virtual String get_name() const override { return "2D"; }
  498. bool has_main_screen() const override { return true; }
  499. virtual void edit(Object *p_object) override;
  500. virtual bool handles(Object *p_object) const override;
  501. virtual void make_visible(bool p_visible) override;
  502. virtual Dictionary get_state() const override;
  503. virtual void set_state(const Dictionary &p_state) override;
  504. virtual void clear() override;
  505. CanvasItemEditor *get_canvas_item_editor() { return canvas_item_editor; }
  506. CanvasItemEditorPlugin();
  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 *selector = nullptr;
  522. Label *selector_label = nullptr;
  523. Label *label = nullptr;
  524. Label *label_desc = nullptr;
  525. VBoxContainer *btn_group = nullptr;
  526. Ref<ButtonGroup> button_group;
  527. void _on_mouse_exit();
  528. void _on_select_type(Object *selected);
  529. void _on_change_type_confirmed();
  530. void _on_change_type_closed();
  531. void _create_preview(const Vector<String> &files) const;
  532. void _remove_preview();
  533. bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) const;
  534. bool _only_packed_scenes_selected() const;
  535. void _create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point);
  536. bool _create_instance(Node *parent, String &path, const Point2 &p_point);
  537. void _perform_drop_data();
  538. void _show_resource_type_selector();
  539. void _update_theme();
  540. protected:
  541. void _notification(int p_what);
  542. public:
  543. virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
  544. virtual void drop_data(const Point2 &p_point, const Variant &p_data) override;
  545. CanvasItemEditorViewport(CanvasItemEditor *p_canvas_item_editor);
  546. ~CanvasItemEditorViewport();
  547. };
  548. #endif // CANVAS_ITEM_EDITOR_PLUGIN_H