canvas_item_editor_plugin.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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 CONTROL_EDITOR_PLUGIN_H
  31. #define CONTROL_EDITOR_PLUGIN_H
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_plugin.h"
  34. #include "scene/2d/canvas_item.h"
  35. #include "scene/gui/box_container.h"
  36. #include "scene/gui/check_box.h"
  37. #include "scene/gui/label.h"
  38. #include "scene/gui/panel_container.h"
  39. #include "scene/gui/spin_box.h"
  40. /**
  41. @author Juan Linietsky <reduzio@gmail.com>
  42. */
  43. class CanvasItemEditorViewport;
  44. class CanvasItemEditorSelectedItem : public Object {
  45. GDCLASS(CanvasItemEditorSelectedItem, Object);
  46. public:
  47. Transform2D prev_xform;
  48. float prev_rot;
  49. Rect2 prev_rect;
  50. Vector2 prev_pivot;
  51. float prev_anchors[4];
  52. Transform2D pre_drag_xform;
  53. Rect2 pre_drag_rect;
  54. List<float> pre_drag_bones_length;
  55. List<Dictionary> pre_drag_bones_undo_state;
  56. Dictionary undo_state;
  57. CanvasItemEditorSelectedItem() :
  58. prev_anchors() {
  59. prev_rot = 0;
  60. }
  61. };
  62. class CanvasItemEditor : public VBoxContainer {
  63. GDCLASS(CanvasItemEditor, VBoxContainer);
  64. public:
  65. enum Tool {
  66. TOOL_SELECT,
  67. TOOL_LIST_SELECT,
  68. TOOL_MOVE,
  69. TOOL_SCALE,
  70. TOOL_ROTATE,
  71. TOOL_EDIT_PIVOT,
  72. TOOL_PAN,
  73. TOOL_MAX
  74. };
  75. private:
  76. EditorNode *editor;
  77. enum MenuOption {
  78. SNAP_USE,
  79. SNAP_USE_NODE_PARENT,
  80. SNAP_USE_NODE_ANCHORS,
  81. SNAP_USE_NODE_SIDES,
  82. SNAP_USE_NODE_CENTER,
  83. SNAP_USE_OTHER_NODES,
  84. SNAP_USE_GRID,
  85. SNAP_USE_GUIDES,
  86. SNAP_USE_ROTATION,
  87. SNAP_RELATIVE,
  88. SNAP_CONFIGURE,
  89. SNAP_USE_PIXEL,
  90. SHOW_GRID,
  91. SHOW_HELPERS,
  92. SHOW_RULERS,
  93. SHOW_GUIDES,
  94. SHOW_ORIGIN,
  95. SHOW_VIEWPORT,
  96. SHOW_EDIT_LOCKS,
  97. LOCK_SELECTED,
  98. UNLOCK_SELECTED,
  99. GROUP_SELECTED,
  100. UNGROUP_SELECTED,
  101. ANCHORS_AND_MARGINS_PRESET_TOP_LEFT,
  102. ANCHORS_AND_MARGINS_PRESET_TOP_RIGHT,
  103. ANCHORS_AND_MARGINS_PRESET_BOTTOM_LEFT,
  104. ANCHORS_AND_MARGINS_PRESET_BOTTOM_RIGHT,
  105. ANCHORS_AND_MARGINS_PRESET_CENTER_LEFT,
  106. ANCHORS_AND_MARGINS_PRESET_CENTER_RIGHT,
  107. ANCHORS_AND_MARGINS_PRESET_CENTER_TOP,
  108. ANCHORS_AND_MARGINS_PRESET_CENTER_BOTTOM,
  109. ANCHORS_AND_MARGINS_PRESET_CENTER,
  110. ANCHORS_AND_MARGINS_PRESET_TOP_WIDE,
  111. ANCHORS_AND_MARGINS_PRESET_LEFT_WIDE,
  112. ANCHORS_AND_MARGINS_PRESET_RIGHT_WIDE,
  113. ANCHORS_AND_MARGINS_PRESET_BOTTOM_WIDE,
  114. ANCHORS_AND_MARGINS_PRESET_VCENTER_WIDE,
  115. ANCHORS_AND_MARGINS_PRESET_HCENTER_WIDE,
  116. ANCHORS_AND_MARGINS_PRESET_WIDE,
  117. ANCHORS_PRESET_TOP_LEFT,
  118. ANCHORS_PRESET_TOP_RIGHT,
  119. ANCHORS_PRESET_BOTTOM_LEFT,
  120. ANCHORS_PRESET_BOTTOM_RIGHT,
  121. ANCHORS_PRESET_CENTER_LEFT,
  122. ANCHORS_PRESET_CENTER_RIGHT,
  123. ANCHORS_PRESET_CENTER_TOP,
  124. ANCHORS_PRESET_CENTER_BOTTOM,
  125. ANCHORS_PRESET_CENTER,
  126. ANCHORS_PRESET_TOP_WIDE,
  127. ANCHORS_PRESET_LEFT_WIDE,
  128. ANCHORS_PRESET_RIGHT_WIDE,
  129. ANCHORS_PRESET_BOTTOM_WIDE,
  130. ANCHORS_PRESET_VCENTER_WIDE,
  131. ANCHORS_PRESET_HCENTER_WIDE,
  132. ANCHORS_PRESET_WIDE,
  133. MARGINS_PRESET_TOP_LEFT,
  134. MARGINS_PRESET_TOP_RIGHT,
  135. MARGINS_PRESET_BOTTOM_LEFT,
  136. MARGINS_PRESET_BOTTOM_RIGHT,
  137. MARGINS_PRESET_CENTER_LEFT,
  138. MARGINS_PRESET_CENTER_RIGHT,
  139. MARGINS_PRESET_CENTER_TOP,
  140. MARGINS_PRESET_CENTER_BOTTOM,
  141. MARGINS_PRESET_CENTER,
  142. MARGINS_PRESET_TOP_WIDE,
  143. MARGINS_PRESET_LEFT_WIDE,
  144. MARGINS_PRESET_RIGHT_WIDE,
  145. MARGINS_PRESET_BOTTOM_WIDE,
  146. MARGINS_PRESET_VCENTER_WIDE,
  147. MARGINS_PRESET_HCENTER_WIDE,
  148. MARGINS_PRESET_WIDE,
  149. ANIM_INSERT_KEY,
  150. ANIM_INSERT_KEY_EXISTING,
  151. ANIM_INSERT_POS,
  152. ANIM_INSERT_ROT,
  153. ANIM_INSERT_SCALE,
  154. ANIM_COPY_POSE,
  155. ANIM_PASTE_POSE,
  156. ANIM_CLEAR_POSE,
  157. VIEW_CENTER_TO_SELECTION,
  158. VIEW_FRAME_TO_SELECTION,
  159. SKELETON_MAKE_BONES,
  160. SKELETON_CLEAR_BONES,
  161. SKELETON_SHOW_BONES,
  162. SKELETON_SET_IK_CHAIN,
  163. SKELETON_CLEAR_IK_CHAIN
  164. };
  165. enum DragType {
  166. DRAG_NONE,
  167. DRAG_BOX_SELECTION,
  168. DRAG_LEFT,
  169. DRAG_TOP_LEFT,
  170. DRAG_TOP,
  171. DRAG_TOP_RIGHT,
  172. DRAG_RIGHT,
  173. DRAG_BOTTOM_RIGHT,
  174. DRAG_BOTTOM,
  175. DRAG_BOTTOM_LEFT,
  176. DRAG_ANCHOR_TOP_LEFT,
  177. DRAG_ANCHOR_TOP_RIGHT,
  178. DRAG_ANCHOR_BOTTOM_RIGHT,
  179. DRAG_ANCHOR_BOTTOM_LEFT,
  180. DRAG_ANCHOR_ALL,
  181. DRAG_MOVE,
  182. DRAG_SCALE_X,
  183. DRAG_SCALE_Y,
  184. DRAG_SCALE_BOTH,
  185. DRAG_ROTATE,
  186. DRAG_PIVOT,
  187. DRAG_V_GUIDE,
  188. DRAG_H_GUIDE,
  189. DRAG_DOUBLE_GUIDE,
  190. DRAG_KEY_MOVE,
  191. DRAG_PAN
  192. };
  193. EditorSelection *editor_selection;
  194. bool selection_menu_additive_selection;
  195. Tool tool;
  196. Control *viewport;
  197. Control *viewport_scrollable;
  198. HScrollBar *h_scroll;
  199. VScrollBar *v_scroll;
  200. HBoxContainer *hb;
  201. ToolButton *zoom_minus;
  202. ToolButton *zoom_reset;
  203. ToolButton *zoom_plus;
  204. Map<Control *, Timer *> popup_temporarily_timers;
  205. Label *warning_child_of_container;
  206. VBoxContainer *info_overlay;
  207. Transform2D transform;
  208. bool show_grid;
  209. bool show_rulers;
  210. bool show_guides;
  211. bool show_origin;
  212. bool show_viewport;
  213. bool show_helpers;
  214. bool show_edit_locks;
  215. float zoom;
  216. Point2 view_offset;
  217. Point2 previous_update_view_offset;
  218. Point2 grid_offset;
  219. Point2 grid_step;
  220. int grid_step_multiplier;
  221. float snap_rotation_step;
  222. float snap_rotation_offset;
  223. bool snap_active;
  224. bool snap_node_parent;
  225. bool snap_node_anchors;
  226. bool snap_node_sides;
  227. bool snap_node_center;
  228. bool snap_other_nodes;
  229. bool snap_grid;
  230. bool snap_guides;
  231. bool snap_rotation;
  232. bool snap_relative;
  233. bool snap_pixel;
  234. bool skeleton_show_bones;
  235. bool key_pos;
  236. bool key_rot;
  237. bool key_scale;
  238. MenuOption last_option;
  239. struct _SelectResult {
  240. CanvasItem *item;
  241. float z_index;
  242. bool has_z;
  243. _FORCE_INLINE_ bool operator<(const _SelectResult &p_rr) const {
  244. return has_z && p_rr.has_z ? p_rr.z_index < z_index : p_rr.has_z;
  245. }
  246. };
  247. Vector<_SelectResult> selection_results;
  248. struct _HoverResult {
  249. Point2 position;
  250. Ref<Texture> icon;
  251. String name;
  252. };
  253. Vector<_HoverResult> hovering_results;
  254. struct BoneList {
  255. Transform2D xform;
  256. float length;
  257. uint64_t last_pass;
  258. BoneList() :
  259. length(0.f),
  260. last_pass(0) {}
  261. };
  262. uint64_t bone_last_frame;
  263. struct BoneKey {
  264. ObjectID from;
  265. ObjectID to;
  266. _FORCE_INLINE_ bool operator<(const BoneKey &p_key) const {
  267. if (from == p_key.from)
  268. return to < p_key.to;
  269. else
  270. return from < p_key.from;
  271. }
  272. };
  273. Map<BoneKey, BoneList> bone_list;
  274. struct PoseClipboard {
  275. Vector2 pos;
  276. Vector2 scale;
  277. float rot;
  278. ObjectID id;
  279. };
  280. List<PoseClipboard> pose_clipboard;
  281. ToolButton *select_button;
  282. ToolButton *move_button;
  283. ToolButton *scale_button;
  284. ToolButton *rotate_button;
  285. ToolButton *list_select_button;
  286. ToolButton *pivot_button;
  287. ToolButton *pan_button;
  288. ToolButton *snap_button;
  289. MenuButton *snap_config_menu;
  290. PopupMenu *smartsnap_config_popup;
  291. ToolButton *lock_button;
  292. ToolButton *unlock_button;
  293. ToolButton *group_button;
  294. ToolButton *ungroup_button;
  295. MenuButton *skeleton_menu;
  296. MenuButton *view_menu;
  297. HBoxContainer *animation_hb;
  298. MenuButton *animation_menu;
  299. MenuButton *presets_menu;
  300. PopupMenu *anchors_and_margins_popup;
  301. PopupMenu *anchors_popup;
  302. Button *key_loc_button;
  303. Button *key_rot_button;
  304. Button *key_scale_button;
  305. Button *key_insert_button;
  306. PopupMenu *selection_menu;
  307. Control *top_ruler;
  308. Control *left_ruler;
  309. DragType drag_type;
  310. Point2 drag_from;
  311. Point2 drag_to;
  312. Point2 drag_rotation_center;
  313. List<CanvasItem *> drag_selection;
  314. int dragged_guide_index;
  315. Point2 dragged_guide_pos;
  316. bool updating_value_dialog;
  317. Point2 box_selecting_to;
  318. Ref<StyleBoxTexture> select_sb;
  319. Ref<Texture> select_handle;
  320. Ref<Texture> 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. bool _is_node_locked(const Node *p_node);
  326. bool _is_node_movable(const Node *p_node, bool p_popup_warning = false);
  327. 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());
  328. void _get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items);
  329. void _get_bones_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items);
  330. 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());
  331. bool _select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append);
  332. ConfirmationDialog *snap_dialog;
  333. CanvasItem *ref_item;
  334. void _add_canvas_item(CanvasItem *p_canvas_item);
  335. void _save_canvas_item_ik_chain(const CanvasItem *p_canvas_item, List<float> *p_bones_length, List<Dictionary> *p_bones_state);
  336. void _save_canvas_item_state(List<CanvasItem *> p_canvas_items, bool save_bones = false);
  337. void _restore_canvas_item_ik_chain(CanvasItem *p_canvas_item, const List<Dictionary> *p_bones_state);
  338. void _restore_canvas_item_state(List<CanvasItem *> p_canvas_items, bool restore_bones = false);
  339. void _commit_canvas_item_state(List<CanvasItem *> p_canvas_items, 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;
  344. void _update_scroll(float);
  345. void _update_scrollbars();
  346. void _append_canvas_item(CanvasItem *p_item);
  347. void _snap_changed();
  348. void _selection_result_pressed(int);
  349. void _selection_menu_hide();
  350. UndoRedo *undo_redo;
  351. bool _build_bones_list(Node *p_node);
  352. bool _get_bone_shape(Vector<Vector2> *shape, Vector<Vector2> *outline_shape, Map<BoneKey, BoneList>::Element *bone);
  353. List<CanvasItem *> _get_edited_canvas_items(bool retreive_locked = false, bool remove_canvas_item_if_parent_in_selection = true);
  354. Rect2 _get_encompassing_rect_from_list(List<CanvasItem *> p_list);
  355. void _expand_encompassing_rect_using_children(Rect2 &p_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);
  356. Rect2 _get_encompassing_rect(const Node *p_node);
  357. Object *_get_editor_data(Object *p_what);
  358. void _keying_changed();
  359. void _unhandled_key_input(const Ref<InputEvent> &p_ev);
  360. void _draw_text_at_position(Point2 p_position, String p_string, Margin p_side);
  361. void _draw_margin_at_position(int p_value, Point2 p_position, Margin p_side);
  362. void _draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side);
  363. void _draw_straight_line(Point2 p_from, Point2 p_to, Color p_color);
  364. void _draw_rulers();
  365. void _draw_guides();
  366. void _draw_focus();
  367. void _draw_grid();
  368. void _draw_control_helpers(Control *control);
  369. void _draw_selection();
  370. void _draw_axis();
  371. void _draw_bones();
  372. void _draw_invisible_nodes_positions(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
  373. void _draw_locks_and_groups(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
  374. void _draw_hover();
  375. void _draw_viewport();
  376. bool _gui_input_anchors(const Ref<InputEvent> &p_event);
  377. bool _gui_input_move(const Ref<InputEvent> &p_event);
  378. bool _gui_input_open_scene_on_double_click(const Ref<InputEvent> &p_event);
  379. bool _gui_input_scale(const Ref<InputEvent> &p_event);
  380. bool _gui_input_pivot(const Ref<InputEvent> &p_event);
  381. bool _gui_input_resize(const Ref<InputEvent> &p_event);
  382. bool _gui_input_rotate(const Ref<InputEvent> &p_event);
  383. bool _gui_input_select(const Ref<InputEvent> &p_event);
  384. bool _gui_input_zoom_or_pan(const Ref<InputEvent> &p_event);
  385. bool _gui_input_rulers_and_guides(const Ref<InputEvent> &p_event);
  386. bool _gui_input_hover(const Ref<InputEvent> &p_event);
  387. void _gui_input_viewport(const Ref<InputEvent> &p_event);
  388. void _focus_selection(int p_op);
  389. void _solve_IK(Node2D *leaf_node, Point2 target_position);
  390. void _snap_if_closer_float(float p_value, float p_target_snap, float &r_current_snap, bool &r_snapped, float p_radius = 10.0);
  391. void _snap_if_closer_point(Point2 p_value, Point2 p_target_snap, Point2 &r_current_snap, bool (&r_snapped)[2], real_t rotation = 0.0, float p_radius = 10.0);
  392. void _snap_other_nodes(Point2 p_value, Point2 &r_current_snap, bool (&r_snapped)[2], const Node *p_current, const CanvasItem *p_to_snap = NULL);
  393. void _set_anchors_preset(Control::LayoutPreset p_preset);
  394. void _set_margins_preset(Control::LayoutPreset p_preset);
  395. void _set_anchors_and_margins_preset(Control::LayoutPreset p_preset);
  396. HBoxContainer *zoom_hb;
  397. void _zoom_on_position(float p_zoom, Point2 p_position = Point2());
  398. void _button_zoom_minus();
  399. void _button_zoom_reset();
  400. void _button_zoom_plus();
  401. void _button_toggle_snap(bool p_status);
  402. void _button_tool_select(int p_index);
  403. HSplitContainer *palette_split;
  404. VSplitContainer *bottom_split;
  405. bool bone_list_dirty;
  406. void _queue_update_bone_list();
  407. void _update_bone_list();
  408. void _tree_changed(Node *);
  409. void _popup_warning_temporarily(Control *p_control, const float p_duration);
  410. void _popup_warning_depop(Control *p_control);
  411. friend class CanvasItemEditorPlugin;
  412. protected:
  413. void _notification(int p_what);
  414. static void _bind_methods();
  415. void end_drag();
  416. void box_selection_start(Point2 &click);
  417. bool box_selection_end();
  418. HBoxContainer *get_panel_hb() { return hb; }
  419. struct compare_items_x {
  420. bool operator()(const CanvasItem *a, const CanvasItem *b) const {
  421. return a->get_global_transform().elements[2].x < b->get_global_transform().elements[2].x;
  422. }
  423. };
  424. struct compare_items_y {
  425. bool operator()(const CanvasItem *a, const CanvasItem *b) const {
  426. return a->get_global_transform().elements[2].y < b->get_global_transform().elements[2].y;
  427. }
  428. };
  429. struct proj_vector2_x {
  430. float get(const Vector2 &v) { return v.x; }
  431. void set(Vector2 &v, float f) { v.x = f; }
  432. };
  433. struct proj_vector2_y {
  434. float get(const Vector2 &v) { return v.y; }
  435. void set(Vector2 &v, float f) { v.y = f; }
  436. };
  437. template <class P, class C>
  438. void space_selected_items();
  439. static CanvasItemEditor *singleton;
  440. public:
  441. enum SnapMode {
  442. SNAP_GRID = 1 << 0,
  443. SNAP_GUIDES = 1 << 1,
  444. SNAP_PIXEL = 1 << 2,
  445. SNAP_NODE_PARENT = 1 << 3,
  446. SNAP_NODE_ANCHORS = 1 << 4,
  447. SNAP_NODE_SIDES = 1 << 5,
  448. SNAP_NODE_CENTER = 1 << 6,
  449. SNAP_OTHER_NODES = 1 << 7,
  450. SNAP_DEFAULT = SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL,
  451. };
  452. Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, const CanvasItem *p_canvas_item = NULL, unsigned int p_forced_modes = 0);
  453. float snap_angle(float p_target, float p_start = 0) const;
  454. Transform2D get_canvas_transform() const { return transform; }
  455. static CanvasItemEditor *get_singleton() { return singleton; }
  456. Dictionary get_state() const;
  457. void set_state(const Dictionary &p_state);
  458. void add_control_to_menu_panel(Control *p_control);
  459. void remove_control_from_menu_panel(Control *p_control);
  460. void add_control_to_info_overlay(Control *p_control);
  461. void remove_control_from_info_overlay(Control *p_control);
  462. HSplitContainer *get_palette_split();
  463. VSplitContainer *get_bottom_split();
  464. Control *get_viewport_control() { return viewport; }
  465. void update_viewport();
  466. Tool get_current_tool() { return tool; }
  467. void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  468. void edit(CanvasItem *p_canvas_item);
  469. void focus_selection();
  470. CanvasItemEditor(EditorNode *p_editor);
  471. };
  472. class CanvasItemEditorPlugin : public EditorPlugin {
  473. GDCLASS(CanvasItemEditorPlugin, EditorPlugin);
  474. CanvasItemEditor *canvas_item_editor;
  475. EditorNode *editor;
  476. public:
  477. virtual String get_name() const { return "2D"; }
  478. bool has_main_screen() const { return true; }
  479. virtual void edit(Object *p_object);
  480. virtual bool handles(Object *p_object) const;
  481. virtual void make_visible(bool p_visible);
  482. virtual Dictionary get_state() const;
  483. virtual void set_state(const Dictionary &p_state);
  484. CanvasItemEditor *get_canvas_item_editor() { return canvas_item_editor; }
  485. CanvasItemEditorPlugin(EditorNode *p_node);
  486. ~CanvasItemEditorPlugin();
  487. };
  488. class CanvasItemEditorViewport : public Control {
  489. GDCLASS(CanvasItemEditorViewport, Control);
  490. String default_type;
  491. Vector<String> types;
  492. Vector<String> selected_files;
  493. Node *target_node;
  494. Point2 drop_pos;
  495. EditorNode *editor;
  496. EditorData *editor_data;
  497. CanvasItemEditor *canvas_item_editor;
  498. Node2D *preview_node;
  499. AcceptDialog *accept;
  500. WindowDialog *selector;
  501. Label *selector_label;
  502. Label *label;
  503. Label *label_desc;
  504. VBoxContainer *btn_group;
  505. Ref<ButtonGroup> button_group;
  506. void _on_mouse_exit();
  507. void _on_select_type(Object *selected);
  508. void _on_change_type_confirmed();
  509. void _on_change_type_closed();
  510. void _create_preview(const Vector<String> &files) const;
  511. void _remove_preview();
  512. bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
  513. bool _only_packed_scenes_selected() const;
  514. void _create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point);
  515. bool _create_instance(Node *parent, String &path, const Point2 &p_point);
  516. void _perform_drop_data();
  517. void _show_resource_type_selector();
  518. static void _bind_methods();
  519. protected:
  520. void _notification(int p_what);
  521. public:
  522. virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const;
  523. virtual void drop_data(const Point2 &p_point, const Variant &p_data);
  524. CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas_item_editor);
  525. ~CanvasItemEditorViewport();
  526. };
  527. #endif