2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* canvas_item_editor_plugin.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
2017-01-02 05:01:57 +08:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 06:11:42 +08:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 09:10:30 +08: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef CONTROL_EDITOR_PLUGIN_H
|
|
|
|
#define CONTROL_EDITOR_PLUGIN_H
|
|
|
|
|
2017-03-05 21:21:25 +08:00
|
|
|
#include "editor/editor_node.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "editor/editor_plugin.h"
|
|
|
|
#include "scene/2d/canvas_item.h"
|
|
|
|
#include "scene/gui/box_container.h"
|
2016-10-26 03:27:24 +08:00
|
|
|
#include "scene/gui/check_box.h"
|
|
|
|
#include "scene/gui/label.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
#include "scene/gui/panel_container.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "scene/gui/spin_box.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
/**
|
|
|
|
@author Juan Linietsky <reduzio@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2016-10-26 03:27:24 +08:00
|
|
|
class CanvasItemEditorViewport;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
class CanvasItemEditorSelectedItem : public Object {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(CanvasItemEditorSelectedItem, Object);
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
public:
|
|
|
|
Variant undo_state;
|
|
|
|
Vector2 undo_pivot;
|
|
|
|
|
2017-01-11 11:52:51 +08:00
|
|
|
Transform2D prev_xform;
|
2014-02-10 09:10:30 +08:00
|
|
|
float prev_rot;
|
|
|
|
Rect2 prev_rect;
|
2017-07-07 04:42:44 +08:00
|
|
|
Vector2 prev_pivot;
|
2017-07-11 06:14:22 +08:00
|
|
|
float prev_anchors[4];
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-09-13 01:11:53 +08:00
|
|
|
Transform2D pre_drag_xform;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
CanvasItemEditorSelectedItem() { prev_rot = 0; }
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class CanvasItemEditor : public VBoxContainer {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(CanvasItemEditor, VBoxContainer);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
EditorNode *editor;
|
|
|
|
|
|
|
|
enum Tool {
|
|
|
|
|
|
|
|
TOOL_SELECT,
|
2015-12-14 04:16:13 +08:00
|
|
|
TOOL_LIST_SELECT,
|
2014-02-10 09:10:30 +08:00
|
|
|
TOOL_MOVE,
|
|
|
|
TOOL_ROTATE,
|
2015-12-28 20:38:15 +08:00
|
|
|
TOOL_EDIT_PIVOT,
|
2014-05-02 19:39:12 +08:00
|
|
|
TOOL_PAN,
|
2014-02-10 09:10:30 +08:00
|
|
|
TOOL_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum MenuOption {
|
|
|
|
SNAP_USE,
|
2015-02-15 16:00:55 +08:00
|
|
|
SNAP_SHOW_GRID,
|
|
|
|
SNAP_USE_ROTATION,
|
2015-02-20 20:21:59 +08:00
|
|
|
SNAP_RELATIVE,
|
2014-02-10 09:10:30 +08:00
|
|
|
SNAP_CONFIGURE,
|
|
|
|
SNAP_USE_PIXEL,
|
2017-08-20 00:29:37 +08:00
|
|
|
SHOW_HELPERS,
|
2017-08-30 03:50:18 +08:00
|
|
|
SHOW_RULERS,
|
2014-02-10 09:10:30 +08:00
|
|
|
LOCK_SELECTED,
|
|
|
|
UNLOCK_SELECTED,
|
|
|
|
GROUP_SELECTED,
|
|
|
|
UNGROUP_SELECTED,
|
2015-08-24 12:00:39 +08:00
|
|
|
ANCHOR_ALIGN_TOP_LEFT,
|
|
|
|
ANCHOR_ALIGN_TOP_RIGHT,
|
|
|
|
ANCHOR_ALIGN_BOTTOM_LEFT,
|
|
|
|
ANCHOR_ALIGN_BOTTOM_RIGHT,
|
|
|
|
ANCHOR_ALIGN_CENTER_LEFT,
|
|
|
|
ANCHOR_ALIGN_CENTER_RIGHT,
|
|
|
|
ANCHOR_ALIGN_CENTER_TOP,
|
|
|
|
ANCHOR_ALIGN_CENTER_BOTTOM,
|
|
|
|
ANCHOR_ALIGN_CENTER,
|
|
|
|
ANCHOR_ALIGN_TOP_WIDE,
|
|
|
|
ANCHOR_ALIGN_LEFT_WIDE,
|
|
|
|
ANCHOR_ALIGN_RIGHT_WIDE,
|
|
|
|
ANCHOR_ALIGN_BOTTOM_WIDE,
|
|
|
|
ANCHOR_ALIGN_VCENTER_WIDE,
|
|
|
|
ANCHOR_ALIGN_HCENTER_WIDE,
|
|
|
|
ANCHOR_ALIGN_WIDE,
|
2017-07-09 21:54:49 +08:00
|
|
|
ANCHOR_ALIGN_WIDE_FIT,
|
2014-02-10 09:10:30 +08: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-04 01:36:59 +08:00
|
|
|
ANIM_CLEAR_POSE,
|
|
|
|
VIEW_CENTER_TO_SELECTION,
|
|
|
|
VIEW_FRAME_TO_SELECTION,
|
2014-07-06 22:49:27 +08:00
|
|
|
SKELETON_MAKE_BONES,
|
|
|
|
SKELETON_CLEAR_BONES,
|
2016-09-07 17:10:00 +08:00
|
|
|
SKELETON_SHOW_BONES,
|
2014-07-06 22:49:27 +08:00
|
|
|
SKELETON_SET_IK_CHAIN,
|
|
|
|
SKELETON_CLEAR_IK_CHAIN
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
enum DragType {
|
|
|
|
DRAG_NONE,
|
|
|
|
DRAG_LEFT,
|
|
|
|
DRAG_TOP_LEFT,
|
|
|
|
DRAG_TOP,
|
|
|
|
DRAG_TOP_RIGHT,
|
|
|
|
DRAG_RIGHT,
|
|
|
|
DRAG_BOTTOM_RIGHT,
|
|
|
|
DRAG_BOTTOM,
|
|
|
|
DRAG_BOTTOM_LEFT,
|
2017-07-29 22:57:32 +08:00
|
|
|
DRAG_ANCHOR_TOP_LEFT,
|
|
|
|
DRAG_ANCHOR_TOP_RIGHT,
|
|
|
|
DRAG_ANCHOR_BOTTOM_RIGHT,
|
|
|
|
DRAG_ANCHOR_BOTTOM_LEFT,
|
2017-08-05 01:27:30 +08:00
|
|
|
DRAG_ANCHOR_ALL,
|
2014-02-10 09:10:30 +08:00
|
|
|
DRAG_ALL,
|
|
|
|
DRAG_ROTATE,
|
|
|
|
DRAG_PIVOT,
|
2017-03-23 07:47:51 +08:00
|
|
|
DRAG_NODE_2D,
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
2014-05-09 15:11:24 +08:00
|
|
|
enum KeyMoveMODE {
|
|
|
|
MOVE_VIEW_BASE,
|
|
|
|
MOVE_LOCAL_BASE,
|
|
|
|
MOVE_LOCAL_WITH_ROT
|
|
|
|
};
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
EditorSelection *editor_selection;
|
2015-11-05 05:39:07 +08:00
|
|
|
bool additive_selection;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
Tool tool;
|
|
|
|
bool first_update;
|
|
|
|
Control *viewport;
|
2017-08-30 03:50:18 +08:00
|
|
|
Control *viewport_base;
|
|
|
|
Control *viewport_scrollable;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
bool can_move_pivot;
|
|
|
|
|
|
|
|
HScrollBar *h_scroll;
|
|
|
|
VScrollBar *v_scroll;
|
|
|
|
HBoxContainer *hb;
|
|
|
|
|
2017-08-20 00:29:37 +08:00
|
|
|
ToolButton *zoom_minus;
|
|
|
|
ToolButton *zoom_reset;
|
|
|
|
ToolButton *zoom_plus;
|
|
|
|
|
2017-01-11 11:52:51 +08:00
|
|
|
Transform2D transform;
|
2017-08-30 03:50:18 +08:00
|
|
|
bool show_rulers;
|
2017-08-20 00:29:37 +08:00
|
|
|
bool show_helpers;
|
2014-02-10 09:10:30 +08:00
|
|
|
float zoom;
|
2017-08-30 03:50:18 +08:00
|
|
|
|
|
|
|
Point2 grid_offset;
|
|
|
|
Point2 grid_step;
|
|
|
|
|
2015-02-15 16:00:55 +08:00
|
|
|
float snap_rotation_step;
|
|
|
|
float snap_rotation_offset;
|
|
|
|
bool snap_grid;
|
|
|
|
bool snap_show_grid;
|
|
|
|
bool snap_rotation;
|
2015-02-20 20:21:59 +08:00
|
|
|
bool snap_relative;
|
2015-02-15 16:00:55 +08:00
|
|
|
bool snap_pixel;
|
2016-09-07 17:10:00 +08:00
|
|
|
bool skeleton_show_bones;
|
2014-02-10 09:10:30 +08:00
|
|
|
bool box_selecting;
|
|
|
|
Point2 box_selecting_to;
|
|
|
|
bool key_pos;
|
|
|
|
bool key_rot;
|
|
|
|
bool key_scale;
|
|
|
|
|
|
|
|
void _tool_select(int p_index);
|
|
|
|
|
|
|
|
MenuOption last_option;
|
|
|
|
|
2015-11-05 05:39:07 +08:00
|
|
|
struct _SelectResult {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
CanvasItem *item;
|
2015-11-05 05:39:07 +08:00
|
|
|
float z;
|
|
|
|
bool has_z;
|
2017-03-05 23:44:50 +08:00
|
|
|
_FORCE_INLINE_ bool operator<(const _SelectResult &p_rr) const {
|
2015-11-05 05:39:07 +08:00
|
|
|
return has_z && p_rr.has_z ? p_rr.z < z : p_rr.has_z;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<_SelectResult> selection_results;
|
|
|
|
|
2014-07-06 22:49:27 +08:00
|
|
|
struct BoneList {
|
|
|
|
|
2017-01-11 11:52:51 +08:00
|
|
|
Transform2D xform;
|
2014-07-06 22:49:27 +08:00
|
|
|
Vector2 from;
|
|
|
|
Vector2 to;
|
|
|
|
ObjectID bone;
|
2015-04-21 06:38:02 +08:00
|
|
|
uint64_t last_pass;
|
2014-07-06 22:49:27 +08:00
|
|
|
};
|
|
|
|
|
2015-04-21 06:38:02 +08:00
|
|
|
uint64_t bone_last_frame;
|
2017-03-05 23:44:50 +08:00
|
|
|
Map<ObjectID, BoneList> bone_list;
|
2015-04-21 06:38:02 +08:00
|
|
|
|
2017-01-11 11:52:51 +08:00
|
|
|
Transform2D bone_orig_xform;
|
2014-07-06 22:49:27 +08:00
|
|
|
|
|
|
|
struct BoneIK {
|
|
|
|
|
|
|
|
Variant orig_state;
|
|
|
|
Vector2 pos;
|
|
|
|
float len;
|
|
|
|
Node2D *node;
|
|
|
|
};
|
|
|
|
|
|
|
|
List<BoneIK> bone_ik_list;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
struct PoseClipboard {
|
|
|
|
|
|
|
|
Vector2 pos;
|
|
|
|
Vector2 scale;
|
|
|
|
float rot;
|
|
|
|
ObjectID id;
|
|
|
|
};
|
|
|
|
|
|
|
|
List<PoseClipboard> pose_clipboard;
|
|
|
|
|
|
|
|
ToolButton *select_button;
|
2015-12-14 04:16:13 +08:00
|
|
|
ToolButton *list_select_button;
|
2014-02-10 09:10:30 +08:00
|
|
|
ToolButton *move_button;
|
|
|
|
ToolButton *rotate_button;
|
|
|
|
|
2015-12-28 20:38:15 +08:00
|
|
|
ToolButton *pivot_button;
|
2014-05-02 19:39:12 +08:00
|
|
|
ToolButton *pan_button;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
ToolButton *lock_button;
|
|
|
|
ToolButton *unlock_button;
|
|
|
|
|
|
|
|
ToolButton *group_button;
|
|
|
|
ToolButton *ungroup_button;
|
|
|
|
|
|
|
|
MenuButton *edit_menu;
|
2016-09-07 17:10:00 +08:00
|
|
|
PopupMenu *skeleton_menu;
|
2014-02-10 09:10:30 +08:00
|
|
|
MenuButton *view_menu;
|
2014-07-06 22:49:27 +08:00
|
|
|
HBoxContainer *animation_hb;
|
2014-02-10 09:10:30 +08:00
|
|
|
MenuButton *animation_menu;
|
2015-08-24 12:00:39 +08:00
|
|
|
MenuButton *anchor_menu;
|
2014-07-06 22:49:27 +08:00
|
|
|
|
|
|
|
Button *key_loc_button;
|
|
|
|
Button *key_rot_button;
|
|
|
|
Button *key_scale_button;
|
|
|
|
Button *key_insert_button;
|
|
|
|
|
2015-11-05 05:39:07 +08:00
|
|
|
PopupMenu *selection_menu;
|
|
|
|
|
2017-08-30 03:50:18 +08:00
|
|
|
Control *top_ruler;
|
|
|
|
Control *left_ruler;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
//PopupMenu *popup;
|
|
|
|
DragType drag;
|
|
|
|
Point2 drag_from;
|
|
|
|
Point2 drag_point_from;
|
|
|
|
bool updating_value_dialog;
|
|
|
|
Point2 display_rotate_from;
|
|
|
|
Point2 display_rotate_to;
|
|
|
|
|
|
|
|
Ref<StyleBoxTexture> select_sb;
|
|
|
|
Ref<Texture> select_handle;
|
2017-07-11 06:14:22 +08:00
|
|
|
Ref<Texture> anchor_handle;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-08-20 06:01:12 +08:00
|
|
|
Ref<ShortCut> drag_pivot_shortcut;
|
|
|
|
Ref<ShortCut> set_pivot_shortcut;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
int handle_len;
|
2016-04-07 18:59:50 +08:00
|
|
|
bool _is_part_of_subscene(CanvasItem *p_item);
|
2017-09-01 05:30:35 +08:00
|
|
|
void _find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform, Vector<_SelectResult> &r_items, int limit = 0);
|
2017-03-05 23:44:50 +08:00
|
|
|
void _find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_node, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform, List<CanvasItem *> *r_items);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-07-19 02:17:55 +08:00
|
|
|
void _select_click_on_empty_area(Point2 p_click_pos, bool p_append, bool p_box_selection);
|
|
|
|
bool _select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append, bool p_drag);
|
2015-11-05 05:39:07 +08:00
|
|
|
|
2015-02-15 16:00:55 +08:00
|
|
|
ConfirmationDialog *snap_dialog;
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
CanvasItem *ref_item;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void _edit_set_pivot(const Vector2 &mouse_pos);
|
2014-02-10 09:10:30 +08:00
|
|
|
void _add_canvas_item(CanvasItem *p_canvas_item);
|
|
|
|
void _remove_canvas_item(CanvasItem *p_canvas_item);
|
|
|
|
void _clear_canvas_items();
|
2017-03-05 23:44:50 +08:00
|
|
|
void _key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode);
|
2017-05-20 23:38:03 +08:00
|
|
|
void _list_select(const Ref<InputEventMouseButton> &b);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-07-29 22:57:32 +08:00
|
|
|
DragType _get_resize_handle_drag_type(const Point2 &p_click, Vector2 &r_point);
|
2017-03-23 07:47:51 +08:00
|
|
|
void _prepare_drag(const Point2 &p_click_pos);
|
2017-07-29 22:57:32 +08:00
|
|
|
DragType _get_anchor_handle_drag_type(const Point2 &p_click, Vector2 &r_point);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-09-15 01:49:11 +08:00
|
|
|
float _anchor_snap(float p_anchor, bool *p_snapped = NULL, float p_opposite_anchor = -1);
|
2017-07-11 06:14:22 +08:00
|
|
|
Vector2 _anchor_to_position(Control *p_control, Vector2 anchor);
|
2017-07-29 22:57:32 +08:00
|
|
|
Vector2 _position_to_anchor(Control *p_control, Vector2 position);
|
2017-07-11 06:14:22 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
void _popup_callback(int p_op);
|
|
|
|
bool updating_scroll;
|
|
|
|
void _update_scroll(float);
|
|
|
|
void _update_scrollbars();
|
2017-09-03 23:04:11 +08:00
|
|
|
void _update_cursor();
|
2017-03-05 23:44:50 +08:00
|
|
|
void incbeg(float &beg, float &end, float inc, float minsize, bool p_symmetric);
|
|
|
|
void incend(float &beg, float &end, float inc, float minsize, bool p_symmetric);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
void _append_canvas_item(CanvasItem *p_item);
|
2015-02-15 16:00:55 +08:00
|
|
|
void _snap_changed();
|
2015-11-05 05:39:07 +08:00
|
|
|
void _selection_result_pressed(int);
|
|
|
|
void _selection_menu_hide();
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
UndoRedo *undo_redo;
|
|
|
|
|
|
|
|
Point2 _find_topleftmost_point();
|
|
|
|
|
2017-08-29 03:51:56 +08:00
|
|
|
void _build_bones_list(Node *p_node);
|
|
|
|
|
|
|
|
void _get_encompassing_rect(Node *p_node, Rect2 &r_rect, const Transform2D &p_xform);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
Object *_get_editor_data(Object *p_what);
|
|
|
|
|
|
|
|
CanvasItem *get_single_item();
|
|
|
|
int get_item_count();
|
2016-01-09 19:35:57 +08:00
|
|
|
void _keying_changed();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-05-20 23:38:03 +08:00
|
|
|
void _unhandled_key_input(const Ref<InputEvent> &p_ev);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-08-18 06:42:49 +08: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-03 00:33:06 +08:00
|
|
|
void _draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side);
|
|
|
|
|
2017-08-30 03:50:18 +08:00
|
|
|
void _draw_rulers();
|
2017-08-29 03:51:56 +08:00
|
|
|
void _draw_focus();
|
|
|
|
void _draw_grid();
|
|
|
|
void _draw_selection();
|
|
|
|
void _draw_axis();
|
|
|
|
void _draw_bones();
|
|
|
|
void _draw_locks_and_groups(Node *p_node, const Transform2D &p_xform);
|
|
|
|
|
|
|
|
void _draw_viewport();
|
2014-12-29 06:37:25 +08:00
|
|
|
|
2017-08-30 03:50:18 +08:00
|
|
|
void _viewport_base_gui_input(const Ref<InputEvent> &p_event);
|
|
|
|
void _draw_viewport_base();
|
|
|
|
|
2016-07-29 03:37:52 +08:00
|
|
|
void _focus_selection(int p_op);
|
|
|
|
|
2017-08-12 00:16:28 +08:00
|
|
|
void _set_anchors_preset(Control::LayoutPreset p_preset);
|
2017-07-09 21:54:49 +08:00
|
|
|
void _set_full_rect();
|
2015-08-24 12:00:39 +08:00
|
|
|
|
2017-08-20 00:29:37 +08:00
|
|
|
void _zoom_minus();
|
|
|
|
void _zoom_reset();
|
|
|
|
void _zoom_plus();
|
|
|
|
|
2014-12-29 06:37:25 +08:00
|
|
|
HSplitContainer *palette_split;
|
2015-01-12 07:52:42 +08:00
|
|
|
VSplitContainer *bottom_split;
|
2014-12-29 06:37:25 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
friend class CanvasItemEditorPlugin;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
protected:
|
2014-02-10 09:10:30 +08:00
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
void end_drag();
|
2017-03-05 23:44:50 +08:00
|
|
|
void box_selection_start(Point2 &click);
|
2014-02-10 09:10:30 +08:00
|
|
|
bool box_selection_end();
|
|
|
|
|
|
|
|
HBoxContainer *get_panel_hb() { return hb; }
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
struct compare_items_x {
|
2017-03-05 23:44:50 +08:00
|
|
|
bool operator()(const CanvasItem *a, const CanvasItem *b) const {
|
2014-02-10 09:10:30 +08:00
|
|
|
return a->get_global_transform().elements[2].x < b->get_global_transform().elements[2].x;
|
|
|
|
}
|
|
|
|
};
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
struct compare_items_y {
|
2017-03-05 23:44:50 +08:00
|
|
|
bool operator()(const CanvasItem *a, const CanvasItem *b) const {
|
2014-02-10 09:10:30 +08:00
|
|
|
return a->get_global_transform().elements[2].y < b->get_global_transform().elements[2].y;
|
|
|
|
}
|
|
|
|
};
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
struct proj_vector2_x {
|
2017-03-05 23:44:50 +08:00
|
|
|
float get(const Vector2 &v) { return v.x; }
|
|
|
|
void set(Vector2 &v, float f) { v.x = f; }
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
struct proj_vector2_y {
|
2017-03-05 23:44:50 +08:00
|
|
|
float get(const Vector2 &v) { return v.y; }
|
|
|
|
void set(Vector2 &v, float f) { v.y = f; }
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
template <class P, class C>
|
|
|
|
void space_selected_items();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
static CanvasItemEditor *singleton;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
public:
|
2015-02-15 16:00:55 +08:00
|
|
|
Vector2 snap_point(Vector2 p_target, Vector2 p_start = Vector2(0, 0)) const;
|
|
|
|
float snap_angle(float p_target, float p_start = 0) const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-01-11 11:52:51 +08:00
|
|
|
Transform2D get_canvas_transform() const { return transform; }
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
static CanvasItemEditor *get_singleton() { return singleton; }
|
|
|
|
Dictionary get_state() const;
|
2017-03-05 23:44:50 +08:00
|
|
|
void set_state(const Dictionary &p_state);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
void add_control_to_menu_panel(Control *p_control);
|
|
|
|
|
2014-12-29 06:37:25 +08:00
|
|
|
HSplitContainer *get_palette_split();
|
2015-01-12 07:52:42 +08:00
|
|
|
VSplitContainer *get_bottom_split();
|
2014-12-29 06:37:25 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
Control *get_viewport_control() { return viewport; }
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
|
2014-02-10 09:10:30 +08:00
|
|
|
void edit(CanvasItem *p_canvas_item);
|
2016-07-29 03:37:52 +08:00
|
|
|
|
|
|
|
void focus_selection();
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
CanvasItemEditor(EditorNode *p_editor);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CanvasItemEditorPlugin : public EditorPlugin {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(CanvasItemEditorPlugin, EditorPlugin);
|
2014-02-10 09:10:30 +08: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 23:44:50 +08:00
|
|
|
virtual void set_state(const Dictionary &p_state);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
CanvasItemEditor *get_canvas_item_editor() { return canvas_item_editor; }
|
|
|
|
|
|
|
|
CanvasItemEditorPlugin(EditorNode *p_node);
|
|
|
|
~CanvasItemEditorPlugin();
|
|
|
|
};
|
|
|
|
|
2017-01-25 22:41:19 +08:00
|
|
|
class CanvasItemEditorViewport : public Control {
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(CanvasItemEditorViewport, Control);
|
2016-10-26 03:27:24 +08:00
|
|
|
|
|
|
|
String default_type;
|
|
|
|
Vector<String> types;
|
|
|
|
|
|
|
|
Vector<String> selected_files;
|
2017-03-05 23:44:50 +08:00
|
|
|
Node *target_node;
|
2016-10-26 03:27:24 +08:00
|
|
|
Point2 drop_pos;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
EditorNode *editor;
|
|
|
|
EditorData *editor_data;
|
|
|
|
CanvasItemEditor *canvas;
|
2017-09-03 03:47:16 +08:00
|
|
|
Node2D *preview_node;
|
2017-03-05 23:44:50 +08:00
|
|
|
AcceptDialog *accept;
|
|
|
|
WindowDialog *selector;
|
|
|
|
Label *selector_label;
|
|
|
|
Label *label;
|
|
|
|
Label *label_desc;
|
|
|
|
VBoxContainer *btn_group;
|
2017-01-10 12:04:31 +08:00
|
|
|
Ref<ButtonGroup> button_group;
|
2016-10-26 03:27:24 +08:00
|
|
|
|
|
|
|
void _on_mouse_exit();
|
2017-03-05 23:44:50 +08:00
|
|
|
void _on_select_type(Object *selected);
|
2016-10-26 03:27:24 +08:00
|
|
|
void _on_change_type();
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void _create_preview(const Vector<String> &files) const;
|
2016-10-26 03:27:24 +08:00
|
|
|
void _remove_preview();
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
|
|
|
|
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-26 03:27:24 +08:00
|
|
|
void _perform_drop_data();
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
public:
|
2017-03-05 23:44:50 +08: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-26 03:27:24 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas);
|
2017-08-25 00:51:28 +08:00
|
|
|
~CanvasItemEditorViewport();
|
2016-10-26 03:27:24 +08:00
|
|
|
};
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
#endif
|