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