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