canvas_item_editor_plugin.h 21 KB

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