2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* canvas_item_editor_plugin.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2018-01-01 14:40:08 +01:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef CONTROL_EDITOR_PLUGIN_H
|
|
|
|
#define CONTROL_EDITOR_PLUGIN_H
|
|
|
|
|
2017-03-05 14:21:25 +01:00
|
|
|
#include "editor/editor_node.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "editor/editor_plugin.h"
|
|
|
|
#include "scene/2d/canvas_item.h"
|
|
|
|
#include "scene/gui/box_container.h"
|
2016-10-25 21:27:24 +02:00
|
|
|
#include "scene/gui/check_box.h"
|
|
|
|
#include "scene/gui/label.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/gui/panel_container.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/gui/spin_box.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
/**
|
|
|
|
@author Juan Linietsky <reduzio@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2016-10-25 21:27:24 +02:00
|
|
|
class CanvasItemEditorViewport;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class CanvasItemEditorSelectedItem : public Object {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(CanvasItemEditorSelectedItem, Object);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D prev_xform;
|
2014-02-10 02:10:30 +01:00
|
|
|
float prev_rot;
|
|
|
|
Rect2 prev_rect;
|
2017-07-06 22:42:44 +02:00
|
|
|
Vector2 prev_pivot;
|
2017-07-11 00:14:22 +02:00
|
|
|
float prev_anchors[4];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-12 19:11:53 +02:00
|
|
|
Transform2D pre_drag_xform;
|
2017-10-03 22:44:34 +02:00
|
|
|
Rect2 pre_drag_rect;
|
2017-09-12 19:11:53 +02:00
|
|
|
|
2017-11-07 08:58:35 +01:00
|
|
|
List<float> pre_drag_bones_length;
|
|
|
|
List<Dictionary> pre_drag_bones_undo_state;
|
|
|
|
|
|
|
|
Dictionary undo_state;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorSelectedItem() { prev_rot = 0; }
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class CanvasItemEditor : public VBoxContainer {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(CanvasItemEditor, VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
EditorNode *editor;
|
|
|
|
|
|
|
|
enum Tool {
|
|
|
|
TOOL_SELECT,
|
2015-12-13 21:16:13 +01:00
|
|
|
TOOL_LIST_SELECT,
|
2014-02-10 02:10:30 +01:00
|
|
|
TOOL_MOVE,
|
|
|
|
TOOL_ROTATE,
|
2015-12-28 13:38:15 +01:00
|
|
|
TOOL_EDIT_PIVOT,
|
2014-05-02 13:39:12 +02:00
|
|
|
TOOL_PAN,
|
2014-02-10 02:10:30 +01:00
|
|
|
TOOL_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum MenuOption {
|
|
|
|
SNAP_USE,
|
2017-09-17 22:52:41 +02:00
|
|
|
SNAP_USE_NODE_PARENT,
|
|
|
|
SNAP_USE_NODE_ANCHORS,
|
|
|
|
SNAP_USE_NODE_SIDES,
|
2017-11-07 08:58:35 +01:00
|
|
|
SNAP_USE_NODE_CENTER,
|
2017-09-17 22:52:41 +02:00
|
|
|
SNAP_USE_OTHER_NODES,
|
|
|
|
SNAP_USE_GRID,
|
2017-10-18 23:55:02 +02:00
|
|
|
SNAP_USE_GUIDES,
|
2015-02-15 09:00:55 +01:00
|
|
|
SNAP_USE_ROTATION,
|
2015-02-20 13:21:59 +01:00
|
|
|
SNAP_RELATIVE,
|
2014-02-10 02:10:30 +01:00
|
|
|
SNAP_CONFIGURE,
|
|
|
|
SNAP_USE_PIXEL,
|
2017-09-17 22:52:41 +02:00
|
|
|
SHOW_GRID,
|
2017-08-19 18:29:37 +02:00
|
|
|
SHOW_HELPERS,
|
2017-08-29 21:50:18 +02:00
|
|
|
SHOW_RULERS,
|
2017-10-18 23:55:02 +02:00
|
|
|
SHOW_GUIDES,
|
2018-03-02 09:52:13 +01:00
|
|
|
SHOW_ORIGIN,
|
|
|
|
SHOW_VIEWPORT,
|
2014-02-10 02:10:30 +01:00
|
|
|
LOCK_SELECTED,
|
|
|
|
UNLOCK_SELECTED,
|
|
|
|
GROUP_SELECTED,
|
|
|
|
UNGROUP_SELECTED,
|
2017-10-04 00:47:40 +02:00
|
|
|
ANCHORS_AND_MARGINS_PRESET_TOP_LEFT,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_TOP_RIGHT,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_BOTTOM_LEFT,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_BOTTOM_RIGHT,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_CENTER_LEFT,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_CENTER_RIGHT,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_CENTER_TOP,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_CENTER_BOTTOM,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_CENTER,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_TOP_WIDE,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_LEFT_WIDE,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_RIGHT_WIDE,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_BOTTOM_WIDE,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_VCENTER_WIDE,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_HCENTER_WIDE,
|
|
|
|
ANCHORS_AND_MARGINS_PRESET_WIDE,
|
|
|
|
ANCHORS_PRESET_TOP_LEFT,
|
|
|
|
ANCHORS_PRESET_TOP_RIGHT,
|
|
|
|
ANCHORS_PRESET_BOTTOM_LEFT,
|
|
|
|
ANCHORS_PRESET_BOTTOM_RIGHT,
|
|
|
|
ANCHORS_PRESET_CENTER_LEFT,
|
|
|
|
ANCHORS_PRESET_CENTER_RIGHT,
|
|
|
|
ANCHORS_PRESET_CENTER_TOP,
|
|
|
|
ANCHORS_PRESET_CENTER_BOTTOM,
|
|
|
|
ANCHORS_PRESET_CENTER,
|
|
|
|
ANCHORS_PRESET_TOP_WIDE,
|
|
|
|
ANCHORS_PRESET_LEFT_WIDE,
|
|
|
|
ANCHORS_PRESET_RIGHT_WIDE,
|
|
|
|
ANCHORS_PRESET_BOTTOM_WIDE,
|
|
|
|
ANCHORS_PRESET_VCENTER_WIDE,
|
|
|
|
ANCHORS_PRESET_HCENTER_WIDE,
|
|
|
|
ANCHORS_PRESET_WIDE,
|
|
|
|
MARGINS_PRESET_TOP_LEFT,
|
|
|
|
MARGINS_PRESET_TOP_RIGHT,
|
|
|
|
MARGINS_PRESET_BOTTOM_LEFT,
|
|
|
|
MARGINS_PRESET_BOTTOM_RIGHT,
|
|
|
|
MARGINS_PRESET_CENTER_LEFT,
|
|
|
|
MARGINS_PRESET_CENTER_RIGHT,
|
|
|
|
MARGINS_PRESET_CENTER_TOP,
|
|
|
|
MARGINS_PRESET_CENTER_BOTTOM,
|
|
|
|
MARGINS_PRESET_CENTER,
|
|
|
|
MARGINS_PRESET_TOP_WIDE,
|
|
|
|
MARGINS_PRESET_LEFT_WIDE,
|
|
|
|
MARGINS_PRESET_RIGHT_WIDE,
|
|
|
|
MARGINS_PRESET_BOTTOM_WIDE,
|
|
|
|
MARGINS_PRESET_VCENTER_WIDE,
|
|
|
|
MARGINS_PRESET_HCENTER_WIDE,
|
|
|
|
MARGINS_PRESET_WIDE,
|
2014-02-10 02:10:30 +01:00
|
|
|
ANIM_INSERT_KEY,
|
|
|
|
ANIM_INSERT_KEY_EXISTING,
|
|
|
|
ANIM_INSERT_POS,
|
|
|
|
ANIM_INSERT_ROT,
|
|
|
|
ANIM_INSERT_SCALE,
|
|
|
|
ANIM_COPY_POSE,
|
|
|
|
ANIM_PASTE_POSE,
|
2014-05-03 19:36:59 +02:00
|
|
|
ANIM_CLEAR_POSE,
|
|
|
|
VIEW_CENTER_TO_SELECTION,
|
|
|
|
VIEW_FRAME_TO_SELECTION,
|
2014-07-06 16:49:27 +02:00
|
|
|
SKELETON_MAKE_BONES,
|
|
|
|
SKELETON_CLEAR_BONES,
|
2016-09-07 11:10:00 +02:00
|
|
|
SKELETON_SHOW_BONES,
|
2014-07-06 16:49:27 +02:00
|
|
|
SKELETON_SET_IK_CHAIN,
|
|
|
|
SKELETON_CLEAR_IK_CHAIN
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
enum DragType {
|
|
|
|
DRAG_NONE,
|
2017-11-07 08:58:35 +01:00
|
|
|
DRAG_BOX_SELECTION,
|
2014-02-10 02:10:30 +01:00
|
|
|
DRAG_LEFT,
|
|
|
|
DRAG_TOP_LEFT,
|
|
|
|
DRAG_TOP,
|
|
|
|
DRAG_TOP_RIGHT,
|
|
|
|
DRAG_RIGHT,
|
|
|
|
DRAG_BOTTOM_RIGHT,
|
|
|
|
DRAG_BOTTOM,
|
|
|
|
DRAG_BOTTOM_LEFT,
|
2017-07-29 16:57:32 +02:00
|
|
|
DRAG_ANCHOR_TOP_LEFT,
|
|
|
|
DRAG_ANCHOR_TOP_RIGHT,
|
|
|
|
DRAG_ANCHOR_BOTTOM_RIGHT,
|
|
|
|
DRAG_ANCHOR_BOTTOM_LEFT,
|
2017-08-04 19:27:30 +02:00
|
|
|
DRAG_ANCHOR_ALL,
|
2018-09-09 22:17:47 +02:00
|
|
|
DRAG_MOVE,
|
2014-02-10 02:10:30 +01:00
|
|
|
DRAG_ROTATE,
|
|
|
|
DRAG_PIVOT,
|
2017-10-18 23:55:02 +02:00
|
|
|
DRAG_V_GUIDE,
|
|
|
|
DRAG_H_GUIDE,
|
|
|
|
DRAG_DOUBLE_GUIDE,
|
2018-04-22 23:27:46 +02:00
|
|
|
DRAG_KEY_MOVE,
|
|
|
|
DRAG_PAN
|
2014-05-09 09:11:24 +02:00
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
EditorSelection *editor_selection;
|
2017-11-07 08:58:35 +01:00
|
|
|
bool selection_menu_additive_selection;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Tool tool;
|
|
|
|
Control *viewport;
|
2017-08-29 21:50:18 +02:00
|
|
|
Control *viewport_scrollable;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
HScrollBar *h_scroll;
|
|
|
|
VScrollBar *v_scroll;
|
|
|
|
HBoxContainer *hb;
|
|
|
|
|
2017-08-19 18:29:37 +02:00
|
|
|
ToolButton *zoom_minus;
|
|
|
|
ToolButton *zoom_reset;
|
|
|
|
ToolButton *zoom_plus;
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D transform;
|
2017-09-17 22:52:41 +02:00
|
|
|
bool show_grid;
|
2017-08-29 21:50:18 +02:00
|
|
|
bool show_rulers;
|
2017-10-18 23:55:02 +02:00
|
|
|
bool show_guides;
|
2018-03-02 09:52:13 +01:00
|
|
|
bool show_origin;
|
|
|
|
bool show_viewport;
|
2017-08-19 18:29:37 +02:00
|
|
|
bool show_helpers;
|
2014-02-10 02:10:30 +01:00
|
|
|
float zoom;
|
2018-03-15 15:12:16 +01:00
|
|
|
Point2 view_offset;
|
|
|
|
Point2 previous_update_view_offset;
|
2017-08-29 21:50:18 +02:00
|
|
|
|
|
|
|
Point2 grid_offset;
|
|
|
|
Point2 grid_step;
|
2017-08-31 21:54:42 +02:00
|
|
|
int grid_step_multiplier;
|
2017-08-29 21:50:18 +02:00
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
float snap_rotation_step;
|
|
|
|
float snap_rotation_offset;
|
2017-09-17 22:52:41 +02:00
|
|
|
bool snap_active;
|
|
|
|
bool snap_node_parent;
|
|
|
|
bool snap_node_anchors;
|
|
|
|
bool snap_node_sides;
|
2017-11-07 08:58:35 +01:00
|
|
|
bool snap_node_center;
|
2017-09-17 22:52:41 +02:00
|
|
|
bool snap_other_nodes;
|
2015-02-15 09:00:55 +01:00
|
|
|
bool snap_grid;
|
2017-10-18 23:55:02 +02:00
|
|
|
bool snap_guides;
|
2015-02-15 09:00:55 +01:00
|
|
|
bool snap_rotation;
|
2015-02-20 13:21:59 +01:00
|
|
|
bool snap_relative;
|
2015-02-15 09:00:55 +01:00
|
|
|
bool snap_pixel;
|
2016-09-07 11:10:00 +02:00
|
|
|
bool skeleton_show_bones;
|
2014-02-10 02:10:30 +01:00
|
|
|
bool key_pos;
|
|
|
|
bool key_rot;
|
|
|
|
bool key_scale;
|
|
|
|
|
|
|
|
MenuOption last_option;
|
|
|
|
|
2015-11-04 22:39:07 +01:00
|
|
|
struct _SelectResult {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItem *item;
|
2017-12-29 23:06:03 +01:00
|
|
|
float z_index;
|
2015-11-04 22:39:07 +01:00
|
|
|
bool has_z;
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ bool operator<(const _SelectResult &p_rr) const {
|
2017-12-29 23:06:03 +01:00
|
|
|
return has_z && p_rr.has_z ? p_rr.z_index < z_index : p_rr.has_z;
|
2015-11-04 22:39:07 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
Vector<_SelectResult> selection_results;
|
2018-06-12 11:01:24 +02:00
|
|
|
|
|
|
|
struct _HoverResult {
|
|
|
|
|
|
|
|
Point2 position;
|
|
|
|
Ref<Texture> icon;
|
|
|
|
String name;
|
|
|
|
};
|
|
|
|
Vector<_HoverResult> hovering_results;
|
2015-11-04 22:39:07 +01:00
|
|
|
|
2014-07-06 16:49:27 +02:00
|
|
|
struct BoneList {
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D xform;
|
2018-05-04 21:46:32 +02:00
|
|
|
float length;
|
|
|
|
uint64_t last_pass;
|
2014-07-06 16:49:27 +02:00
|
|
|
};
|
2018-05-04 21:46:32 +02:00
|
|
|
|
2015-04-21 00:38:02 +02:00
|
|
|
uint64_t bone_last_frame;
|
2018-05-04 21:46:32 +02:00
|
|
|
|
|
|
|
struct BoneKey {
|
|
|
|
ObjectID from;
|
|
|
|
ObjectID to;
|
|
|
|
_FORCE_INLINE_ bool operator<(const BoneKey &p_key) const {
|
|
|
|
if (from == p_key.from)
|
|
|
|
return to < p_key.to;
|
|
|
|
else
|
|
|
|
return from < p_key.from;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Map<BoneKey, BoneList> bone_list;
|
2015-04-21 00:38:02 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
struct PoseClipboard {
|
|
|
|
Vector2 pos;
|
|
|
|
Vector2 scale;
|
|
|
|
float rot;
|
|
|
|
ObjectID id;
|
|
|
|
};
|
|
|
|
List<PoseClipboard> pose_clipboard;
|
|
|
|
|
|
|
|
ToolButton *select_button;
|
2015-12-13 21:16:13 +01:00
|
|
|
ToolButton *list_select_button;
|
2014-02-10 02:10:30 +01:00
|
|
|
ToolButton *move_button;
|
|
|
|
ToolButton *rotate_button;
|
|
|
|
|
2017-09-17 22:52:41 +02:00
|
|
|
ToolButton *snap_button;
|
|
|
|
MenuButton *snap_config_menu;
|
|
|
|
PopupMenu *smartsnap_config_popup;
|
|
|
|
|
2015-12-28 13:38:15 +01:00
|
|
|
ToolButton *pivot_button;
|
2014-05-02 13:39:12 +02:00
|
|
|
ToolButton *pan_button;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ToolButton *lock_button;
|
|
|
|
ToolButton *unlock_button;
|
|
|
|
|
|
|
|
ToolButton *group_button;
|
|
|
|
ToolButton *ungroup_button;
|
|
|
|
|
2017-09-17 22:52:41 +02:00
|
|
|
MenuButton *skeleton_menu;
|
2014-02-10 02:10:30 +01:00
|
|
|
MenuButton *view_menu;
|
2014-07-06 16:49:27 +02:00
|
|
|
HBoxContainer *animation_hb;
|
2014-02-10 02:10:30 +01:00
|
|
|
MenuButton *animation_menu;
|
2017-10-04 00:47:40 +02:00
|
|
|
|
|
|
|
MenuButton *presets_menu;
|
|
|
|
PopupMenu *anchors_and_margins_popup;
|
|
|
|
PopupMenu *anchors_popup;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
Button *key_loc_button;
|
|
|
|
Button *key_rot_button;
|
|
|
|
Button *key_scale_button;
|
|
|
|
Button *key_insert_button;
|
|
|
|
|
2015-11-04 22:39:07 +01:00
|
|
|
PopupMenu *selection_menu;
|
|
|
|
|
2017-08-29 21:50:18 +02:00
|
|
|
Control *top_ruler;
|
|
|
|
Control *left_ruler;
|
|
|
|
|
2017-11-07 08:58:35 +01:00
|
|
|
DragType drag_type;
|
2014-02-10 02:10:30 +01:00
|
|
|
Point2 drag_from;
|
2017-11-07 08:58:35 +01:00
|
|
|
Point2 drag_to;
|
|
|
|
Point2 drag_rotation_center;
|
|
|
|
List<CanvasItem *> drag_selection;
|
|
|
|
int dragged_guide_index;
|
|
|
|
Point2 dragged_guide_pos;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool updating_value_dialog;
|
|
|
|
|
2017-11-07 08:58:35 +01:00
|
|
|
Point2 box_selecting_to;
|
2017-10-18 23:55:02 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Ref<StyleBoxTexture> select_sb;
|
|
|
|
Ref<Texture> select_handle;
|
2017-07-11 00:14:22 +02:00
|
|
|
Ref<Texture> anchor_handle;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-20 00:01:12 +02:00
|
|
|
Ref<ShortCut> drag_pivot_shortcut;
|
|
|
|
Ref<ShortCut> set_pivot_shortcut;
|
2017-08-31 21:54:42 +02:00
|
|
|
Ref<ShortCut> multiply_grid_step_shortcut;
|
|
|
|
Ref<ShortCut> divide_grid_step_shortcut;
|
2017-08-20 00:01:12 +02:00
|
|
|
|
2018-04-24 21:55:28 +02:00
|
|
|
void _find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, int p_limit = 0, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
|
|
|
|
void _get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, int p_limit = 0);
|
2018-05-15 15:18:46 +02:00
|
|
|
void _get_bones_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items);
|
2018-04-24 21:55:28 +02:00
|
|
|
|
2018-03-08 21:35:41 +01:00
|
|
|
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());
|
2017-11-07 08:58:35 +01:00
|
|
|
bool _select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append);
|
2015-11-04 22:39:07 +01:00
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
ConfirmationDialog *snap_dialog;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
CanvasItem *ref_item;
|
|
|
|
|
|
|
|
void _add_canvas_item(CanvasItem *p_canvas_item);
|
|
|
|
|
2017-11-07 08:58:35 +01:00
|
|
|
void _save_canvas_item_state(List<CanvasItem *> p_canvas_items, bool save_bones = false);
|
|
|
|
void _restore_canvas_item_state(List<CanvasItem *> p_canvas_items, bool restore_bones = false);
|
|
|
|
void _commit_canvas_item_state(List<CanvasItem *> p_canvas_items, String action_name, bool commit_bones = false);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-07 23:30:54 +02:00
|
|
|
Vector2 _anchor_to_position(const Control *p_control, Vector2 anchor);
|
|
|
|
Vector2 _position_to_anchor(const Control *p_control, Vector2 position);
|
2017-07-11 00:14:22 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _popup_callback(int p_op);
|
|
|
|
bool updating_scroll;
|
|
|
|
void _update_scroll(float);
|
|
|
|
void _update_scrollbars();
|
|
|
|
void _append_canvas_item(CanvasItem *p_item);
|
2015-02-15 09:00:55 +01:00
|
|
|
void _snap_changed();
|
2015-11-04 22:39:07 +01:00
|
|
|
void _selection_result_pressed(int);
|
|
|
|
void _selection_menu_hide();
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
UndoRedo *undo_redo;
|
2018-05-04 21:46:32 +02:00
|
|
|
bool _build_bones_list(Node *p_node);
|
2018-05-15 15:18:46 +02:00
|
|
|
bool _get_bone_shape(Vector<Vector2> *shape, Vector<Vector2> *outline_shape, Map<BoneKey, BoneList>::Element *bone);
|
2017-08-28 21:51:56 +02:00
|
|
|
|
2017-11-07 08:58:35 +01:00
|
|
|
List<CanvasItem *> _get_edited_canvas_items(bool retreive_locked = false, bool remove_canvas_item_if_parent_in_selection = true);
|
|
|
|
Rect2 _get_encompassing_rect_from_list(List<CanvasItem *> p_list);
|
2018-07-29 23:09:59 +02:00
|
|
|
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);
|
2018-03-08 21:35:41 +01:00
|
|
|
Rect2 _get_encompassing_rect(const Node *p_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Object *_get_editor_data(Object *p_what);
|
|
|
|
|
2016-01-09 12:35:57 +01:00
|
|
|
void _keying_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
void _unhandled_key_input(const Ref<InputEvent> &p_ev);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-18 00:42:49 +02:00
|
|
|
void _draw_text_at_position(Point2 p_position, String p_string, Margin p_side);
|
|
|
|
void _draw_margin_at_position(int p_value, Point2 p_position, Margin p_side);
|
2017-08-02 18:33:06 +02:00
|
|
|
void _draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side);
|
2017-11-07 08:58:35 +01:00
|
|
|
void _draw_straight_line(Point2 p_from, Point2 p_to, Color p_color);
|
2017-08-02 18:33:06 +02:00
|
|
|
|
2017-08-29 21:50:18 +02:00
|
|
|
void _draw_rulers();
|
2017-10-18 23:55:02 +02:00
|
|
|
void _draw_guides();
|
2017-08-28 21:51:56 +02:00
|
|
|
void _draw_focus();
|
|
|
|
void _draw_grid();
|
|
|
|
void _draw_selection();
|
|
|
|
void _draw_axis();
|
|
|
|
void _draw_bones();
|
2018-03-10 11:56:27 +01:00
|
|
|
void _draw_invisible_nodes_positions(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
|
2018-03-08 21:12:49 +01:00
|
|
|
void _draw_locks_and_groups(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
|
2018-03-12 23:32:25 +01:00
|
|
|
void _draw_hover();
|
2017-08-28 21:51:56 +02:00
|
|
|
|
|
|
|
void _draw_viewport();
|
2017-11-07 08:58:35 +01:00
|
|
|
|
|
|
|
bool _gui_input_anchors(const Ref<InputEvent> &p_event);
|
|
|
|
bool _gui_input_move(const Ref<InputEvent> &p_event);
|
|
|
|
bool _gui_input_open_scene_on_double_click(const Ref<InputEvent> &p_event);
|
|
|
|
bool _gui_input_pivot(const Ref<InputEvent> &p_event);
|
|
|
|
bool _gui_input_resize(const Ref<InputEvent> &p_event);
|
|
|
|
bool _gui_input_rotate(const Ref<InputEvent> &p_event);
|
|
|
|
bool _gui_input_select(const Ref<InputEvent> &p_event);
|
|
|
|
bool _gui_input_zoom_or_pan(const Ref<InputEvent> &p_event);
|
|
|
|
bool _gui_input_rulers_and_guides(const Ref<InputEvent> &p_event);
|
2018-03-12 23:32:25 +01:00
|
|
|
bool _gui_input_hover(const Ref<InputEvent> &p_event);
|
2017-08-29 21:50:18 +02:00
|
|
|
|
2017-10-15 22:33:25 +02:00
|
|
|
void _gui_input_viewport(const Ref<InputEvent> &p_event);
|
|
|
|
|
2016-07-28 21:37:52 +02:00
|
|
|
void _focus_selection(int p_op);
|
|
|
|
|
2017-11-07 08:58:35 +01:00
|
|
|
void _solve_IK(Node2D *leaf_node, Point2 target_position);
|
|
|
|
|
2017-10-18 23:55:02 +02:00
|
|
|
void _snap_if_closer_float(float p_value, float p_target_snap, float &r_current_snap, bool &r_snapped, float p_radius = 10.0);
|
|
|
|
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);
|
|
|
|
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);
|
2017-09-07 23:30:54 +02:00
|
|
|
|
2017-08-11 18:16:28 +02:00
|
|
|
void _set_anchors_preset(Control::LayoutPreset p_preset);
|
2017-10-04 00:47:40 +02:00
|
|
|
void _set_margins_preset(Control::LayoutPreset p_preset);
|
|
|
|
void _set_anchors_and_margins_preset(Control::LayoutPreset p_preset);
|
2015-08-24 06:00:39 +02:00
|
|
|
|
2017-11-07 08:58:35 +01:00
|
|
|
HBoxContainer *zoom_hb;
|
2017-10-01 11:30:38 +02:00
|
|
|
void _zoom_on_position(float p_zoom, Point2 p_position = Point2());
|
2017-11-07 08:58:35 +01:00
|
|
|
void _button_zoom_minus();
|
|
|
|
void _button_zoom_reset();
|
|
|
|
void _button_zoom_plus();
|
|
|
|
void _button_toggle_snap(bool p_status);
|
|
|
|
void _button_tool_select(int p_index);
|
2017-09-17 22:52:41 +02:00
|
|
|
|
2014-12-28 23:37:25 +01:00
|
|
|
HSplitContainer *palette_split;
|
2015-01-12 00:52:42 +01:00
|
|
|
VSplitContainer *bottom_split;
|
2014-12-28 23:37:25 +01:00
|
|
|
|
2018-05-04 23:11:28 +02:00
|
|
|
bool bone_list_dirty;
|
|
|
|
void _queue_update_bone_list();
|
|
|
|
void _update_bone_list();
|
|
|
|
void _tree_changed(Node *);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
friend class CanvasItemEditorPlugin;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
protected:
|
2014-02-10 02:10:30 +01:00
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
void end_drag();
|
2017-03-05 16:44:50 +01:00
|
|
|
void box_selection_start(Point2 &click);
|
2014-02-10 02:10:30 +01:00
|
|
|
bool box_selection_end();
|
|
|
|
|
|
|
|
HBoxContainer *get_panel_hb() { return hb; }
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
struct compare_items_x {
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator()(const CanvasItem *a, const CanvasItem *b) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
return a->get_global_transform().elements[2].x < b->get_global_transform().elements[2].x;
|
|
|
|
}
|
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
struct compare_items_y {
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator()(const CanvasItem *a, const CanvasItem *b) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
return a->get_global_transform().elements[2].y < b->get_global_transform().elements[2].y;
|
|
|
|
}
|
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
struct proj_vector2_x {
|
2017-03-05 16:44:50 +01:00
|
|
|
float get(const Vector2 &v) { return v.x; }
|
|
|
|
void set(Vector2 &v, float f) { v.x = f; }
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
struct proj_vector2_y {
|
2017-03-05 16:44:50 +01:00
|
|
|
float get(const Vector2 &v) { return v.y; }
|
|
|
|
void set(Vector2 &v, float f) { v.y = f; }
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
template <class P, class C>
|
|
|
|
void space_selected_items();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static CanvasItemEditor *singleton;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-09-07 23:30:54 +02:00
|
|
|
enum SnapMode {
|
|
|
|
SNAP_GRID = 1 << 0,
|
2017-10-18 23:55:02 +02:00
|
|
|
SNAP_GUIDES = 1 << 1,
|
|
|
|
SNAP_PIXEL = 1 << 2,
|
|
|
|
SNAP_NODE_PARENT = 1 << 3,
|
|
|
|
SNAP_NODE_ANCHORS = 1 << 4,
|
|
|
|
SNAP_NODE_SIDES = 1 << 5,
|
2017-11-07 08:58:35 +01:00
|
|
|
SNAP_NODE_CENTER = 1 << 6,
|
|
|
|
SNAP_OTHER_NODES = 1 << 7,
|
2017-10-18 23:55:02 +02:00
|
|
|
|
2017-11-07 08:58:35 +01:00
|
|
|
SNAP_DEFAULT = SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL,
|
2017-09-07 23:30:54 +02:00
|
|
|
};
|
|
|
|
|
2017-09-17 22:52:41 +02:00
|
|
|
Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, const CanvasItem *p_canvas_item = NULL, unsigned int p_forced_modes = 0);
|
2015-02-15 09:00:55 +01:00
|
|
|
float snap_angle(float p_target, float p_start = 0) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D get_canvas_transform() const { return transform; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static CanvasItemEditor *get_singleton() { return singleton; }
|
|
|
|
Dictionary get_state() const;
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_state(const Dictionary &p_state);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void add_control_to_menu_panel(Control *p_control);
|
2018-02-13 22:21:19 +01:00
|
|
|
void remove_control_from_menu_panel(Control *p_control);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-12-28 23:37:25 +01:00
|
|
|
HSplitContainer *get_palette_split();
|
2015-01-12 00:52:42 +01:00
|
|
|
VSplitContainer *get_bottom_split();
|
2014-12-28 23:37:25 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Control *get_viewport_control() { return viewport; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
|
2014-02-10 02:10:30 +01:00
|
|
|
void edit(CanvasItem *p_canvas_item);
|
2016-07-28 21:37:52 +02:00
|
|
|
|
|
|
|
void focus_selection();
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
CanvasItemEditor(EditorNode *p_editor);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CanvasItemEditorPlugin : public EditorPlugin {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(CanvasItemEditorPlugin, EditorPlugin);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
CanvasItemEditor *canvas_item_editor;
|
|
|
|
EditorNode *editor;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual String get_name() const { return "2D"; }
|
|
|
|
bool has_main_screen() const { return true; }
|
|
|
|
virtual void edit(Object *p_object);
|
|
|
|
virtual bool handles(Object *p_object) const;
|
|
|
|
virtual void make_visible(bool p_visible);
|
|
|
|
virtual Dictionary get_state() const;
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_state(const Dictionary &p_state);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
CanvasItemEditor *get_canvas_item_editor() { return canvas_item_editor; }
|
|
|
|
|
|
|
|
CanvasItemEditorPlugin(EditorNode *p_node);
|
|
|
|
~CanvasItemEditorPlugin();
|
|
|
|
};
|
|
|
|
|
2017-01-25 15:41:19 +01:00
|
|
|
class CanvasItemEditorViewport : public Control {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(CanvasItemEditorViewport, Control);
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
String default_type;
|
|
|
|
Vector<String> types;
|
|
|
|
|
|
|
|
Vector<String> selected_files;
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *target_node;
|
2016-10-25 21:27:24 +02:00
|
|
|
Point2 drop_pos;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
EditorNode *editor;
|
|
|
|
EditorData *editor_data;
|
|
|
|
CanvasItemEditor *canvas;
|
2017-09-02 21:47:16 +02:00
|
|
|
Node2D *preview_node;
|
2017-03-05 16:44:50 +01:00
|
|
|
AcceptDialog *accept;
|
|
|
|
WindowDialog *selector;
|
|
|
|
Label *selector_label;
|
|
|
|
Label *label;
|
|
|
|
Label *label_desc;
|
|
|
|
VBoxContainer *btn_group;
|
2017-01-10 05:04:31 +01:00
|
|
|
Ref<ButtonGroup> button_group;
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
void _on_mouse_exit();
|
2017-03-05 16:44:50 +01:00
|
|
|
void _on_select_type(Object *selected);
|
2017-11-12 10:50:06 +01:00
|
|
|
void _on_change_type_confirmed();
|
|
|
|
void _on_change_type_closed();
|
2016-10-25 21:27:24 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _create_preview(const Vector<String> &files) const;
|
2016-10-25 21:27:24 +02:00
|
|
|
void _remove_preview();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
|
2018-01-09 07:05:15 +01:00
|
|
|
bool _only_packed_scenes_selected() const;
|
2017-03-05 16:44:50 +01:00
|
|
|
void _create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point);
|
|
|
|
bool _create_instance(Node *parent, String &path, const Point2 &p_point);
|
2016-10-25 21:27:24 +02:00
|
|
|
void _perform_drop_data();
|
2017-11-22 03:28:02 +01:00
|
|
|
void _show_resource_type_selector();
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
public:
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const;
|
|
|
|
virtual void drop_data(const Point2 &p_point, const Variant &p_data);
|
2016-10-25 21:27:24 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas);
|
2017-08-24 18:51:28 +02:00
|
|
|
~CanvasItemEditorViewport();
|
2016-10-25 21:27:24 +02:00
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|