2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* canvas_item_editor_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* 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
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:11:42 +02:00
|
|
|
/* Copyright (c) 2014-2017 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "canvas_item_editor_plugin.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "editor/animation_editor.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_settings.h"
|
|
|
|
#include "editor/plugins/animation_player_editor_plugin.h"
|
|
|
|
#include "editor/plugins/script_editor_plugin.h"
|
|
|
|
#include "editor/script_editor_debugger.h"
|
|
|
|
#include "os/input.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "os/keyboard.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "print_string.h"
|
2017-07-20 22:03:34 +02:00
|
|
|
#include "project_settings.h"
|
2016-10-25 21:27:24 +02:00
|
|
|
#include "scene/2d/light_2d.h"
|
|
|
|
#include "scene/2d/particles_2d.h"
|
|
|
|
#include "scene/2d/polygon_2d.h"
|
|
|
|
#include "scene/2d/screen_button.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/2d/sprite.h"
|
2015-02-15 09:00:55 +01:00
|
|
|
#include "scene/gui/grid_container.h"
|
2017-01-14 10:52:54 +01:00
|
|
|
#include "scene/gui/patch_9_rect.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/main/canvas_layer.h"
|
|
|
|
#include "scene/main/viewport.h"
|
2016-04-07 12:59:50 +02:00
|
|
|
#include "scene/resources/packed_scene.h"
|
2015-02-15 09:00:55 +01:00
|
|
|
|
2016-07-21 15:06:38 +02:00
|
|
|
#define MIN_ZOOM 0.01
|
|
|
|
#define MAX_ZOOM 100
|
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
class SnapDialog : public ConfirmationDialog {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(SnapDialog, ConfirmationDialog);
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
friend class CanvasItemEditor;
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
SpinBox *grid_offset_x;
|
|
|
|
SpinBox *grid_offset_y;
|
|
|
|
SpinBox *grid_step_x;
|
2016-03-09 00:00:52 +01:00
|
|
|
SpinBox *grid_step_y;
|
|
|
|
SpinBox *rotation_offset;
|
2015-02-15 09:00:55 +01:00
|
|
|
SpinBox *rotation_step;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
public:
|
2017-03-05 16:44:50 +01:00
|
|
|
SnapDialog()
|
|
|
|
: ConfirmationDialog() {
|
2015-02-15 09:00:55 +01:00
|
|
|
const int SPIN_BOX_GRID_RANGE = 256;
|
|
|
|
const int SPIN_BOX_ROTATION_RANGE = 360;
|
|
|
|
Label *label;
|
|
|
|
VBoxContainer *container;
|
|
|
|
GridContainer *child_container;
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
set_title(TTR("Configure Snap"));
|
|
|
|
get_ok()->set_text(TTR("Close"));
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
container = memnew(VBoxContainer);
|
2015-02-15 09:00:55 +01:00
|
|
|
add_child(container);
|
2017-01-14 12:26:56 +01:00
|
|
|
//set_child_rect(container);
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
child_container = memnew(GridContainer);
|
2015-02-15 09:00:55 +01:00
|
|
|
child_container->set_columns(3);
|
|
|
|
container->add_child(child_container);
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
label = memnew(Label);
|
2016-05-04 03:25:37 +02:00
|
|
|
label->set_text(TTR("Grid Offset:"));
|
2015-02-15 09:00:55 +01:00
|
|
|
child_container->add_child(label);
|
2015-10-18 18:31:44 +02:00
|
|
|
label->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
grid_offset_x = memnew(SpinBox);
|
2015-02-15 09:00:55 +01:00
|
|
|
grid_offset_x->set_min(-SPIN_BOX_GRID_RANGE);
|
|
|
|
grid_offset_x->set_max(SPIN_BOX_GRID_RANGE);
|
|
|
|
grid_offset_x->set_suffix("px");
|
|
|
|
child_container->add_child(grid_offset_x);
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
grid_offset_y = memnew(SpinBox);
|
2015-02-15 09:00:55 +01:00
|
|
|
grid_offset_y->set_min(-SPIN_BOX_GRID_RANGE);
|
|
|
|
grid_offset_y->set_max(SPIN_BOX_GRID_RANGE);
|
|
|
|
grid_offset_y->set_suffix("px");
|
|
|
|
child_container->add_child(grid_offset_y);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
label = memnew(Label);
|
2016-05-04 03:25:37 +02:00
|
|
|
label->set_text(TTR("Grid Step:"));
|
2015-02-15 09:00:55 +01:00
|
|
|
child_container->add_child(label);
|
2015-10-18 18:31:44 +02:00
|
|
|
label->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
grid_step_x = memnew(SpinBox);
|
2015-02-15 09:00:55 +01:00
|
|
|
grid_step_x->set_min(-SPIN_BOX_GRID_RANGE);
|
|
|
|
grid_step_x->set_max(SPIN_BOX_GRID_RANGE);
|
|
|
|
grid_step_x->set_suffix("px");
|
|
|
|
child_container->add_child(grid_step_x);
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
grid_step_y = memnew(SpinBox);
|
2015-02-15 09:00:55 +01:00
|
|
|
grid_step_y->set_min(-SPIN_BOX_GRID_RANGE);
|
|
|
|
grid_step_y->set_max(SPIN_BOX_GRID_RANGE);
|
|
|
|
grid_step_y->set_suffix("px");
|
|
|
|
child_container->add_child(grid_step_y);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
container->add_child(memnew(HSeparator));
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
child_container = memnew(GridContainer);
|
2015-02-15 09:00:55 +01:00
|
|
|
child_container->set_columns(2);
|
|
|
|
container->add_child(child_container);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
label = memnew(Label);
|
2016-05-04 03:25:37 +02:00
|
|
|
label->set_text(TTR("Rotation Offset:"));
|
2015-02-15 09:00:55 +01:00
|
|
|
child_container->add_child(label);
|
2015-10-18 18:31:44 +02:00
|
|
|
label->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
rotation_offset = memnew(SpinBox);
|
2015-02-15 09:00:55 +01:00
|
|
|
rotation_offset->set_min(-SPIN_BOX_ROTATION_RANGE);
|
|
|
|
rotation_offset->set_max(SPIN_BOX_ROTATION_RANGE);
|
|
|
|
rotation_offset->set_suffix("deg");
|
|
|
|
child_container->add_child(rotation_offset);
|
2015-10-18 18:31:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
label = memnew(Label);
|
2016-05-04 03:25:37 +02:00
|
|
|
label->set_text(TTR("Rotation Step:"));
|
2015-02-15 09:00:55 +01:00
|
|
|
child_container->add_child(label);
|
2015-10-18 18:31:44 +02:00
|
|
|
label->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
rotation_step = memnew(SpinBox);
|
2015-02-15 09:00:55 +01:00
|
|
|
rotation_step->set_min(-SPIN_BOX_ROTATION_RANGE);
|
|
|
|
rotation_step->set_max(SPIN_BOX_ROTATION_RANGE);
|
|
|
|
rotation_step->set_suffix("deg");
|
|
|
|
child_container->add_child(rotation_step);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
void set_fields(const Point2 p_grid_offset, const Size2 p_grid_step, const float p_rotation_offset, const float p_rotation_step) {
|
2017-01-04 05:16:14 +01:00
|
|
|
grid_offset_x->set_value(p_grid_offset.x);
|
|
|
|
grid_offset_y->set_value(p_grid_offset.y);
|
|
|
|
grid_step_x->set_value(p_grid_step.x);
|
|
|
|
grid_step_y->set_value(p_grid_step.y);
|
|
|
|
rotation_offset->set_value(p_rotation_offset * (180 / Math_PI));
|
|
|
|
rotation_step->set_value(p_rotation_step * (180 / Math_PI));
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
void get_fields(Point2 &p_grid_offset, Size2 &p_grid_step, float &p_rotation_offset, float &p_rotation_step) {
|
2017-01-04 05:16:14 +01:00
|
|
|
p_grid_offset.x = grid_offset_x->get_value();
|
|
|
|
p_grid_offset.y = grid_offset_y->get_value();
|
|
|
|
p_grid_step.x = grid_step_x->get_value();
|
|
|
|
p_grid_step.y = grid_step_y->get_value();
|
|
|
|
p_rotation_offset = rotation_offset->get_value() / (180 / Math_PI);
|
|
|
|
p_rotation_step = rotation_step->get_value() / (180 / Math_PI);
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditor::_edit_set_pivot(const Vector2 &mouse_pos) {
|
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2015-12-28 13:38:15 +01:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Move Pivot"));
|
2015-12-28 13:38:15 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2015-12-28 13:38:15 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *n2d = Object::cast_to<Node2D>(E->get());
|
2015-12-28 13:38:15 +01:00
|
|
|
if (n2d && n2d->edit_has_pivot()) {
|
|
|
|
|
|
|
|
Vector2 offset = n2d->edit_get_pivot();
|
2017-01-04 05:16:14 +01:00
|
|
|
Vector2 gpos = n2d->get_global_position();
|
2015-12-28 13:38:15 +01:00
|
|
|
|
2015-12-29 11:31:50 +01:00
|
|
|
Vector2 local_mouse_pos = n2d->get_canvas_transform().affine_inverse().xform(mouse_pos);
|
2015-12-28 13:38:15 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 motion_ofs = gpos - local_mouse_pos;
|
2015-12-29 11:31:50 +01:00
|
|
|
|
2017-03-29 17:29:38 +02:00
|
|
|
undo_redo->add_do_method(n2d, "set_global_position", local_mouse_pos);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(n2d, "edit_set_pivot", offset + n2d->get_global_transform().affine_inverse().basis_xform(motion_ofs));
|
2017-03-29 17:29:38 +02:00
|
|
|
undo_redo->add_undo_method(n2d, "set_global_position", gpos);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_undo_method(n2d, "edit_set_pivot", offset);
|
|
|
|
for (int i = 0; i < n2d->get_child_count(); i++) {
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *n2dc = Object::cast_to<Node2D>(n2d->get_child(i));
|
2015-12-28 13:38:15 +01:00
|
|
|
if (!n2dc)
|
|
|
|
continue;
|
|
|
|
|
2017-03-29 17:29:38 +02:00
|
|
|
undo_redo->add_do_method(n2dc, "set_global_position", n2dc->get_global_position());
|
|
|
|
undo_redo->add_undo_method(n2dc, "set_global_position", n2dc->get_global_position());
|
2015-12-28 13:38:15 +01:00
|
|
|
}
|
|
|
|
}
|
2017-07-06 22:42:44 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *cnt = Object::cast_to<Control>(E->get());
|
2017-07-06 22:42:44 +02:00
|
|
|
if (cnt) {
|
|
|
|
|
|
|
|
Vector2 old_pivot = cnt->get_pivot_offset();
|
|
|
|
Vector2 new_pivot = cnt->get_global_transform_with_canvas().affine_inverse().xform(mouse_pos);
|
|
|
|
Vector2 old_pos = cnt->get_position();
|
|
|
|
|
|
|
|
Vector2 top_pos = cnt->get_transform().get_origin(); //remember where top pos was
|
|
|
|
cnt->set_pivot_offset(new_pivot);
|
|
|
|
Vector2 new_top_pos = cnt->get_transform().get_origin(); //check where it is now
|
|
|
|
|
|
|
|
Vector2 new_pos = old_pos - (new_top_pos - top_pos); //offset it back
|
|
|
|
|
|
|
|
undo_redo->add_do_method(cnt, "set_pivot_offset", new_pivot);
|
|
|
|
undo_redo->add_do_method(cnt, "set_position", new_pos);
|
|
|
|
undo_redo->add_undo_method(cnt, "set_pivot_offset", old_pivot);
|
|
|
|
undo_redo->add_undo_method(cnt, "set_position", old_pos);
|
|
|
|
}
|
2015-12-28 13:38:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
|
|
|
|
|
|
|
|
Ref<InputEventKey> k = p_ev;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!is_visible_in_tree() || get_viewport()->gui_has_modal_stack())
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2016-07-15 21:22:01 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_control())
|
2015-08-11 15:39:59 +02:00
|
|
|
return;
|
2016-07-15 21:22:01 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->is_pressed() && !k->is_echo() && k->get_scancode() == KEY_V && drag == DRAG_NONE && can_move_pivot) {
|
2016-07-15 21:22:01 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift()) {
|
2015-06-12 18:53:18 +02:00
|
|
|
//move drag pivot
|
2017-03-05 16:44:50 +01:00
|
|
|
drag = DRAG_PIVOT;
|
2015-06-12 18:53:18 +02:00
|
|
|
} else if (!Input::get_singleton()->is_mouse_button_pressed(0)) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2015-06-12 18:53:18 +02:00
|
|
|
Vector2 mouse_pos = viewport->get_local_mouse_pos();
|
|
|
|
if (selection.size() && viewport->get_rect().has_point(mouse_pos)) {
|
|
|
|
//just in case, make it work if over viewport
|
2017-03-05 16:44:50 +01:00
|
|
|
mouse_pos = transform.affine_inverse().xform(mouse_pos);
|
|
|
|
mouse_pos = snap_point(mouse_pos);
|
2015-06-12 18:53:18 +02:00
|
|
|
|
2015-12-28 13:38:15 +01:00
|
|
|
_edit_set_pivot(mouse_pos);
|
2015-06-12 18:53:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditor::_tool_select(int p_index) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ToolButton *tb[TOOL_MAX] = { select_button, list_select_button, move_button, rotate_button, pivot_button, pan_button };
|
|
|
|
for (int i = 0; i < TOOL_MAX; i++) {
|
|
|
|
tb[i]->set_pressed(i == p_index);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
viewport->update();
|
2017-03-05 16:44:50 +01:00
|
|
|
tool = (Tool)p_index;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *CanvasItemEditor::_get_editor_data(Object *p_what) {
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *ci = Object::cast_to<CanvasItem>(p_what);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!ci)
|
|
|
|
return NULL;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return memnew(CanvasItemEditorSelectedItem);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-02-20 13:21:59 +01:00
|
|
|
inline float _snap_scalar(float p_offset, float p_step, bool p_snap_relative, float p_target, float p_start) {
|
|
|
|
float offset = p_snap_relative ? p_start : p_offset;
|
2015-02-15 09:00:55 +01:00
|
|
|
return p_step != 0 ? Math::stepify(p_target - offset, p_step) + offset : p_target;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 CanvasItemEditor::snap_point(Vector2 p_target, Vector2 p_start) const {
|
|
|
|
if (snap_grid) {
|
2015-02-20 13:21:59 +01:00
|
|
|
p_target.x = _snap_scalar(snap_offset.x, snap_step.x, snap_relative, p_target.x, p_start.x);
|
|
|
|
p_target.y = _snap_scalar(snap_offset.y, snap_step.y, snap_relative, p_target.y, p_start.y);
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
|
|
|
if (snap_pixel)
|
|
|
|
p_target = p_target.snapped(Size2(1, 1));
|
|
|
|
|
|
|
|
return p_target;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
float CanvasItemEditor::snap_angle(float p_target, float p_start) const {
|
2015-02-20 13:21:59 +01:00
|
|
|
return snap_rotation ? _snap_scalar(snap_rotation_offset, snap_rotation_step, snap_relative, p_target, p_start) : p_target;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary CanvasItemEditor::get_state() const {
|
|
|
|
|
|
|
|
Dictionary state;
|
2017-03-05 16:44:50 +01:00
|
|
|
state["zoom"] = zoom;
|
|
|
|
state["ofs"] = Point2(h_scroll->get_value(), v_scroll->get_value());
|
2017-01-14 12:26:56 +01:00
|
|
|
//state["ofs"]=-transform.get_origin();
|
2017-03-05 16:44:50 +01:00
|
|
|
state["snap_offset"] = snap_offset;
|
|
|
|
state["snap_step"] = snap_step;
|
|
|
|
state["snap_rotation_offset"] = snap_rotation_offset;
|
|
|
|
state["snap_rotation_step"] = snap_rotation_step;
|
|
|
|
state["snap_grid"] = snap_grid;
|
|
|
|
state["snap_show_grid"] = snap_show_grid;
|
|
|
|
state["snap_rotation"] = snap_rotation;
|
|
|
|
state["snap_relative"] = snap_relative;
|
|
|
|
state["snap_pixel"] = snap_pixel;
|
|
|
|
state["skeleton_show_bones"] = skeleton_show_bones;
|
2014-02-10 02:10:30 +01:00
|
|
|
return state;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditor::set_state(const Dictionary &p_state) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Dictionary state = p_state;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (state.has("zoom")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
zoom = p_state["zoom"];
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state.has("ofs")) {
|
|
|
|
_update_scrollbars(); // i wonder how safe is calling this here..
|
2017-03-05 16:44:50 +01:00
|
|
|
Point2 ofs = p_state["ofs"];
|
2017-01-04 05:16:14 +01:00
|
|
|
h_scroll->set_value(ofs.x);
|
|
|
|
v_scroll->set_value(ofs.y);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
if (state.has("snap_step")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_step = state["snap_step"];
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state.has("snap_offset")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_offset = state["snap_offset"];
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state.has("snap_rotation_step")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_rotation_step = state["snap_rotation_step"];
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state.has("snap_rotation_offset")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_rotation_offset = state["snap_rotation_offset"];
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state.has("snap_grid")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_grid = state["snap_grid"];
|
2014-04-24 03:43:02 +02:00
|
|
|
int idx = edit_menu->get_popup()->get_item_index(SNAP_USE);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->set_item_checked(idx, snap_grid);
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state.has("snap_show_grid")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_show_grid = state["snap_show_grid"];
|
2015-02-15 09:00:55 +01:00
|
|
|
int idx = edit_menu->get_popup()->get_item_index(SNAP_SHOW_GRID);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->set_item_checked(idx, snap_show_grid);
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state.has("snap_rotation")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_rotation = state["snap_rotation"];
|
2015-02-15 09:00:55 +01:00
|
|
|
int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_ROTATION);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->set_item_checked(idx, snap_rotation);
|
2014-04-24 03:43:02 +02:00
|
|
|
}
|
|
|
|
|
2015-02-20 13:21:59 +01:00
|
|
|
if (state.has("snap_relative")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_relative = state["snap_relative"];
|
2015-02-20 13:21:59 +01:00
|
|
|
int idx = edit_menu->get_popup()->get_item_index(SNAP_RELATIVE);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->set_item_checked(idx, snap_relative);
|
2014-04-24 03:43:02 +02:00
|
|
|
}
|
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
if (state.has("snap_pixel")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_pixel = state["snap_pixel"];
|
2014-02-10 02:10:30 +01:00
|
|
|
int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_PIXEL);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->set_item_checked(idx, snap_pixel);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-09-07 11:10:00 +02:00
|
|
|
|
|
|
|
if (state.has("skeleton_show_bones")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
skeleton_show_bones = state["skeleton_show_bones"];
|
2016-09-07 11:10:00 +02:00
|
|
|
int idx = skeleton_menu->get_item_index(SKELETON_SHOW_BONES);
|
2017-03-05 16:44:50 +01:00
|
|
|
skeleton_menu->set_item_checked(idx, skeleton_show_bones);
|
2016-09-07 11:10:00 +02:00
|
|
|
}
|
2017-08-09 02:12:32 +02:00
|
|
|
|
|
|
|
viewport->update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditor::_add_canvas_item(CanvasItem *p_canvas_item) {
|
|
|
|
|
|
|
|
editor_selection->add_node(p_canvas_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditor::_remove_canvas_item(CanvasItem *p_canvas_item) {
|
|
|
|
|
|
|
|
editor_selection->remove_node(p_canvas_item);
|
|
|
|
}
|
|
|
|
void CanvasItemEditor::_clear_canvas_items() {
|
|
|
|
|
2017-01-14 18:03:38 +01:00
|
|
|
editor_selection->clear();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-01-09 12:35:57 +01:00
|
|
|
void CanvasItemEditor::_keying_changed() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-13 14:45:50 +01:00
|
|
|
if (AnimationPlayerEditor::singleton->get_key_editor()->is_visible_in_tree())
|
2014-07-06 16:49:27 +02:00
|
|
|
animation_hb->show();
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
2014-07-06 16:49:27 +02:00
|
|
|
animation_hb->hide();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-04-07 12:59:50 +02:00
|
|
|
bool CanvasItemEditor::_is_part_of_subscene(CanvasItem *p_item) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *scene_node = get_tree()->get_edited_scene_root();
|
|
|
|
Node *item_owner = p_item->get_owner();
|
2016-04-07 12:59:50 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return item_owner && item_owner != scene_node && p_item != scene_node && item_owner->get_filename() != "";
|
2016-04-07 12:59:50 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 23:28:19 +02:00
|
|
|
void CanvasItemEditor::_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, unsigned int limit) {
|
2015-11-04 22:39:07 +01:00
|
|
|
if (!p_node)
|
|
|
|
return;
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Viewport>(p_node))
|
2015-11-04 22:39:07 +01:00
|
|
|
return;
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *c = Object::cast_to<CanvasItem>(p_node);
|
2015-11-04 22:39:07 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
|
2015-11-04 22:39:07 +01:00
|
|
|
|
|
|
|
if (c && !c->is_set_as_toplevel())
|
2017-03-05 16:44:50 +01:00
|
|
|
_find_canvas_items_at_pos(p_pos, p_node->get_child(i), p_parent_xform * c->get_transform(), p_canvas_xform, r_items);
|
2015-11-04 22:39:07 +01:00
|
|
|
else {
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
|
2017-03-05 16:44:50 +01:00
|
|
|
_find_canvas_items_at_pos(p_pos, p_node->get_child(i), transform, cl ? cl->get_transform() : p_canvas_xform, r_items); //use base transform
|
2015-11-04 22:39:07 +01:00
|
|
|
}
|
2017-07-17 23:28:19 +02:00
|
|
|
|
|
|
|
if (limit != 0 && r_items.size() >= limit)
|
|
|
|
return;
|
2015-11-04 22:39:07 +01:00
|
|
|
}
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !Object::cast_to<CanvasLayer>(c)) {
|
2015-11-04 22:39:07 +01:00
|
|
|
|
|
|
|
Rect2 rect = c->get_item_rect();
|
|
|
|
Point2 local_pos = (p_parent_xform * p_canvas_xform * c->get_transform()).affine_inverse().xform(p_pos);
|
|
|
|
|
|
|
|
if (rect.has_point(local_pos)) {
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *node = Object::cast_to<Node2D>(c);
|
2015-11-04 22:39:07 +01:00
|
|
|
|
|
|
|
_SelectResult res;
|
2017-03-05 16:44:50 +01:00
|
|
|
res.item = c;
|
|
|
|
res.z = node ? node->get_z() : 0;
|
|
|
|
res.has_z = node;
|
2015-11-04 22:39:07 +01:00
|
|
|
r_items.push_back(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditor::_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 02:10:30 +01:00
|
|
|
|
|
|
|
if (!p_node)
|
|
|
|
return;
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Viewport>(p_node))
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *c = Object::cast_to<CanvasItem>(p_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool inherited = p_node != get_tree()->get_edited_scene_root() && p_node->get_filename() != "";
|
|
|
|
bool editable = false;
|
|
|
|
if (inherited) {
|
|
|
|
editable = EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node);
|
2016-11-12 14:43:31 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
bool lock_children = p_node->has_meta("_edit_group_") && p_node->get_meta("_edit_group_");
|
2016-11-12 14:43:31 +01:00
|
|
|
if (!lock_children && (!inherited || editable)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
|
2016-11-12 14:43:31 +01:00
|
|
|
|
|
|
|
if (c && !c->is_set_as_toplevel())
|
2017-03-05 16:44:50 +01:00
|
|
|
_find_canvas_items_at_rect(p_rect, p_node->get_child(i), p_parent_xform * c->get_transform(), p_canvas_xform, r_items);
|
2016-11-12 14:43:31 +01:00
|
|
|
else {
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
|
2017-03-05 16:44:50 +01:00
|
|
|
_find_canvas_items_at_rect(p_rect, p_node->get_child(i), transform, cl ? cl->get_transform() : p_canvas_xform, r_items);
|
2016-11-12 14:43:31 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !Object::cast_to<CanvasLayer>(c)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Rect2 rect = c->get_item_rect();
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D xform = p_parent_xform * p_canvas_xform * c->get_transform();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
if (p_rect.has_point(xform.xform(rect.position)) &&
|
|
|
|
p_rect.has_point(xform.xform(rect.position + Vector2(rect.size.x, 0))) &&
|
|
|
|
p_rect.has_point(xform.xform(rect.position + Vector2(rect.size.x, rect.size.y))) &&
|
|
|
|
p_rect.has_point(xform.xform(rect.position + Vector2(0, rect.size.y)))) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
r_items->push_back(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 20:17:55 +02:00
|
|
|
void CanvasItemEditor::_select_click_on_empty_area(Point2 p_click_pos, bool p_append, bool p_box_selection) {
|
|
|
|
if (!p_append) {
|
|
|
|
editor_selection->clear();
|
|
|
|
viewport->update();
|
|
|
|
};
|
2015-11-04 22:39:07 +01:00
|
|
|
|
2017-07-18 20:17:55 +02:00
|
|
|
if (p_box_selection) {
|
|
|
|
// Start a box selection
|
|
|
|
drag_from = transform.affine_inverse().xform(p_click_pos);
|
|
|
|
box_selecting = true;
|
|
|
|
box_selecting_to = drag_from;
|
|
|
|
}
|
|
|
|
}
|
2015-11-04 22:39:07 +01:00
|
|
|
|
2017-07-18 20:17:55 +02:00
|
|
|
bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append, bool p_drag) {
|
|
|
|
bool still_selected = true;
|
|
|
|
if (p_append) {
|
2015-11-04 22:39:07 +01:00
|
|
|
if (editor_selection->is_selected(item)) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Already in the selection, remove it from the selected nodes
|
2015-11-04 22:39:07 +01:00
|
|
|
editor_selection->remove_node(item);
|
2017-07-18 20:17:55 +02:00
|
|
|
still_selected = false;
|
|
|
|
} else {
|
|
|
|
// Add the item to the selection
|
|
|
|
_append_canvas_item(item);
|
2015-11-04 22:39:07 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!editor_selection->is_selected(item)) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Select a new one and clear previous selection
|
2015-11-04 22:39:07 +01:00
|
|
|
editor_selection->clear();
|
|
|
|
editor_selection->add_node(item);
|
2017-07-18 20:17:55 +02:00
|
|
|
// Reselect
|
2017-08-19 01:02:56 +02:00
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
editor->call("edit_node", item);
|
2015-11-04 22:39:07 +01:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 20:17:55 +02:00
|
|
|
}
|
2015-11-04 22:39:07 +01:00
|
|
|
|
2017-07-18 20:17:55 +02:00
|
|
|
if (still_selected && p_drag) {
|
|
|
|
// Drag the node(s) if requested
|
|
|
|
_prepare_drag(p_click_pos);
|
2015-11-04 22:39:07 +01:00
|
|
|
}
|
2017-07-18 20:17:55 +02:00
|
|
|
|
|
|
|
viewport->update();
|
|
|
|
return still_selected;
|
2015-11-04 22:39:07 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (drag != DRAG_NONE)
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (editor_selection->get_selected_node_list().empty())
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->create_action(TTR("Move Action"), UndoRedo::MERGE_ENDS);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!se)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (canvas_item->has_meta("_edit_lock_"))
|
|
|
|
continue;
|
|
|
|
|
2014-05-09 09:11:24 +02:00
|
|
|
Vector2 drag = p_dir;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (p_snap)
|
2017-03-05 16:44:50 +01:00
|
|
|
drag *= snap_step;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_undo_method(canvas_item, "edit_set_state", canvas_item->edit_get_state());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_move_mode == MOVE_VIEW_BASE) {
|
2014-05-09 09:11:24 +02:00
|
|
|
|
|
|
|
// drag = transform.affine_inverse().basis_xform(p_dir); // zoom sensitive
|
|
|
|
drag = canvas_item->get_global_transform_with_canvas().affine_inverse().basis_xform(drag);
|
|
|
|
Rect2 local_rect = canvas_item->get_item_rect();
|
2017-06-04 00:25:13 +02:00
|
|
|
local_rect.position += drag;
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(canvas_item, "edit_set_rect", local_rect);
|
2014-05-09 09:11:24 +02:00
|
|
|
|
|
|
|
} else { // p_move_mode==MOVE_LOCAL_BASE || p_move_mode==MOVE_LOCAL_WITH_ROT
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Node2D *node_2d = Object::cast_to<Node2D>(canvas_item)) {
|
2014-05-09 09:11:24 +02:00
|
|
|
|
|
|
|
if (p_move_mode == MOVE_LOCAL_WITH_ROT) {
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D m;
|
2017-03-05 16:44:50 +01:00
|
|
|
m.rotate(node_2d->get_rotation());
|
2014-05-09 09:11:24 +02:00
|
|
|
drag = m.xform(drag);
|
|
|
|
}
|
2017-01-04 05:16:14 +01:00
|
|
|
node_2d->set_position(node_2d->get_position() + drag);
|
2014-05-09 09:11:24 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
} else if (Control *control = Object::cast_to<Control>(canvas_item)) {
|
2014-05-09 09:11:24 +02:00
|
|
|
|
2017-03-29 17:29:38 +02:00
|
|
|
control->set_position(control->get_position() + drag);
|
2014-05-09 09:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
Point2 CanvasItemEditor::_find_topleftmost_point() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 tl = Point2(1e10, 1e10);
|
2014-02-10 02:10:30 +01:00
|
|
|
Rect2 r2;
|
2017-06-04 00:25:13 +02:00
|
|
|
r2.position = tl;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Rect2 rect = canvas_item->get_item_rect();
|
|
|
|
Transform2D xform = canvas_item->get_global_transform_with_canvas();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
r2.expand_to(xform.xform(rect.position));
|
|
|
|
r2.expand_to(xform.xform(rect.position + Vector2(rect.size.x, 0)));
|
|
|
|
r2.expand_to(xform.xform(rect.position + rect.size));
|
|
|
|
r2.expand_to(xform.xform(rect.position + Vector2(0, rect.size.y)));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
return r2.position;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int CanvasItemEditor::get_item_count() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int ic = 0;
|
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ic++;
|
|
|
|
};
|
|
|
|
|
|
|
|
return ic;
|
|
|
|
}
|
|
|
|
|
|
|
|
CanvasItem *CanvasItemEditor::get_single_item() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<Node *, Object *> &selection = editor_selection->get_selection();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItem *single_item = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (single_item)
|
|
|
|
return NULL; //morethan one
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
single_item = canvas_item;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return single_item;
|
|
|
|
}
|
|
|
|
|
2017-07-29 16:57:32 +02:00
|
|
|
CanvasItemEditor::DragType CanvasItemEditor::_get_resize_handle_drag_type(const Point2 &p_click, Vector2 &r_point) {
|
|
|
|
// Returns a drag type if a resize handle is clicked
|
2014-02-10 02:10:30 +01:00
|
|
|
CanvasItem *canvas_item = get_single_item();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!canvas_item, DRAG_NONE);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Rect2 rect = canvas_item->get_item_rect();
|
|
|
|
Transform2D xforml = canvas_item->get_global_transform_with_canvas();
|
|
|
|
Transform2D xform = transform * xforml;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 endpoints[4] = {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
xform.xform(rect.position),
|
|
|
|
xform.xform(rect.position + Vector2(rect.size.x, 0)),
|
|
|
|
xform.xform(rect.position + rect.size),
|
|
|
|
xform.xform(rect.position + Vector2(0, rect.size.y))
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 endpointsl[4] = {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
xforml.xform(rect.position),
|
|
|
|
xforml.xform(rect.position + Vector2(rect.size.x, 0)),
|
|
|
|
xforml.xform(rect.position + rect.size),
|
|
|
|
xforml.xform(rect.position + Vector2(0, rect.size.y))
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
DragType dragger[] = {
|
2014-02-10 02:10:30 +01:00
|
|
|
DRAG_TOP_LEFT,
|
|
|
|
DRAG_TOP,
|
|
|
|
DRAG_TOP_RIGHT,
|
|
|
|
DRAG_RIGHT,
|
|
|
|
DRAG_BOTTOM_RIGHT,
|
|
|
|
DRAG_BOTTOM,
|
|
|
|
DRAG_BOTTOM_LEFT,
|
|
|
|
DRAG_LEFT
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float radius = (select_handle->get_size().width / 2) * 1.5;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int prev = (i + 3) % 4;
|
|
|
|
int next = (i + 1) % 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_point = endpointsl[i];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized();
|
2017-03-05 16:44:50 +01:00
|
|
|
ofs *= 1.4144 * (select_handle->get_size().width / 2);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ofs += endpoints[i];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (ofs.distance_to(p_click) < radius)
|
|
|
|
return dragger[i * 2];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ofs = (endpoints[i] + endpoints[next]) / 2;
|
|
|
|
ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_point = (endpointsl[i] + endpointsl[next]) / 2;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (ofs.distance_to(p_click) < radius)
|
|
|
|
return dragger[i * 2 + 1];
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return DRAG_NONE;
|
|
|
|
}
|
|
|
|
|
2017-08-02 19:24:05 +02:00
|
|
|
float CanvasItemEditor::_anchor_snap(float p_anchor, bool *p_snapped, float p_opposite_anchor) {
|
|
|
|
bool snapped = false;
|
|
|
|
float dist, dist_min = 0.0;
|
2017-07-30 15:32:22 +02:00
|
|
|
float radius = 0.05 / zoom;
|
2017-08-16 00:48:38 +02:00
|
|
|
float basic_anchors[3] = { 0.0, 0.5, 1.0 };
|
2017-08-02 19:24:05 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
if ((dist = fabs(p_anchor - basic_anchors[i])) < radius) {
|
|
|
|
if (!snapped || dist <= dist_min) {
|
|
|
|
p_anchor = basic_anchors[i];
|
|
|
|
dist_min = dist;
|
|
|
|
snapped = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_opposite_anchor >= 0 && (dist = fabs(p_anchor - p_opposite_anchor)) < radius) {
|
|
|
|
if (!snapped || dist <= dist_min) {
|
|
|
|
p_anchor = p_opposite_anchor;
|
|
|
|
dist_min = dist;
|
|
|
|
snapped = true;
|
|
|
|
}
|
2017-07-30 15:32:22 +02:00
|
|
|
}
|
2017-08-02 19:24:05 +02:00
|
|
|
if (p_snapped)
|
|
|
|
*p_snapped = snapped;
|
|
|
|
return p_anchor;
|
2017-07-30 15:32:22 +02:00
|
|
|
}
|
2017-07-31 18:49:46 +02:00
|
|
|
|
2017-07-11 00:14:22 +02:00
|
|
|
Vector2 CanvasItemEditor::_anchor_to_position(Control *p_control, Vector2 anchor) {
|
|
|
|
ERR_FAIL_COND_V(!p_control, Vector2());
|
|
|
|
|
|
|
|
Transform2D parent_transform = p_control->get_transform().affine_inverse();
|
|
|
|
Size2 parent_size = p_control->get_parent_area_size();
|
|
|
|
|
|
|
|
return parent_transform.xform(Vector2(parent_size.x * anchor.x, parent_size.y * anchor.y));
|
|
|
|
}
|
|
|
|
|
2017-07-29 16:57:32 +02:00
|
|
|
Vector2 CanvasItemEditor::_position_to_anchor(Control *p_control, Vector2 position) {
|
|
|
|
ERR_FAIL_COND_V(!p_control, Vector2());
|
|
|
|
Size2 parent_size = p_control->get_parent_area_size();
|
|
|
|
|
|
|
|
return p_control->get_transform().xform(position) / parent_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
CanvasItemEditor::DragType CanvasItemEditor::_get_anchor_handle_drag_type(const Point2 &p_click, Vector2 &r_point) {
|
|
|
|
// Returns a drag type if an anchor handle is clicked
|
|
|
|
CanvasItem *canvas_item = get_single_item();
|
|
|
|
ERR_FAIL_COND_V(!canvas_item, DRAG_NONE);
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *control = Object::cast_to<Control>(canvas_item);
|
2017-07-29 16:57:32 +02:00
|
|
|
ERR_FAIL_COND_V(!control, DRAG_NONE);
|
|
|
|
|
|
|
|
Vector2 anchor_pos[4];
|
|
|
|
anchor_pos[0] = Vector2(control->get_anchor(MARGIN_LEFT), control->get_anchor(MARGIN_TOP));
|
|
|
|
anchor_pos[1] = Vector2(control->get_anchor(MARGIN_RIGHT), control->get_anchor(MARGIN_TOP));
|
|
|
|
anchor_pos[2] = Vector2(control->get_anchor(MARGIN_RIGHT), control->get_anchor(MARGIN_BOTTOM));
|
|
|
|
anchor_pos[3] = Vector2(control->get_anchor(MARGIN_LEFT), control->get_anchor(MARGIN_BOTTOM));
|
|
|
|
|
|
|
|
Rect2 anchor_rects[4];
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
anchor_pos[i] = (transform * control->get_global_transform_with_canvas()).xform(_anchor_to_position(control, anchor_pos[i]));
|
|
|
|
anchor_rects[i] = Rect2(anchor_pos[i], anchor_handle->get_size());
|
|
|
|
anchor_rects[i].position -= anchor_handle->get_size() * Vector2(i == 0 || i == 3, i <= 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DragType dragger[] = {
|
|
|
|
DRAG_ANCHOR_TOP_LEFT,
|
|
|
|
DRAG_ANCHOR_TOP_RIGHT,
|
|
|
|
DRAG_ANCHOR_BOTTOM_RIGHT,
|
|
|
|
DRAG_ANCHOR_BOTTOM_LEFT,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (anchor_rects[i].has_point(p_click)) {
|
|
|
|
r_point = transform.affine_inverse().xform(anchor_pos[i]);
|
2017-08-04 19:27:30 +02:00
|
|
|
if ((anchor_pos[0] == anchor_pos[2]) && (anchor_pos[0].distance_to(p_click) < anchor_handle->get_size().length() / 3.0)) {
|
|
|
|
return DRAG_ANCHOR_ALL;
|
|
|
|
} else {
|
|
|
|
return dragger[i];
|
|
|
|
}
|
2017-07-29 16:57:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return DRAG_NONE;
|
|
|
|
}
|
|
|
|
|
2017-03-23 00:47:51 +01:00
|
|
|
void CanvasItemEditor::_prepare_drag(const Point2 &p_click_pos) {
|
|
|
|
|
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
|
|
|
|
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-03-23 00:47:51 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
|
|
|
continue;
|
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
|
|
|
|
if (!se)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
se->undo_state = canvas_item->edit_get_state();
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item))
|
|
|
|
se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot();
|
|
|
|
if (Object::cast_to<Control>(canvas_item))
|
|
|
|
se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
|
2017-03-23 00:47:51 +01:00
|
|
|
}
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (selection.size() == 1 && Object::cast_to<Node2D>(selection[0])) {
|
2017-03-23 00:47:51 +01:00
|
|
|
drag = DRAG_NODE_2D;
|
2017-08-24 22:58:51 +02:00
|
|
|
drag_point_from = Object::cast_to<Node2D>(selection[0])->get_global_position();
|
2017-03-23 00:47:51 +01:00
|
|
|
} else {
|
|
|
|
drag = DRAG_ALL;
|
|
|
|
drag_point_from = _find_topleftmost_point();
|
|
|
|
}
|
|
|
|
drag_from = transform.affine_inverse().xform(p_click_pos);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditor::incbeg(float &beg, float &end, float inc, float minsize, bool p_symmetric) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (minsize < 0) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
beg += inc;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (p_symmetric)
|
2017-03-05 16:44:50 +01:00
|
|
|
end -= inc;
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
if (p_symmetric) {
|
2017-03-05 16:44:50 +01:00
|
|
|
beg += inc;
|
|
|
|
end -= inc;
|
|
|
|
if (end - beg < minsize) {
|
|
|
|
float center = (beg + end) / 2.0;
|
|
|
|
beg = center - minsize / 2.0;
|
|
|
|
end = center + minsize / 2.0;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (end - (beg + inc) < minsize)
|
|
|
|
beg = end - minsize;
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
beg += inc;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditor::incend(float &beg, float &end, float inc, float minsize, bool p_symmetric) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (minsize < 0) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
end += inc;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (p_symmetric)
|
2017-03-05 16:44:50 +01:00
|
|
|
beg -= inc;
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
if (p_symmetric) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
end += inc;
|
|
|
|
beg -= inc;
|
|
|
|
if (end - beg < minsize) {
|
|
|
|
float center = (beg + end) / 2.0;
|
|
|
|
beg = center - minsize / 2.0;
|
|
|
|
end = center + minsize / 2.0;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
if ((end + inc) - beg < minsize)
|
|
|
|
end = beg + minsize;
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
end += inc;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-12 18:52:50 +02:00
|
|
|
void CanvasItemEditor::_append_canvas_item(CanvasItem *p_item) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-12 18:52:50 +02:00
|
|
|
editor_selection->add_node(p_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
void CanvasItemEditor::_snap_changed() {
|
|
|
|
((SnapDialog *)snap_dialog)->get_fields(snap_offset, snap_step, snap_rotation_offset, snap_rotation_step);
|
|
|
|
viewport->update();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void CanvasItemEditor::_dialog_value_changed(double) {
|
|
|
|
|
|
|
|
if (updating_value_dialog)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (last_option) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
case ZOOM_SET: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
zoom = dialog_val->get_value() / 100.0;
|
2014-02-10 02:10:30 +01:00
|
|
|
_update_scroll(0);
|
|
|
|
viewport->update();
|
|
|
|
|
|
|
|
} break;
|
2017-03-05 16:44:50 +01:00
|
|
|
default: {}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-04 22:39:07 +01:00
|
|
|
void CanvasItemEditor::_selection_result_pressed(int p_result) {
|
|
|
|
|
|
|
|
if (selection_results.size() <= p_result)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItem *item = selection_results[p_result].item;
|
2015-11-04 22:39:07 +01:00
|
|
|
|
|
|
|
if (item)
|
2017-07-18 20:17:55 +02:00
|
|
|
_select_click_on_item(item, Point2(), additive_selection, false);
|
2015-11-04 22:39:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditor::_selection_menu_hide() {
|
|
|
|
|
|
|
|
selection_results.clear();
|
|
|
|
selection_menu->clear();
|
|
|
|
selection_menu->set_size(Vector2(0, 0));
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-03 10:54:24 +02:00
|
|
|
Point2 click = b->get_position();
|
2015-12-13 21:16:13 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *scene = editor->get_edited_scene();
|
2015-12-13 21:16:13 +01:00
|
|
|
if (!scene)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_find_canvas_items_at_pos(click, scene, transform, Transform2D(), selection_results);
|
2015-12-13 21:16:13 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < selection_results.size(); i++) {
|
|
|
|
CanvasItem *item = selection_results[i].item;
|
|
|
|
if (item != scene && item->get_owner() != scene && !scene->is_editable_instance(item->get_owner())) {
|
2015-12-13 21:16:13 +01:00
|
|
|
//invalid result
|
|
|
|
selection_results.remove(i);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection_results.size() == 1) {
|
|
|
|
|
|
|
|
CanvasItem *item = selection_results[0].item;
|
|
|
|
selection_results.clear();
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
additive_selection = b->get_shift();
|
2017-07-18 20:17:55 +02:00
|
|
|
|
|
|
|
if (!_select_click_on_item(item, click, additive_selection, false))
|
2015-12-13 21:16:13 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
} else if (!selection_results.empty()) {
|
|
|
|
|
|
|
|
selection_results.sort();
|
|
|
|
|
|
|
|
NodePath root_path = get_tree()->get_edited_scene_root()->get_path();
|
2017-03-05 16:44:50 +01:00
|
|
|
StringName root_name = root_path.get_name(root_path.get_name_count() - 1);
|
2015-12-13 21:16:13 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < selection_results.size(); i++) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItem *item = selection_results[i].item;
|
2015-12-13 21:16:13 +01:00
|
|
|
|
|
|
|
Ref<Texture> icon;
|
|
|
|
if (item->has_meta("_editor_icon"))
|
2017-03-05 16:44:50 +01:00
|
|
|
icon = item->get_meta("_editor_icon");
|
2015-12-13 21:16:13 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
icon = get_icon(has_icon(item->get_class(), "EditorIcons") ? item->get_class() : String("Object"), "EditorIcons");
|
2015-12-13 21:16:13 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String node_path = "/" + root_name + "/" + root_path.rel_path_to(item->get_path());
|
2015-12-13 21:16:13 +01:00
|
|
|
|
|
|
|
selection_menu->add_item(item->get_name());
|
2017-03-05 16:44:50 +01:00
|
|
|
selection_menu->set_item_icon(i, icon);
|
2015-12-13 21:16:13 +01:00
|
|
|
selection_menu->set_item_metadata(i, node_path);
|
2017-06-06 01:33:38 +02:00
|
|
|
selection_menu->set_item_tooltip(i, String(item->get_name()) + "\nType: " + item->get_class() + "\nPath: " + node_path);
|
2015-12-13 21:16:13 +01:00
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
additive_selection = b->get_shift();
|
2015-12-13 21:16:13 +01:00
|
|
|
|
2017-06-03 10:54:24 +02:00
|
|
|
selection_menu->set_global_position(b->get_global_position());
|
2015-12-13 21:16:13 +01:00
|
|
|
selection_menu->popup();
|
|
|
|
selection_menu->call_deferred("grab_click_focus");
|
|
|
|
selection_menu->set_invalidate_click_until_motion();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{
|
2014-02-10 02:10:30 +01:00
|
|
|
EditorNode *en = editor;
|
2016-03-30 01:02:53 +02:00
|
|
|
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-30 01:02:53 +02:00
|
|
|
if (!over_plugin_list->empty()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
bool discard = over_plugin_list->forward_gui_input(transform, p_event);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (discard) {
|
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventMouseButton> b = p_event;
|
|
|
|
if (b.is_valid()) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Button event
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (b->get_button_index() == BUTTON_WHEEL_DOWN) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Scroll or pan down
|
2017-06-06 01:33:38 +02:00
|
|
|
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
|
|
|
|
|
|
|
v_scroll->set_value(v_scroll->get_value() + int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor());
|
|
|
|
|
|
|
|
} else {
|
2016-07-21 15:06:38 +02:00
|
|
|
|
2017-06-06 01:33:38 +02:00
|
|
|
if (zoom < MIN_ZOOM)
|
|
|
|
return;
|
|
|
|
|
|
|
|
float prev_zoom = zoom;
|
|
|
|
zoom = zoom * (1 - (0.05 * b->get_factor()));
|
|
|
|
{
|
|
|
|
Point2 ofs = b->get_position();
|
|
|
|
ofs = ofs / prev_zoom - ofs / zoom;
|
|
|
|
h_scroll->set_value(h_scroll->get_value() + ofs.x);
|
|
|
|
v_scroll->set_value(v_scroll->get_value() + ofs.y);
|
|
|
|
}
|
2014-05-24 06:35:47 +02:00
|
|
|
}
|
2017-06-06 01:33:38 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
_update_scroll(0);
|
|
|
|
viewport->update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (b->get_button_index() == BUTTON_WHEEL_UP) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Scroll or pan up
|
2017-06-06 01:33:38 +02:00
|
|
|
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
|
|
|
|
|
|
|
v_scroll->set_value(v_scroll->get_value() - int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor());
|
2016-07-21 15:06:38 +02:00
|
|
|
|
2017-06-06 01:33:38 +02:00
|
|
|
} else {
|
|
|
|
if (zoom > MAX_ZOOM) return;
|
|
|
|
|
|
|
|
float prev_zoom = zoom;
|
|
|
|
zoom = zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95);
|
|
|
|
{
|
|
|
|
Point2 ofs = b->get_position();
|
|
|
|
ofs = ofs / prev_zoom - ofs / zoom;
|
|
|
|
h_scroll->set_value(h_scroll->get_value() + ofs.x);
|
|
|
|
v_scroll->set_value(v_scroll->get_value() + ofs.y);
|
|
|
|
}
|
2014-05-24 06:35:47 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
_update_scroll(0);
|
|
|
|
viewport->update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-06 01:33:38 +02:00
|
|
|
if (b->get_button_index() == BUTTON_WHEEL_LEFT) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Pan left
|
2017-06-06 01:33:38 +02:00
|
|
|
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
|
|
|
|
|
|
|
h_scroll->set_value(h_scroll->get_value() - int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b->get_button_index() == BUTTON_WHEEL_RIGHT) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Pan right
|
2017-06-06 01:33:38 +02:00
|
|
|
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
|
|
|
|
|
|
|
h_scroll->set_value(h_scroll->get_value() + int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (b->get_button_index() == BUTTON_RIGHT) {
|
2015-11-04 22:39:07 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (b->is_pressed() && (tool == TOOL_SELECT && b->get_alt())) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Open the selection list
|
2015-12-13 21:16:13 +01:00
|
|
|
_list_select(b);
|
|
|
|
return;
|
2015-11-04 22:39:07 +01:00
|
|
|
}
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (get_item_count() > 0 && drag != DRAG_NONE) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Cancel a drag
|
2014-07-06 16:49:27 +02:00
|
|
|
if (bone_ik_list.size()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<BoneIK>::Element *E = bone_ik_list.back(); E; E = E->prev()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
E->get().node->edit_set_state(E->get().orig_state);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-07-06 16:49:27 +02:00
|
|
|
bone_ik_list.clear();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-07-06 16:49:27 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-07-06 16:49:27 +02:00
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
|
2014-07-06 16:49:27 +02:00
|
|
|
if (!se)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
canvas_item->edit_set_state(se->undo_state);
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item))
|
|
|
|
Object::cast_to<Node2D>(canvas_item)->edit_set_pivot(se->undo_pivot);
|
|
|
|
if (Object::cast_to<Control>(canvas_item))
|
|
|
|
Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot);
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
drag = DRAG_NONE;
|
2014-07-06 16:49:27 +02:00
|
|
|
viewport->update();
|
2017-03-05 16:44:50 +01:00
|
|
|
can_move_pivot = false;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} else if (box_selecting) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Cancel box selection
|
2017-03-05 16:44:50 +01:00
|
|
|
box_selecting = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
viewport->update();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (b->get_button_index() == BUTTON_LEFT && tool == TOOL_LIST_SELECT) {
|
|
|
|
if (b->is_pressed())
|
2017-07-18 20:17:55 +02:00
|
|
|
// Open the selection list
|
2015-12-13 21:16:13 +01:00
|
|
|
_list_select(b);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (b->get_button_index() == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) {
|
|
|
|
if (b->is_pressed()) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Set the pivot point
|
2017-06-03 10:54:24 +02:00
|
|
|
Point2 mouse_pos = b->get_position();
|
2017-03-05 16:44:50 +01:00
|
|
|
mouse_pos = transform.affine_inverse().xform(mouse_pos);
|
|
|
|
mouse_pos = snap_point(mouse_pos);
|
2015-12-28 13:38:15 +01:00
|
|
|
_edit_set_pivot(mouse_pos);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (tool == TOOL_PAN || b->get_button_index() != BUTTON_LEFT || Input::get_singleton()->is_key_pressed(KEY_SPACE))
|
2017-07-18 20:17:55 +02:00
|
|
|
// Pan the view
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
2017-07-18 20:17:55 +02:00
|
|
|
// -- From now we consider that the button is BUTTON_LEFT --
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!b->is_pressed()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (drag != DRAG_NONE) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Stop dragging
|
2014-02-10 02:10:30 +01:00
|
|
|
if (undo_redo) {
|
|
|
|
|
2014-07-06 16:49:27 +02:00
|
|
|
if (bone_ik_list.size()) {
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Edit IK Chain"));
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<BoneIK>::Element *E = bone_ik_list.back(); E; E = E->prev()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(E->get().node, "edit_set_state", E->get().node->edit_get_state());
|
|
|
|
undo_redo->add_undo_method(E->get().node, "edit_set_state", E->get().orig_state);
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(viewport, "update");
|
|
|
|
undo_redo->add_undo_method(viewport, "update");
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
bone_ik_list.clear();
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
} else {
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Edit CanvasItem"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-07-06 16:49:27 +02:00
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
|
2014-07-06 16:49:27 +02:00
|
|
|
if (!se)
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant state = canvas_item->edit_get_state();
|
|
|
|
undo_redo->add_do_method(canvas_item, "edit_set_state", state);
|
|
|
|
undo_redo->add_undo_method(canvas_item, "edit_set_state", se->undo_state);
|
2017-07-06 22:42:44 +02:00
|
|
|
{
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *pvt = Object::cast_to<Node2D>(canvas_item);
|
2017-07-06 22:42:44 +02:00
|
|
|
if (pvt && pvt->edit_has_pivot()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(canvas_item, "edit_set_pivot", pvt->edit_get_pivot());
|
|
|
|
undo_redo->add_undo_method(canvas_item, "edit_set_pivot", se->undo_pivot);
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
2017-07-06 22:42:44 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *cnt = Object::cast_to<Control>(canvas_item);
|
2017-07-06 22:42:44 +02:00
|
|
|
if (cnt) {
|
|
|
|
undo_redo->add_do_method(canvas_item, "set_pivot_offset", cnt->get_pivot_offset());
|
|
|
|
undo_redo->add_undo_method(canvas_item, "set_pivot_offset", se->undo_pivot);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-06 16:49:27 +02:00
|
|
|
undo_redo->commit_action();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
drag = DRAG_NONE;
|
2014-02-10 02:10:30 +01:00
|
|
|
viewport->update();
|
2017-03-05 16:44:50 +01:00
|
|
|
can_move_pivot = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (box_selecting) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Stop box selection
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *scene = editor->get_edited_scene();
|
2014-02-10 02:10:30 +01:00
|
|
|
if (scene) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<CanvasItem *> selitems;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Point2 bsfrom = transform.xform(drag_from);
|
2017-03-05 16:44:50 +01:00
|
|
|
Point2 bsto = transform.xform(box_selecting_to);
|
|
|
|
if (bsfrom.x > bsto.x)
|
|
|
|
SWAP(bsfrom.x, bsto.x);
|
|
|
|
if (bsfrom.y > bsto.y)
|
|
|
|
SWAP(bsfrom.y, bsto.y);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_find_canvas_items_at_rect(Rect2(bsfrom, bsto - bsfrom), scene, transform, Transform2D(), &selitems);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<CanvasItem *>::Element *E = selitems.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_append_canvas_item(E->get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
box_selecting = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
viewport->update();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-18 20:17:55 +02:00
|
|
|
// -- From now we consider that the button is BUTTON_LEFT and that it is pressed --
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<ObjectID, BoneList>::Element *Cbone = NULL; //closest
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
bone_ik_list.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
float closest_dist = 1e20;
|
2017-01-15 02:20:05 +01:00
|
|
|
int bone_width = EditorSettings::get_singleton()->get("editors/2d/bone_width");
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<ObjectID, BoneList>::Element *E = bone_list.front(); E; E = E->next()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
if (E->get().from == E->get().to)
|
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 s[2] = {
|
2014-07-06 16:49:27 +02:00
|
|
|
E->get().from,
|
|
|
|
E->get().to
|
|
|
|
};
|
|
|
|
|
2017-06-03 10:54:24 +02:00
|
|
|
Vector2 p = Geometry::get_closest_point_to_segment_2d(b->get_position(), s);
|
|
|
|
float d = p.distance_to(b->get_position());
|
2017-03-05 16:44:50 +01:00
|
|
|
if (d < bone_width && d < closest_dist) {
|
|
|
|
Cbone = E;
|
|
|
|
closest_dist = d;
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cbone) {
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *b = Object::cast_to<Node2D>(ObjectDB::get_instance(Cbone->get().bone));
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
if (b) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ik_found = false;
|
2017-07-30 15:32:22 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool first = true;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (b) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItem *pi = b->get_parent_item();
|
2014-07-06 16:49:27 +02:00
|
|
|
if (!pi)
|
|
|
|
break;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float len = pi->get_global_transform().get_origin().distance_to(b->get_global_position());
|
2017-08-24 22:58:51 +02:00
|
|
|
b = Object::cast_to<Node2D>(pi);
|
2014-07-06 16:49:27 +02:00
|
|
|
if (!b)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bone_orig_xform = b->get_global_transform();
|
|
|
|
first = false;
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
BoneIK bik;
|
2017-03-05 16:44:50 +01:00
|
|
|
bik.node = b;
|
|
|
|
bik.len = len;
|
|
|
|
bik.orig_state = b->edit_get_state();
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
bone_ik_list.push_back(bik);
|
|
|
|
|
|
|
|
if (b->has_meta("_edit_ik_")) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ik_found = bone_ik_list.size() > 1;
|
2014-07-06 16:49:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pi->has_meta("_edit_bone_"))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ik_found)
|
|
|
|
bone_ik_list.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 20:17:55 +02:00
|
|
|
// Single selected item
|
2017-07-17 23:28:19 +02:00
|
|
|
CanvasItem *canvas_item = get_single_item();
|
|
|
|
if (canvas_item) {
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(!se);
|
|
|
|
|
2017-06-03 10:54:24 +02:00
|
|
|
Point2 click = b->get_position();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-17 23:28:19 +02:00
|
|
|
// Rotation
|
2017-05-20 17:38:03 +02:00
|
|
|
if ((b->get_control() && tool == TOOL_SELECT) || tool == TOOL_ROTATE) {
|
2017-03-05 16:44:50 +01:00
|
|
|
drag = DRAG_ROTATE;
|
|
|
|
drag_from = transform.affine_inverse().xform(click);
|
|
|
|
se->undo_state = canvas_item->edit_get_state();
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item))
|
|
|
|
se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot();
|
|
|
|
if (Object::cast_to<Control>(canvas_item))
|
|
|
|
se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tool == TOOL_SELECT) {
|
2017-07-17 23:28:19 +02:00
|
|
|
// Open a sub-scene on double-click
|
2017-05-20 17:38:03 +02:00
|
|
|
if (b->is_doubleclick()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_filename() != "" && canvas_item != editor->get_edited_scene()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
editor->open_request(canvas_item->get_filename());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-29 16:57:32 +02:00
|
|
|
// Drag resize handles
|
|
|
|
drag = _get_resize_handle_drag_type(click, drag_point_from);
|
2017-07-18 20:17:55 +02:00
|
|
|
if (drag != DRAG_NONE) {
|
2017-03-05 16:44:50 +01:00
|
|
|
drag_from = transform.affine_inverse().xform(click);
|
|
|
|
se->undo_state = canvas_item->edit_get_state();
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item))
|
|
|
|
se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot();
|
|
|
|
if (Object::cast_to<Control>(canvas_item))
|
|
|
|
se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-07-29 16:57:32 +02:00
|
|
|
|
|
|
|
// Drag anchor handles
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Control>(canvas_item)) {
|
2017-07-29 16:57:32 +02:00
|
|
|
drag = _get_anchor_handle_drag_type(click, drag_point_from);
|
|
|
|
if (drag != DRAG_NONE) {
|
|
|
|
drag_from = transform.affine_inverse().xform(click);
|
|
|
|
se->undo_state = canvas_item->edit_get_state();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 20:17:55 +02:00
|
|
|
// Multiple selected items
|
2017-06-03 10:54:24 +02:00
|
|
|
Point2 click = b->get_position();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if ((b->get_alt() || tool == TOOL_MOVE) && get_item_count()) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Drag the nodes
|
2017-03-23 00:47:51 +01:00
|
|
|
_prepare_drag(click);
|
2014-02-10 02:10:30 +01:00
|
|
|
viewport->update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItem *c = NULL;
|
2014-07-06 16:49:27 +02:00
|
|
|
if (Cbone) {
|
2017-08-24 22:58:51 +02:00
|
|
|
c = Object::cast_to<CanvasItem>(ObjectDB::get_instance(Cbone->get().bone));
|
2014-07-06 16:49:27 +02:00
|
|
|
if (c)
|
2017-03-05 16:44:50 +01:00
|
|
|
c = c->get_parent_item();
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
2017-07-18 20:17:55 +02:00
|
|
|
|
|
|
|
Node *scene = editor->get_edited_scene();
|
|
|
|
if (!scene)
|
|
|
|
return;
|
|
|
|
// Find the item to select
|
2014-07-06 16:49:27 +02:00
|
|
|
if (!c) {
|
2017-07-17 23:28:19 +02:00
|
|
|
Vector<_SelectResult> selection;
|
|
|
|
_find_canvas_items_at_pos(click, scene, transform, Transform2D(), selection, 1);
|
|
|
|
if (!selection.empty())
|
|
|
|
c = selection[0].item;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItem *cn = c;
|
|
|
|
while (cn) {
|
2014-07-06 16:49:27 +02:00
|
|
|
if (cn->has_meta("_edit_group_")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
c = cn;
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
cn = cn->get_parent_item();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *n = c;
|
2017-01-03 03:03:46 +01:00
|
|
|
while ((n && n != scene && n->get_owner() != scene) || (n && !n->is_class("CanvasItem"))) {
|
2014-02-10 02:10:30 +01:00
|
|
|
n = n->get_parent();
|
|
|
|
};
|
2017-08-08 12:13:17 +02:00
|
|
|
|
|
|
|
if (n) {
|
2017-08-24 22:58:51 +02:00
|
|
|
c = Object::cast_to<CanvasItem>(n);
|
2017-08-08 12:13:17 +02:00
|
|
|
} else {
|
|
|
|
c = NULL;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-18 20:17:55 +02:00
|
|
|
// Select the item
|
2017-05-20 17:38:03 +02:00
|
|
|
additive_selection = b->get_shift();
|
2017-07-18 20:17:55 +02:00
|
|
|
if (!c) {
|
|
|
|
_select_click_on_empty_area(click, additive_selection, true);
|
|
|
|
} else if (!_select_click_on_item(c, click, additive_selection, true)) {
|
2015-11-04 22:39:07 +01:00
|
|
|
return;
|
2017-07-18 20:17:55 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventMouseMotion> m = p_event;
|
|
|
|
if (m.is_valid()) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Mouse motion event
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-15 01:56:22 +01:00
|
|
|
if (!viewport->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
|
2014-02-10 02:10:30 +01:00
|
|
|
viewport->call_deferred("grab_focus");
|
|
|
|
|
|
|
|
if (box_selecting) {
|
2017-07-18 20:17:55 +02:00
|
|
|
// Update box selection
|
2017-06-03 10:54:24 +02:00
|
|
|
box_selecting_to = transform.affine_inverse().xform(m->get_position());
|
2014-02-10 02:10:30 +01:00
|
|
|
viewport->update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (drag == DRAG_NONE) {
|
2017-05-20 17:38:03 +02:00
|
|
|
if ((m->get_button_mask() & BUTTON_MASK_LEFT && tool == TOOL_PAN) || m->get_button_mask() & BUTTON_MASK_MIDDLE || (m->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE))) {
|
2017-07-29 16:57:32 +02:00
|
|
|
// Pan the viewport
|
2017-03-22 21:18:47 +01:00
|
|
|
Point2i relative;
|
|
|
|
if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) {
|
|
|
|
relative = Input::get_singleton()->warp_mouse_motion(m, viewport->get_global_rect());
|
|
|
|
} else {
|
2017-05-20 17:38:03 +02:00
|
|
|
relative = m->get_relative();
|
2017-03-22 21:18:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
h_scroll->set_value(h_scroll->get_value() - relative.x / zoom);
|
|
|
|
v_scroll->set_value(v_scroll->get_value() - relative.y / zoom);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!se)
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool dragging_bone = drag == DRAG_ALL && selection.size() == 1 && bone_ik_list.size();
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
if (!dragging_bone) {
|
|
|
|
canvas_item->edit_set_state(se->undo_state); //reset state and reapply
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item))
|
|
|
|
Object::cast_to<Node2D>(canvas_item)->edit_set_pivot(se->undo_pivot);
|
|
|
|
if (Object::cast_to<Control>(canvas_item))
|
|
|
|
Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot);
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector2 dfrom = drag_from;
|
2017-06-03 10:54:24 +02:00
|
|
|
Vector2 dto = transform.affine_inverse().xform(m->get_position());
|
2014-02-10 02:10:30 +01:00
|
|
|
if (canvas_item->has_meta("_edit_lock_"))
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (drag == DRAG_ROTATE) {
|
2017-07-29 16:57:32 +02:00
|
|
|
// Rotate the node
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector2 center = canvas_item->get_global_transform_with_canvas().get_origin();
|
2016-06-27 15:47:51 +02:00
|
|
|
{
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *node = Object::cast_to<Node2D>(canvas_item);
|
2016-06-27 15:47:51 +02:00
|
|
|
|
|
|
|
if (node) {
|
2017-01-06 06:27:48 +01:00
|
|
|
real_t angle = node->get_rotation();
|
2017-03-05 16:44:50 +01:00
|
|
|
node->set_rotation(snap_angle(angle + (dfrom - center).angle_to(dto - center), angle));
|
2016-06-27 15:47:51 +02:00
|
|
|
display_rotate_to = dto;
|
|
|
|
display_rotate_from = center;
|
|
|
|
viewport->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *node = Object::cast_to<Control>(canvas_item);
|
2016-06-27 15:47:51 +02:00
|
|
|
|
|
|
|
if (node) {
|
2017-01-06 06:27:48 +01:00
|
|
|
real_t angle = node->get_rotation();
|
2017-03-05 16:44:50 +01:00
|
|
|
node->set_rotation(snap_angle(angle + (dfrom - center).angle_to(dto - center), angle));
|
2016-06-27 15:47:51 +02:00
|
|
|
display_rotate_to = dto;
|
|
|
|
display_rotate_from = center;
|
|
|
|
viewport->update();
|
|
|
|
}
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *control = Object::cast_to<Control>(canvas_item);
|
2017-07-29 16:57:32 +02:00
|
|
|
if (control) {
|
2017-07-30 15:32:22 +02:00
|
|
|
// Drag and snap the anchor
|
2017-07-29 16:57:32 +02:00
|
|
|
Vector2 anchor = _position_to_anchor(control, canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dto - drag_from + drag_point_from));
|
|
|
|
|
|
|
|
switch (drag) {
|
|
|
|
case DRAG_ANCHOR_TOP_LEFT:
|
2017-08-11 19:25:26 +02:00
|
|
|
control->set_anchor(MARGIN_LEFT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_RIGHT)), false, false);
|
|
|
|
control->set_anchor(MARGIN_TOP, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_BOTTOM)), false, false);
|
2017-07-29 16:57:32 +02:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case DRAG_ANCHOR_TOP_RIGHT:
|
2017-08-11 19:25:26 +02:00
|
|
|
control->set_anchor(MARGIN_RIGHT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_LEFT)), false, false);
|
|
|
|
control->set_anchor(MARGIN_TOP, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_BOTTOM)), false, false);
|
2017-07-29 16:57:32 +02:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case DRAG_ANCHOR_BOTTOM_RIGHT:
|
2017-08-11 19:25:26 +02:00
|
|
|
control->set_anchor(MARGIN_RIGHT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_LEFT)), false, false);
|
|
|
|
control->set_anchor(MARGIN_BOTTOM, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_TOP)), false, false);
|
2017-07-29 16:57:32 +02:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case DRAG_ANCHOR_BOTTOM_LEFT:
|
2017-08-11 19:25:26 +02:00
|
|
|
control->set_anchor(MARGIN_LEFT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_RIGHT)), false, false);
|
|
|
|
control->set_anchor(MARGIN_BOTTOM, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_TOP)), false, false);
|
2017-07-29 16:57:32 +02:00
|
|
|
continue;
|
|
|
|
break;
|
2017-08-04 19:27:30 +02:00
|
|
|
case DRAG_ANCHOR_ALL:
|
|
|
|
control->set_anchor(MARGIN_LEFT, _anchor_snap(anchor.x));
|
|
|
|
control->set_anchor(MARGIN_RIGHT, _anchor_snap(anchor.x));
|
|
|
|
control->set_anchor(MARGIN_TOP, _anchor_snap(anchor.y));
|
|
|
|
control->set_anchor(MARGIN_BOTTOM, _anchor_snap(anchor.y));
|
|
|
|
continue;
|
|
|
|
break;
|
2017-07-29 16:57:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 16:00:44 +02:00
|
|
|
bool uniform = m->get_shift();
|
|
|
|
bool symmetric = m->get_alt();
|
2016-04-29 14:06:29 +02:00
|
|
|
|
2017-07-29 16:57:32 +02:00
|
|
|
if (drag == DRAG_ALL || drag == DRAG_NODE_2D)
|
|
|
|
dto -= drag_from - drag_point_from;
|
2016-04-29 14:06:29 +02:00
|
|
|
|
2017-03-27 01:32:24 +02:00
|
|
|
if (uniform && (drag == DRAG_ALL || drag == DRAG_NODE_2D)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (ABS(dto.x - drag_point_from.x) > ABS(dto.y - drag_point_from.y)) {
|
2016-04-29 14:06:29 +02:00
|
|
|
dto.y = drag_point_from.y;
|
|
|
|
} else {
|
|
|
|
dto.x = drag_point_from.x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
dfrom = drag_point_from;
|
2016-04-29 14:06:29 +02:00
|
|
|
dto = snap_point(dto, drag_point_from);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector2 drag_vector =
|
|
|
|
canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dto) -
|
|
|
|
canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dfrom);
|
|
|
|
|
|
|
|
Rect2 local_rect = canvas_item->get_item_rect();
|
2017-06-04 00:25:13 +02:00
|
|
|
Vector2 begin = local_rect.position;
|
|
|
|
Vector2 end = local_rect.position + local_rect.size;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector2 minsize = canvas_item->edit_get_minimum_size();
|
|
|
|
|
2016-01-06 00:13:07 +01:00
|
|
|
if (uniform) {
|
2017-07-20 22:03:34 +02:00
|
|
|
// Keep the height/width ratio of the item
|
2017-01-14 00:00:43 +01:00
|
|
|
float aspect = local_rect.size.aspect();
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (drag) {
|
2017-07-11 00:14:22 +02:00
|
|
|
case DRAG_LEFT:
|
2017-07-20 22:03:34 +02:00
|
|
|
drag_vector.y = -drag_vector.x / aspect;
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
|
|
|
case DRAG_RIGHT:
|
2017-07-20 22:03:34 +02:00
|
|
|
drag_vector.y = drag_vector.x / aspect;
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
|
|
|
case DRAG_TOP:
|
2017-07-20 22:03:34 +02:00
|
|
|
drag_vector.x = -drag_vector.y * aspect;
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
|
|
|
case DRAG_BOTTOM:
|
2017-07-20 22:03:34 +02:00
|
|
|
drag_vector.x = drag_vector.y * aspect;
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
2016-01-06 00:13:07 +01:00
|
|
|
case DRAG_BOTTOM_LEFT:
|
2017-07-11 00:14:22 +02:00
|
|
|
case DRAG_TOP_RIGHT:
|
2016-01-06 00:13:07 +01:00
|
|
|
if (aspect > 1.0) { // width > height, take x as reference
|
2017-03-05 16:44:50 +01:00
|
|
|
drag_vector.y = -drag_vector.x / aspect;
|
2016-01-06 00:13:07 +01:00
|
|
|
} else { // height > width, take y as reference
|
2017-03-05 16:44:50 +01:00
|
|
|
drag_vector.x = -drag_vector.y * aspect;
|
2016-01-06 00:13:07 +01:00
|
|
|
}
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
2016-01-06 00:13:07 +01:00
|
|
|
case DRAG_BOTTOM_RIGHT:
|
2017-07-11 00:14:22 +02:00
|
|
|
case DRAG_TOP_LEFT:
|
2016-01-06 00:13:07 +01:00
|
|
|
if (aspect > 1.0) { // width > height, take x as reference
|
2017-03-05 16:44:50 +01:00
|
|
|
drag_vector.y = drag_vector.x / aspect;
|
2016-01-06 00:13:07 +01:00
|
|
|
} else { // height > width, take y as reference
|
2017-03-05 16:44:50 +01:00
|
|
|
drag_vector.x = drag_vector.y * aspect;
|
2016-01-06 00:13:07 +01:00
|
|
|
}
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
2017-07-20 22:03:34 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (drag) {
|
|
|
|
case DRAG_RIGHT:
|
2017-07-11 00:14:22 +02:00
|
|
|
case DRAG_LEFT:
|
2017-07-20 22:03:34 +02:00
|
|
|
drag_vector.y = 0;
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
2017-07-20 22:03:34 +02:00
|
|
|
case DRAG_TOP:
|
2017-07-11 00:14:22 +02:00
|
|
|
case DRAG_BOTTOM:
|
2017-07-20 22:03:34 +02:00
|
|
|
drag_vector.x = 0;
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
2016-01-06 00:13:07 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (drag) {
|
2017-07-11 00:14:22 +02:00
|
|
|
case DRAG_ALL:
|
2017-03-05 16:44:50 +01:00
|
|
|
begin += drag_vector;
|
|
|
|
end += drag_vector;
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
2017-07-20 22:03:34 +02:00
|
|
|
case DRAG_RIGHT:
|
|
|
|
case DRAG_BOTTOM:
|
2017-07-11 00:14:22 +02:00
|
|
|
case DRAG_BOTTOM_RIGHT:
|
2017-03-05 16:44:50 +01:00
|
|
|
incend(begin.x, end.x, drag_vector.x, minsize.x, symmetric);
|
|
|
|
incend(begin.y, end.y, drag_vector.y, minsize.y, symmetric);
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
|
|
|
case DRAG_TOP_LEFT:
|
2017-03-05 16:44:50 +01:00
|
|
|
incbeg(begin.x, end.x, drag_vector.x, minsize.x, symmetric);
|
|
|
|
incbeg(begin.y, end.y, drag_vector.y, minsize.y, symmetric);
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
2017-07-20 22:03:34 +02:00
|
|
|
case DRAG_TOP:
|
2017-07-11 00:14:22 +02:00
|
|
|
case DRAG_TOP_RIGHT:
|
2017-03-05 16:44:50 +01:00
|
|
|
incbeg(begin.y, end.y, drag_vector.y, minsize.y, symmetric);
|
|
|
|
incend(begin.x, end.x, drag_vector.x, minsize.x, symmetric);
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
2017-07-20 22:03:34 +02:00
|
|
|
case DRAG_LEFT:
|
2017-07-11 00:14:22 +02:00
|
|
|
case DRAG_BOTTOM_LEFT:
|
2017-03-05 16:44:50 +01:00
|
|
|
incbeg(begin.x, end.x, drag_vector.x, minsize.x, symmetric);
|
|
|
|
incend(begin.y, end.y, drag_vector.y, minsize.y, symmetric);
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAG_PIVOT:
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item)) {
|
|
|
|
Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
|
2017-03-05 16:44:50 +01:00
|
|
|
n2d->edit_set_pivot(se->undo_pivot + drag_vector);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Control>(canvas_item)) {
|
|
|
|
Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot + drag_vector);
|
2017-07-06 22:42:44 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
|
|
|
case DRAG_NODE_2D:
|
2017-03-23 00:47:51 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
ERR_FAIL_COND(!Object::cast_to<Node2D>(canvas_item));
|
|
|
|
Object::cast_to<Node2D>(canvas_item)->set_global_position(dto);
|
2017-03-23 00:47:51 +01:00
|
|
|
continue;
|
2017-07-11 00:14:22 +02:00
|
|
|
break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2014-07-06 16:49:27 +02:00
|
|
|
if (!dragging_bone) {
|
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
local_rect.position = begin;
|
2017-03-05 16:44:50 +01:00
|
|
|
local_rect.size = end - begin;
|
2014-07-06 16:49:27 +02:00
|
|
|
canvas_item->edit_set_rect(local_rect);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//ok, all that had to be done was done, now solve IK
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D final_xform = bone_orig_xform;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
if (n2d) {
|
|
|
|
|
|
|
|
float total_len = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<BoneIK>::Element *E = bone_ik_list.front(); E; E = E->next()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
if (E->prev())
|
2017-03-05 16:44:50 +01:00
|
|
|
total_len += E->get().len;
|
2014-07-06 16:49:27 +02:00
|
|
|
E->get().pos = E->get().node->get_global_transform().get_origin();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
final_xform.elements[2] += dto - dfrom; //final_xform.affine_inverse().basis_xform_inv(drag_vector);
|
2014-07-06 16:49:27 +02:00
|
|
|
//n2d->set_global_transform(final_xform);
|
|
|
|
}
|
|
|
|
|
|
|
|
CanvasItem *last = bone_ik_list.back()->get().node;
|
|
|
|
if (!last)
|
|
|
|
break;
|
|
|
|
|
|
|
|
Vector2 root_pos = last->get_global_transform().get_origin();
|
|
|
|
Vector2 leaf_pos = final_xform.get_origin();
|
|
|
|
|
|
|
|
if ((leaf_pos.distance_to(root_pos)) > total_len) {
|
|
|
|
//oops dude you went too far
|
2016-05-04 15:28:37 +02:00
|
|
|
//print_line("TOO FAR!");
|
2014-07-06 16:49:27 +02:00
|
|
|
Vector2 rel = leaf_pos - root_pos;
|
|
|
|
rel = rel.normalized() * total_len;
|
2017-03-05 16:44:50 +01:00
|
|
|
leaf_pos = root_pos + rel;
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bone_ik_list.front()->get().pos = leaf_pos;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2016-05-04 15:28:37 +02:00
|
|
|
//print_line("BONE IK LIST "+itos(bone_ik_list.size()));
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (bone_ik_list.size() > 2) {
|
|
|
|
int solver_iterations = 64;
|
|
|
|
float solver_k = 0.3;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < solver_iterations; i++) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<BoneIK>::Element *E = bone_ik_list.front(); E; E = E->next()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (E == bone_ik_list.back()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
float len = E->next()->get().len;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (E->next() == bone_ik_list.back()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
//print_line("back");
|
|
|
|
|
|
|
|
Vector2 rel = E->get().pos - E->next()->get().pos;
|
2016-05-04 15:28:37 +02:00
|
|
|
//print_line("PREV "+E->get().pos);
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 desired = E->next()->get().pos + rel.normalized() * len;
|
2016-05-04 15:28:37 +02:00
|
|
|
//print_line("DESIRED "+desired);
|
2017-03-05 16:44:50 +01:00
|
|
|
E->get().pos = E->get().pos.linear_interpolate(desired, solver_k);
|
2016-05-04 15:28:37 +02:00
|
|
|
//print_line("POST "+E->get().pos);
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (E == bone_ik_list.front()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
//only adjust parent
|
|
|
|
//print_line("front");
|
|
|
|
Vector2 rel = E->next()->get().pos - E->get().pos;
|
2016-05-04 15:28:37 +02:00
|
|
|
//print_line("PREV "+E->next()->get().pos);
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 desired = E->get().pos + rel.normalized() * len;
|
2016-05-04 15:28:37 +02:00
|
|
|
//print_line("DESIRED "+desired);
|
2017-03-05 16:44:50 +01:00
|
|
|
E->next()->get().pos = E->next()->get().pos.linear_interpolate(desired, solver_k);
|
2016-05-04 15:28:37 +02:00
|
|
|
//print_line("POST "+E->next()->get().pos);
|
2014-07-06 16:49:27 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
Vector2 rel = E->next()->get().pos - E->get().pos;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 cen = (E->next()->get().pos + E->get().pos) * 0.5;
|
|
|
|
rel = rel.linear_interpolate(rel.normalized() * len, solver_k);
|
|
|
|
rel *= 0.5;
|
|
|
|
E->next()->get().pos = cen + rel;
|
|
|
|
E->get().pos = cen - rel;
|
2014-07-06 16:49:27 +02:00
|
|
|
//print_line("mid");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<BoneIK>::Element *E = bone_ik_list.back(); E; E = E->prev()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
Node2D *n = E->get().node;
|
|
|
|
|
|
|
|
if (!E->prev()) {
|
|
|
|
//last goes to what it was
|
2017-01-04 05:16:14 +01:00
|
|
|
final_xform.set_origin(n->get_global_position());
|
2014-07-06 16:49:27 +02:00
|
|
|
n->set_global_transform(final_xform);
|
|
|
|
|
|
|
|
} else {
|
2017-01-04 05:16:14 +01:00
|
|
|
Vector2 rel = (E->prev()->get().node->get_global_position() - n->get_global_position()).normalized();
|
2014-07-06 16:49:27 +02:00
|
|
|
Vector2 rel2 = (E->prev()->get().pos - E->get().pos).normalized();
|
|
|
|
float rot = rel.angle_to(rel2);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (n->get_global_transform().basis_determinant() < 0) {
|
2014-07-06 16:49:27 +02:00
|
|
|
//mirrored, rotate the other way
|
2017-03-05 16:44:50 +01:00
|
|
|
rot = -rot;
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
n->rotate(rot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventKey> k = p_event;
|
|
|
|
if (k.is_valid()) {
|
|
|
|
if (k->is_pressed() && drag == DRAG_NONE) {
|
2017-07-25 21:09:32 +02:00
|
|
|
// Move the object with the arrow keys
|
2014-05-09 09:11:24 +02:00
|
|
|
KeyMoveMODE move_mode = MOVE_VIEW_BASE;
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_alt()) move_mode = MOVE_LOCAL_BASE;
|
|
|
|
if (k->get_control() || k->get_metakey()) move_mode = MOVE_LOCAL_WITH_ROT;
|
|
|
|
|
|
|
|
if (k->get_scancode() == KEY_UP)
|
|
|
|
_key_move(Vector2(0, -1), k->get_shift(), move_mode);
|
|
|
|
else if (k->get_scancode() == KEY_DOWN)
|
|
|
|
_key_move(Vector2(0, 1), k->get_shift(), move_mode);
|
|
|
|
else if (k->get_scancode() == KEY_LEFT)
|
|
|
|
_key_move(Vector2(-1, 0), k->get_shift(), move_mode);
|
|
|
|
else if (k->get_scancode() == KEY_RIGHT)
|
|
|
|
_key_move(Vector2(1, 0), k->get_shift(), move_mode);
|
|
|
|
else if (k->get_scancode() == KEY_ESCAPE) {
|
2014-02-10 02:10:30 +01:00
|
|
|
editor_selection->clear();
|
|
|
|
viewport->update();
|
2017-03-05 16:44:50 +01:00
|
|
|
} else
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
accept_event();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 18:33:06 +02:00
|
|
|
void CanvasItemEditor::_draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side) {
|
|
|
|
if (p_value != 0) {
|
|
|
|
Color color = Color(0.8, 0.8, 0.8, 0.5);
|
|
|
|
Ref<Font> font = get_font("font", "Label");
|
|
|
|
String str = vformat("%.1f %%", p_value * 100.0);
|
|
|
|
Size2 text_size = font->get_string_size(str);
|
|
|
|
switch (p_side) {
|
|
|
|
case MARGIN_LEFT:
|
|
|
|
p_position += Vector2(-text_size.x - 5, text_size.y / 2);
|
|
|
|
break;
|
|
|
|
case MARGIN_TOP:
|
|
|
|
p_position += Vector2(-text_size.x / 2, -5);
|
|
|
|
break;
|
|
|
|
case MARGIN_RIGHT:
|
|
|
|
p_position += Vector2(5, text_size.y / 2);
|
|
|
|
break;
|
|
|
|
case MARGIN_BOTTOM:
|
|
|
|
p_position += Vector2(-text_size.x / 2, text_size.y + 5);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
viewport->draw_string(font, p_position, str, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void CanvasItemEditor::_viewport_draw() {
|
|
|
|
|
|
|
|
// TODO fetch the viewport?
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<Texture> pivot = get_icon("EditorPivot", "EditorIcons");
|
2014-02-10 02:10:30 +01:00
|
|
|
_update_scrollbars();
|
2017-03-05 16:44:50 +01:00
|
|
|
RID ci = viewport->get_canvas_item();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-02-15 09:00:55 +01:00
|
|
|
if (snap_show_grid) {
|
2017-07-25 21:09:32 +02:00
|
|
|
//Draw the grid
|
2014-02-10 02:10:30 +01:00
|
|
|
Size2 s = viewport->get_size();
|
|
|
|
int last_cell;
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D xform = transform.affine_inverse();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-25 21:09:32 +02:00
|
|
|
Vector2 grid_offset;
|
|
|
|
if (snap_relative && snap_grid && get_item_count() > 0) {
|
|
|
|
Vector2 topleft = _find_topleftmost_point();
|
|
|
|
grid_offset.x = fmod(topleft.x, snap_step.x);
|
|
|
|
grid_offset.y = fmod(topleft.y, snap_step.y);
|
|
|
|
} else {
|
|
|
|
grid_offset = snap_offset;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (snap_step.x != 0) {
|
|
|
|
for (int i = 0; i < s.width; i++) {
|
2017-07-25 21:09:32 +02:00
|
|
|
int cell = Math::fast_ftoi(Math::floor((xform.xform(Vector2(i, 0)).x - grid_offset.x) / snap_step.x));
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == 0)
|
|
|
|
last_cell = cell;
|
|
|
|
if (last_cell != cell)
|
|
|
|
viewport->draw_line(Point2(i, 0), Point2(i, s.height), Color(0.3, 0.7, 1, 0.3));
|
|
|
|
last_cell = cell;
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (snap_step.y != 0) {
|
|
|
|
for (int i = 0; i < s.height; i++) {
|
2017-07-25 21:09:32 +02:00
|
|
|
int cell = Math::fast_ftoi(Math::floor((xform.xform(Vector2(0, i)).y - grid_offset.y) / snap_step.y));
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == 0)
|
|
|
|
last_cell = cell;
|
|
|
|
if (last_cell != cell)
|
|
|
|
viewport->draw_line(Point2(0, i), Point2(s.width, i), Color(0.3, 0.7, 1, 0.3));
|
|
|
|
last_cell = cell;
|
2015-02-15 09:00:55 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (viewport->has_focus()) {
|
|
|
|
Size2 size = viewport->get_size();
|
2017-05-02 22:13:12 +02:00
|
|
|
get_stylebox("Focus", "EditorStyles")->draw(ci, Rect2(Point2(), size));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<Texture> lock = get_icon("Lock", "EditorIcons");
|
|
|
|
Ref<Texture> group = get_icon("Group", "EditorIcons");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool single = get_single_item() != NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<Node *, Object *> &selection = editor_selection->get_selection();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool pivot_found = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!se)
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Rect2 rect = canvas_item->get_item_rect();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform2D xform = transform * canvas_item->get_global_transform_with_canvas();
|
|
|
|
VisualServer::get_singleton()->canvas_item_add_set_transform(ci, xform);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 endpoints[4] = {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
xform.xform(rect.position),
|
|
|
|
xform.xform(rect.position + Vector2(rect.size.x, 0)),
|
|
|
|
xform.xform(rect.position + rect.size),
|
|
|
|
xform.xform(rect.position + Vector2(0, rect.size.y))
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Color c = Color(1, 0.6, 0.4, 0.7);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_set_transform(ci, Transform2D());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
viewport->draw_line(endpoints[i], endpoints[(i + 1) % 4], c, 2);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (single && (tool == TOOL_SELECT || tool == TOOL_MOVE || tool == TOOL_ROTATE || tool == TOOL_EDIT_PIVOT)) { //kind of sucks
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item)->edit_has_pivot()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
viewport->draw_texture(pivot, xform.get_origin() + (-pivot->get_size() / 2).floor());
|
|
|
|
can_move_pivot = true;
|
|
|
|
pivot_found = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
2017-07-11 00:14:22 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *control = Object::cast_to<Control>(canvas_item);
|
2017-07-11 00:14:22 +02:00
|
|
|
if (control) {
|
|
|
|
Vector2 pivot_ofs = control->get_pivot_offset();
|
2017-07-06 22:42:44 +02:00
|
|
|
if (pivot_ofs != Vector2()) {
|
|
|
|
viewport->draw_texture(pivot, xform.xform(pivot_ofs) + (-pivot->get_size() / 2).floor());
|
|
|
|
}
|
|
|
|
can_move_pivot = true;
|
|
|
|
pivot_found = true;
|
2017-07-11 00:14:22 +02:00
|
|
|
|
|
|
|
if (tool == TOOL_SELECT) {
|
2017-07-31 18:49:46 +02:00
|
|
|
float anchors_values[4];
|
|
|
|
anchors_values[0] = control->get_anchor(MARGIN_LEFT);
|
|
|
|
anchors_values[1] = control->get_anchor(MARGIN_TOP);
|
|
|
|
anchors_values[2] = control->get_anchor(MARGIN_RIGHT);
|
|
|
|
anchors_values[3] = control->get_anchor(MARGIN_BOTTOM);
|
|
|
|
|
2017-07-11 00:14:22 +02:00
|
|
|
// Draw the anchors
|
2017-07-30 17:59:57 +02:00
|
|
|
Vector2 anchors[4];
|
|
|
|
Vector2 anchors_pos[4];
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-07-31 18:49:46 +02:00
|
|
|
anchors[i] = Vector2((i % 2 == 0) ? anchors_values[i] : anchors_values[(i + 1) % 4], (i % 2 == 1) ? anchors_values[i] : anchors_values[(i + 1) % 4]);
|
2017-07-30 17:59:57 +02:00
|
|
|
anchors_pos[i] = xform.xform(_anchor_to_position(control, anchors[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get which anchor is dragged
|
|
|
|
int dragged_anchor = -1;
|
|
|
|
switch (drag) {
|
2017-08-04 19:27:30 +02:00
|
|
|
case DRAG_ANCHOR_ALL:
|
2017-07-30 17:59:57 +02:00
|
|
|
case DRAG_ANCHOR_TOP_LEFT:
|
|
|
|
dragged_anchor = 0;
|
|
|
|
break;
|
|
|
|
case DRAG_ANCHOR_TOP_RIGHT:
|
|
|
|
dragged_anchor = 1;
|
|
|
|
break;
|
|
|
|
case DRAG_ANCHOR_BOTTOM_RIGHT:
|
|
|
|
dragged_anchor = 2;
|
|
|
|
break;
|
|
|
|
case DRAG_ANCHOR_BOTTOM_LEFT:
|
|
|
|
dragged_anchor = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dragged_anchor >= 0) {
|
|
|
|
// Draw the 4 lines when dragged
|
2017-07-31 18:49:46 +02:00
|
|
|
bool snapped;
|
2017-07-30 17:59:57 +02:00
|
|
|
Color color_snapped = Color(0.64, 0.93, 0.67, 0.5);
|
|
|
|
Color color_base = Color(0.8, 0.8, 0.8, 0.5);
|
|
|
|
|
|
|
|
Vector2 corners_pos[4];
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
corners_pos[i] = xform.xform(_anchor_to_position(control, Vector2((i == 0 || i == 3) ? ANCHOR_BEGIN : ANCHOR_END, (i <= 1) ? ANCHOR_BEGIN : ANCHOR_END)));
|
|
|
|
}
|
|
|
|
|
2017-08-02 18:33:06 +02:00
|
|
|
Vector2 line_starts[4];
|
|
|
|
Vector2 line_ends[4];
|
2017-07-30 17:59:57 +02:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-07-31 18:49:46 +02:00
|
|
|
float anchor_val = (i >= 2) ? ANCHOR_END - anchors_values[i] : anchors_values[i];
|
2017-08-02 18:33:06 +02:00
|
|
|
line_starts[i] = Vector2::linear_interpolate(corners_pos[i], corners_pos[(i + 1) % 4], anchor_val);
|
|
|
|
line_ends[i] = Vector2::linear_interpolate(corners_pos[(i + 3) % 4], corners_pos[(i + 2) % 4], anchor_val);
|
2017-07-31 18:49:46 +02:00
|
|
|
_anchor_snap(anchors_values[i], &snapped);
|
2017-08-02 18:33:06 +02:00
|
|
|
viewport->draw_line(line_starts[i], line_ends[i], snapped ? color_snapped : color_base, (i == dragged_anchor || (i + 3) % 4 == dragged_anchor) ? 2 : 1);
|
2017-07-30 17:59:57 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 18:33:06 +02:00
|
|
|
// Display the percentages next to the lines
|
|
|
|
float percent_val;
|
|
|
|
percent_val = anchors_values[(dragged_anchor + 2) % 4] - anchors_values[dragged_anchor];
|
|
|
|
percent_val = (dragged_anchor >= 2) ? -percent_val : percent_val;
|
|
|
|
_draw_percentage_at_position(percent_val, (anchors_pos[dragged_anchor] + anchors_pos[(dragged_anchor + 1) % 4]) / 2, (Margin)((dragged_anchor + 1) % 4));
|
|
|
|
|
|
|
|
percent_val = anchors_values[(dragged_anchor + 3) % 4] - anchors_values[(dragged_anchor + 1) % 4];
|
|
|
|
percent_val = ((dragged_anchor + 1) % 4 >= 2) ? -percent_val : percent_val;
|
|
|
|
_draw_percentage_at_position(percent_val, (anchors_pos[dragged_anchor] + anchors_pos[(dragged_anchor + 3) % 4]) / 2, (Margin)(dragged_anchor));
|
|
|
|
|
|
|
|
percent_val = anchors_values[(dragged_anchor + 1) % 4];
|
|
|
|
percent_val = ((dragged_anchor + 1) % 4 >= 2) ? ANCHOR_END - percent_val : percent_val;
|
|
|
|
_draw_percentage_at_position(percent_val, (line_starts[dragged_anchor] + anchors_pos[dragged_anchor]) / 2, (Margin)(dragged_anchor));
|
|
|
|
|
|
|
|
percent_val = anchors_values[dragged_anchor];
|
|
|
|
percent_val = (dragged_anchor >= 2) ? ANCHOR_END - percent_val : percent_val;
|
|
|
|
_draw_percentage_at_position(percent_val, (line_ends[(dragged_anchor + 1) % 4] + anchors_pos[dragged_anchor]) / 2, (Margin)((dragged_anchor + 1) % 4));
|
2017-07-30 17:59:57 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 00:14:22 +02:00
|
|
|
Rect2 anchor_rects[4];
|
2017-07-30 17:59:57 +02:00
|
|
|
anchor_rects[0] = Rect2(anchors_pos[0] - anchor_handle->get_size(), anchor_handle->get_size());
|
|
|
|
anchor_rects[1] = Rect2(anchors_pos[1] - Vector2(0.0, anchor_handle->get_size().y), Point2(-anchor_handle->get_size().x, anchor_handle->get_size().y));
|
|
|
|
anchor_rects[2] = Rect2(anchors_pos[2], -anchor_handle->get_size());
|
|
|
|
anchor_rects[3] = Rect2(anchors_pos[3] - Vector2(anchor_handle->get_size().x, 0.0), Point2(anchor_handle->get_size().x, -anchor_handle->get_size().y));
|
2017-07-11 00:14:22 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
anchor_handle->draw_rect(ci, anchor_rects[i]);
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 22:42:44 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tool == TOOL_SELECT) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int prev = (i + 3) % 4;
|
|
|
|
int next = (i + 1) % 4;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized();
|
2017-03-05 16:44:50 +01:00
|
|
|
ofs *= 1.4144 * (select_handle->get_size().width / 2);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
select_handle->draw(ci, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ofs = (endpoints[i] + endpoints[next]) / 2;
|
|
|
|
ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
select_handle->draw(ci, (ofs - (select_handle->get_size() / 2)).floor());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//DRAW_EMPTY_RECT( Rect2( current_window->get_scroll()-Point2(1,1), get_size()+Size2(2,2)), Color(0.8,0.8,1.0,0.8) );
|
|
|
|
//E->get().last_rect = rect;
|
|
|
|
}
|
|
|
|
|
2015-12-28 13:38:15 +01:00
|
|
|
pivot_button->set_disabled(!pivot_found);
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_set_transform(ci, Transform2D());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Color x_axis_color(1.0, 0.4, 0.4, 0.6);
|
|
|
|
Color y_axis_color(0.4, 1.0, 0.4, 0.6);
|
|
|
|
Color area_axis_color(0.4, 0.4, 1.0, 0.4);
|
|
|
|
Color rotate_color(0.4, 0.7, 1.0, 0.8);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(h_scroll->get_min(), 0) + transform.get_origin(), Point2(h_scroll->get_max(), 0) + transform.get_origin(), x_axis_color);
|
|
|
|
VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(0, v_scroll->get_min()) + transform.get_origin(), Point2(0, v_scroll->get_max()) + transform.get_origin(), y_axis_color);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (box_selecting) {
|
|
|
|
|
|
|
|
Point2 bsfrom = transform.xform(drag_from);
|
2017-03-05 16:44:50 +01:00
|
|
|
Point2 bsto = transform.xform(box_selecting_to);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(bsfrom, bsto - bsfrom), Color(0.7, 0.7, 1.0, 0.3));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (drag == DRAG_ROTATE) {
|
|
|
|
VisualServer::get_singleton()->canvas_item_add_line(ci, transform.xform(display_rotate_from), transform.xform(display_rotate_to), rotate_color);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
Size2 screen_size = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 screen_endpoints[4] = {
|
|
|
|
transform.xform(Vector2(0, 0)),
|
|
|
|
transform.xform(Vector2(screen_size.width, 0)),
|
|
|
|
transform.xform(Vector2(screen_size.width, screen_size.height)),
|
|
|
|
transform.xform(Vector2(0, screen_size.height))
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_line(ci, screen_endpoints[i], screen_endpoints[(i + 1) % 4], area_axis_color);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<LockList>::Element *E = lock_list.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector2 ofs = transform.xform(E->get().pos);
|
|
|
|
if (E->get().lock) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
lock->draw(ci, ofs);
|
|
|
|
ofs.x += lock->get_width();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
if (E->get().group) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
group->draw(ci, ofs);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-10 21:44:03 +02:00
|
|
|
{
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
EditorNode *en = editor;
|
|
|
|
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
|
2016-09-10 21:44:03 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!over_plugin_list->empty()) {
|
2016-09-10 21:44:03 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
over_plugin_list->forward_draw_over_canvas(transform, viewport);
|
|
|
|
}
|
|
|
|
}
|
2016-09-10 21:44:03 +02:00
|
|
|
|
2016-09-07 11:10:00 +02:00
|
|
|
if (skeleton_show_bones) {
|
2017-01-15 02:20:05 +01:00
|
|
|
int bone_width = EditorSettings::get_singleton()->get("editors/2d/bone_width");
|
|
|
|
Color bone_color1 = EditorSettings::get_singleton()->get("editors/2d/bone_color1");
|
|
|
|
Color bone_color2 = EditorSettings::get_singleton()->get("editors/2d/bone_color2");
|
|
|
|
Color bone_ik_color = EditorSettings::get_singleton()->get("editors/2d/bone_ik_color");
|
|
|
|
Color bone_selected_color = EditorSettings::get_singleton()->get("editors/2d/bone_selected_color");
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<ObjectID, BoneList>::Element *E = bone_list.front(); E; E = E->next()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
E->get().from = Vector2();
|
|
|
|
E->get().to = Vector2();
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E->get().bone));
|
2016-09-07 11:10:00 +02:00
|
|
|
if (!n2d)
|
|
|
|
continue;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2016-09-07 11:10:00 +02:00
|
|
|
if (!n2d->get_parent())
|
|
|
|
continue;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2016-09-07 11:10:00 +02:00
|
|
|
CanvasItem *pi = n2d->get_parent_item();
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *pn2d = Object::cast_to<Node2D>(n2d->get_parent());
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2016-09-07 11:10:00 +02:00
|
|
|
if (!pn2d)
|
|
|
|
continue;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-01-04 05:16:14 +01:00
|
|
|
Vector2 from = transform.xform(pn2d->get_global_position());
|
|
|
|
Vector2 to = transform.xform(n2d->get_global_position());
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
E->get().from = from;
|
|
|
|
E->get().to = to;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 rel = to - from;
|
|
|
|
Vector2 relt = rel.tangent().normalized() * bone_width;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2016-09-07 11:10:00 +02:00
|
|
|
Vector<Vector2> bone_shape;
|
|
|
|
bone_shape.push_back(from);
|
2017-03-05 16:44:50 +01:00
|
|
|
bone_shape.push_back(from + rel * 0.2 + relt);
|
2016-09-07 11:10:00 +02:00
|
|
|
bone_shape.push_back(to);
|
2017-03-05 16:44:50 +01:00
|
|
|
bone_shape.push_back(from + rel * 0.2 - relt);
|
2016-09-07 11:10:00 +02:00
|
|
|
Vector<Color> colors;
|
|
|
|
if (pi->has_meta("_edit_ik_")) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2016-09-07 11:10:00 +02:00
|
|
|
colors.push_back(bone_ik_color);
|
|
|
|
colors.push_back(bone_ik_color);
|
|
|
|
colors.push_back(bone_ik_color);
|
|
|
|
colors.push_back(bone_ik_color);
|
|
|
|
} else {
|
|
|
|
colors.push_back(bone_color1);
|
|
|
|
colors.push_back(bone_color2);
|
|
|
|
colors.push_back(bone_color1);
|
|
|
|
colors.push_back(bone_color2);
|
|
|
|
}
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_primitive(ci, bone_shape, colors, Vector<Vector2>(), RID());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-09-07 11:10:00 +02:00
|
|
|
if (editor_selection->is_selected(pi)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < bone_shape.size(); i++) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_line(ci, bone_shape[i], bone_shape[(i + 1) % bone_shape.size()], bone_selected_color, 2);
|
2016-09-07 11:10:00 +02:00
|
|
|
}
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
2016-09-07 11:10:00 +02:00
|
|
|
}
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditor::_notification(int p_what) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_what == NOTIFICATION_FIXED_PROCESS) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool all_control = true;
|
|
|
|
bool has_control = false;
|
2015-08-24 06:00:39 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Control>(canvas_item))
|
2017-03-05 16:44:50 +01:00
|
|
|
has_control = true;
|
2015-08-24 06:00:39 +02:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
all_control = false;
|
2015-08-24 06:00:39 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!se)
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Rect2 r = canvas_item->get_item_rect();
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D xform = canvas_item->get_transform();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-11 00:14:22 +02:00
|
|
|
float anchors[4];
|
2017-07-06 22:42:44 +02:00
|
|
|
Vector2 pivot;
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Control>(canvas_item)) {
|
|
|
|
pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
|
|
|
|
anchors[MARGIN_LEFT] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_LEFT);
|
|
|
|
anchors[MARGIN_RIGHT] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_RIGHT);
|
|
|
|
anchors[MARGIN_TOP] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_TOP);
|
|
|
|
anchors[MARGIN_BOTTOM] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_BOTTOM);
|
2017-07-06 22:42:44 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 00:14:22 +02:00
|
|
|
if (r != se->prev_rect || xform != se->prev_xform || pivot != se->prev_pivot || anchors[MARGIN_LEFT] != se->prev_anchors[MARGIN_LEFT] || anchors[MARGIN_RIGHT] != se->prev_anchors[MARGIN_RIGHT] || anchors[MARGIN_TOP] != se->prev_anchors[MARGIN_TOP] || anchors[MARGIN_BOTTOM] != se->prev_anchors[MARGIN_BOTTOM]) {
|
2014-02-10 02:10:30 +01:00
|
|
|
viewport->update();
|
2017-03-05 16:44:50 +01:00
|
|
|
se->prev_rect = r;
|
|
|
|
se->prev_xform = xform;
|
2017-07-06 22:42:44 +02:00
|
|
|
se->prev_pivot = pivot;
|
2017-07-11 00:14:22 +02:00
|
|
|
se->prev_anchors[MARGIN_LEFT] = anchors[MARGIN_LEFT];
|
|
|
|
se->prev_anchors[MARGIN_RIGHT] = anchors[MARGIN_RIGHT];
|
|
|
|
se->prev_anchors[MARGIN_TOP] = anchors[MARGIN_TOP];
|
|
|
|
se->prev_anchors[MARGIN_BOTTOM] = anchors[MARGIN_BOTTOM];
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-12 13:23:08 +02:00
|
|
|
if (all_control && has_control)
|
|
|
|
anchor_menu->show();
|
|
|
|
else
|
|
|
|
anchor_menu->hide();
|
2015-04-21 00:38:02 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<ObjectID, BoneList>::Element *E = bone_list.front(); E; E = E->next()) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
|
|
|
Object *b = ObjectDB::get_instance(E->get().bone);
|
|
|
|
if (!b) {
|
2015-04-21 00:38:02 +02:00
|
|
|
|
2014-07-07 22:44:21 +02:00
|
|
|
viewport->update();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *b2 = Object::cast_to<Node2D>(b);
|
2014-07-07 22:44:21 +02:00
|
|
|
if (!b2) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (b2->get_global_transform() != E->get().xform) {
|
2014-07-07 22:44:21 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
E->get().xform = b2->get_global_transform();
|
2014-07-07 22:44:21 +02:00
|
|
|
viewport->update();
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
select_sb->set_texture(get_icon("EditorRect2D", "EditorIcons"));
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
select_sb->set_margin_size(Margin(i), 4);
|
|
|
|
select_sb->set_default_margin(Margin(i), 4);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
select_button->set_icon(get_icon("ToolSelect", "EditorIcons"));
|
|
|
|
list_select_button->set_icon(get_icon("ListSelect", "EditorIcons"));
|
|
|
|
move_button->set_icon(get_icon("ToolMove", "EditorIcons"));
|
|
|
|
rotate_button->set_icon(get_icon("ToolRotate", "EditorIcons"));
|
|
|
|
pan_button->set_icon(get_icon("ToolPan", "EditorIcons"));
|
|
|
|
pivot_button->set_icon(get_icon("EditPivot", "EditorIcons"));
|
|
|
|
select_handle = get_icon("EditorHandle", "EditorIcons");
|
2017-07-11 00:14:22 +02:00
|
|
|
anchor_handle = get_icon("EditorControlAnchor", "EditorIcons");
|
2017-03-05 16:44:50 +01:00
|
|
|
lock_button->set_icon(get_icon("Lock", "EditorIcons"));
|
|
|
|
unlock_button->set_icon(get_icon("Unlock", "EditorIcons"));
|
|
|
|
group_button->set_icon(get_icon("Group", "EditorIcons"));
|
|
|
|
ungroup_button->set_icon(get_icon("Ungroup", "EditorIcons"));
|
|
|
|
key_insert_button->set_icon(get_icon("Key", "EditorIcons"));
|
2015-08-24 06:00:39 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
anchor_menu->set_icon(get_icon("Anchor", "EditorIcons"));
|
|
|
|
PopupMenu *p = anchor_menu->get_popup();
|
2015-08-24 06:00:39 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
p->add_icon_item(get_icon("ControlAlignTopLeft", "EditorIcons"), "Top Left", ANCHOR_ALIGN_TOP_LEFT);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignTopRight", "EditorIcons"), "Top Right", ANCHOR_ALIGN_TOP_RIGHT);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignBottomRight", "EditorIcons"), "Bottom Right", ANCHOR_ALIGN_BOTTOM_RIGHT);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignBottomLeft", "EditorIcons"), "Bottom Left", ANCHOR_ALIGN_BOTTOM_LEFT);
|
2015-08-24 06:00:39 +02:00
|
|
|
p->add_separator();
|
2017-03-05 16:44:50 +01:00
|
|
|
p->add_icon_item(get_icon("ControlAlignLeftCenter", "EditorIcons"), "Center Left", ANCHOR_ALIGN_CENTER_LEFT);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignTopCenter", "EditorIcons"), "Center Top", ANCHOR_ALIGN_CENTER_TOP);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignRightCenter", "EditorIcons"), "Center Right", ANCHOR_ALIGN_CENTER_RIGHT);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignBottomCenter", "EditorIcons"), "Center Bottom", ANCHOR_ALIGN_CENTER_BOTTOM);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignCenter", "EditorIcons"), "Center", ANCHOR_ALIGN_CENTER);
|
2015-08-24 06:00:39 +02:00
|
|
|
p->add_separator();
|
2017-03-05 16:44:50 +01:00
|
|
|
p->add_icon_item(get_icon("ControlAlignLeftWide", "EditorIcons"), "Left Wide", ANCHOR_ALIGN_LEFT_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignTopWide", "EditorIcons"), "Top Wide", ANCHOR_ALIGN_TOP_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignRightWide", "EditorIcons"), "Right Wide", ANCHOR_ALIGN_RIGHT_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignBottomWide", "EditorIcons"), "Bottom Wide", ANCHOR_ALIGN_BOTTOM_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlVcenterWide", "EditorIcons"), "VCenter Wide ", ANCHOR_ALIGN_VCENTER_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlHcenterWide", "EditorIcons"), "HCenter Wide ", ANCHOR_ALIGN_HCENTER_WIDE);
|
2015-08-24 06:00:39 +02:00
|
|
|
p->add_separator();
|
2017-03-05 16:44:50 +01:00
|
|
|
p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect", ANCHOR_ALIGN_WIDE);
|
2017-07-09 15:54:49 +02:00
|
|
|
p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect and Fit Parent", ANCHOR_ALIGN_WIDE_FIT);
|
2015-08-24 06:00:39 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->connect("visibility_changed", this, "_keying_changed");
|
2016-02-09 20:09:29 +01:00
|
|
|
_keying_changed();
|
2017-08-30 01:03:13 +02:00
|
|
|
} else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
|
|
|
|
|
|
|
|
select_sb->set_texture(get_icon("EditorRect2D", "EditorIcons"));
|
|
|
|
|
|
|
|
select_button->set_icon(get_icon("ToolSelect", "EditorIcons"));
|
|
|
|
list_select_button->set_icon(get_icon("ListSelect", "EditorIcons"));
|
|
|
|
move_button->set_icon(get_icon("ToolMove", "EditorIcons"));
|
|
|
|
rotate_button->set_icon(get_icon("ToolRotate", "EditorIcons"));
|
|
|
|
pan_button->set_icon(get_icon("ToolPan", "EditorIcons"));
|
|
|
|
pivot_button->set_icon(get_icon("EditPivot", "EditorIcons"));
|
|
|
|
select_handle = get_icon("EditorHandle", "EditorIcons");
|
|
|
|
anchor_handle = get_icon("EditorControlAnchor", "EditorIcons");
|
|
|
|
lock_button->set_icon(get_icon("Lock", "EditorIcons"));
|
|
|
|
unlock_button->set_icon(get_icon("Unlock", "EditorIcons"));
|
|
|
|
group_button->set_icon(get_icon("Group", "EditorIcons"));
|
|
|
|
ungroup_button->set_icon(get_icon("Ungroup", "EditorIcons"));
|
|
|
|
key_insert_button->set_icon(get_icon("Key", "EditorIcons"));
|
|
|
|
|
|
|
|
anchor_menu->set_icon(get_icon("Anchor", "EditorIcons"));
|
|
|
|
PopupMenu *p = anchor_menu->get_popup();
|
|
|
|
p->clear();
|
|
|
|
|
|
|
|
p->add_icon_item(get_icon("ControlAlignTopLeft", "EditorIcons"), "Top Left", ANCHOR_ALIGN_TOP_LEFT);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignTopRight", "EditorIcons"), "Top Right", ANCHOR_ALIGN_TOP_RIGHT);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignBottomRight", "EditorIcons"), "Bottom Right", ANCHOR_ALIGN_BOTTOM_RIGHT);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignBottomLeft", "EditorIcons"), "Bottom Left", ANCHOR_ALIGN_BOTTOM_LEFT);
|
|
|
|
p->add_separator();
|
|
|
|
p->add_icon_item(get_icon("ControlAlignLeftCenter", "EditorIcons"), "Center Left", ANCHOR_ALIGN_CENTER_LEFT);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignTopCenter", "EditorIcons"), "Center Top", ANCHOR_ALIGN_CENTER_TOP);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignRightCenter", "EditorIcons"), "Center Right", ANCHOR_ALIGN_CENTER_RIGHT);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignBottomCenter", "EditorIcons"), "Center Bottom", ANCHOR_ALIGN_CENTER_BOTTOM);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignCenter", "EditorIcons"), "Center", ANCHOR_ALIGN_CENTER);
|
|
|
|
p->add_separator();
|
|
|
|
p->add_icon_item(get_icon("ControlAlignLeftWide", "EditorIcons"), "Left Wide", ANCHOR_ALIGN_LEFT_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignTopWide", "EditorIcons"), "Top Wide", ANCHOR_ALIGN_TOP_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignRightWide", "EditorIcons"), "Right Wide", ANCHOR_ALIGN_RIGHT_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignBottomWide", "EditorIcons"), "Bottom Wide", ANCHOR_ALIGN_BOTTOM_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlVcenterWide", "EditorIcons"), "VCenter Wide ", ANCHOR_ALIGN_VCENTER_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlHcenterWide", "EditorIcons"), "HCenter Wide ", ANCHOR_ALIGN_HCENTER_WIDE);
|
|
|
|
p->add_separator();
|
|
|
|
p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect", ANCHOR_ALIGN_WIDE);
|
|
|
|
p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect and Fit Parent", ANCHOR_ALIGN_WIDE_FIT);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditor::edit(CanvasItem *p_canvas_item) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
drag = DRAG_NONE;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
editor_selection->clear(); //_clear_canvas_items();
|
2014-02-10 02:10:30 +01:00
|
|
|
editor_selection->add_node(p_canvas_item);
|
|
|
|
//_add_canvas_item(p_canvas_item);
|
|
|
|
viewport->update();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditor::_find_canvas_items_span(Node *p_node, Rect2 &r_rect, const Transform2D &p_xform) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (!p_node)
|
|
|
|
return;
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *c = Object::cast_to<CanvasItem>(p_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
//CanvasItem *r=NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (c && !c->is_set_as_toplevel())
|
2017-03-05 16:44:50 +01:00
|
|
|
_find_canvas_items_span(p_node->get_child(i), r_rect, p_xform * c->get_transform());
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
_find_canvas_items_span(p_node->get_child(i), r_rect, Transform2D());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-19 17:10:47 +01:00
|
|
|
if (c && c->is_visible_in_tree()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Rect2 rect = c->get_item_rect();
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D xform = p_xform * c->get_transform();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
LockList lock;
|
2017-03-05 16:44:50 +01:00
|
|
|
lock.lock = c->has_meta("_edit_lock_");
|
|
|
|
lock.group = c->has_meta("_edit_group_");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (lock.group || lock.lock) {
|
2017-06-04 00:25:13 +02:00
|
|
|
lock.pos = xform.xform(rect.position);
|
2014-02-10 02:10:30 +01:00
|
|
|
lock_list.push_back(lock);
|
|
|
|
}
|
|
|
|
|
2014-07-06 16:49:27 +02:00
|
|
|
if (c->has_meta("_edit_bone_")) {
|
|
|
|
|
2017-08-07 12:17:31 +02:00
|
|
|
ObjectID id = c->get_instance_id();
|
2015-04-21 00:38:02 +02:00
|
|
|
if (!bone_list.has(id)) {
|
|
|
|
BoneList bone;
|
2017-03-05 16:44:50 +01:00
|
|
|
bone.bone = id;
|
|
|
|
bone_list[id] = bone;
|
2015-04-21 00:38:02 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bone_list[id].last_pass = bone_last_frame;
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
r_rect.expand_to(xform.xform(rect.position));
|
|
|
|
r_rect.expand_to(xform.xform(rect.position + Point2(rect.size.x, 0)));
|
|
|
|
r_rect.expand_to(xform.xform(rect.position + Point2(0, rect.size.y)));
|
|
|
|
r_rect.expand_to(xform.xform(rect.position + rect.size));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditor::_update_scrollbars() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_scroll = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Size2 size = viewport->get_size();
|
|
|
|
Size2 hmin = h_scroll->get_minimum_size();
|
|
|
|
Size2 vmin = v_scroll->get_minimum_size();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
v_scroll->set_begin(Point2(size.width - vmin.width, 0));
|
|
|
|
v_scroll->set_end(Point2(size.width, size.height));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
h_scroll->set_begin(Point2(0, size.height - hmin.height));
|
|
|
|
h_scroll->set_end(Point2(size.width - vmin.width, size.height));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
Size2 screen_rect = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height"));
|
2017-01-15 01:56:22 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Rect2 local_rect = Rect2(Point2(), viewport->get_size() - Size2(vmin.width, hmin.height));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Rect2 canvas_item_rect = Rect2(Point2(), screen_rect);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 18:03:38 +01:00
|
|
|
lock_list.clear();
|
2015-04-21 00:38:02 +02:00
|
|
|
bone_last_frame++;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (editor->get_edited_scene())
|
2017-03-05 16:44:50 +01:00
|
|
|
_find_canvas_items_span(editor->get_edited_scene(), canvas_item_rect, Transform2D());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Map<ObjectID, BoneList>::Element *> bone_to_erase;
|
2015-04-21 00:38:02 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<ObjectID, BoneList>::Element *E = bone_list.front(); E; E = E->next()) {
|
2015-04-21 00:38:02 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (E->get().last_pass != bone_last_frame) {
|
2015-04-21 00:38:02 +02:00
|
|
|
bone_to_erase.push_back(E);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (bone_to_erase.size()) {
|
2015-04-21 00:38:02 +02:00
|
|
|
bone_list.erase(bone_to_erase.front()->get());
|
|
|
|
bone_to_erase.pop_front();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//expand area so it's easier to do animations and stuff at 0,0
|
2017-03-05 16:44:50 +01:00
|
|
|
canvas_item_rect.size += screen_rect * 2;
|
2017-06-04 00:25:13 +02:00
|
|
|
canvas_item_rect.position -= screen_rect;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Point2 ofs;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item_rect.size.height <= (local_rect.size.y / zoom)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
v_scroll->hide();
|
2017-06-04 00:25:13 +02:00
|
|
|
ofs.y = canvas_item_rect.position.y;
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
v_scroll->show();
|
2017-06-04 00:25:13 +02:00
|
|
|
v_scroll->set_min(canvas_item_rect.position.y);
|
|
|
|
v_scroll->set_max(canvas_item_rect.position.y + canvas_item_rect.size.y);
|
2017-03-05 16:44:50 +01:00
|
|
|
v_scroll->set_page(local_rect.size.y / zoom);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (first_update) {
|
|
|
|
//so 0,0 is visible
|
2017-01-04 05:16:14 +01:00
|
|
|
v_scroll->set_value(-10);
|
|
|
|
h_scroll->set_value(-10);
|
2017-03-05 16:44:50 +01:00
|
|
|
first_update = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ofs.y = v_scroll->get_value();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item_rect.size.width <= (local_rect.size.x / zoom)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
h_scroll->hide();
|
2017-06-04 00:25:13 +02:00
|
|
|
ofs.x = canvas_item_rect.position.x;
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
h_scroll->show();
|
2017-06-04 00:25:13 +02:00
|
|
|
h_scroll->set_min(canvas_item_rect.position.x);
|
|
|
|
h_scroll->set_max(canvas_item_rect.position.x + canvas_item_rect.size.x);
|
2017-03-05 16:44:50 +01:00
|
|
|
h_scroll->set_page(local_rect.size.x / zoom);
|
|
|
|
ofs.x = h_scroll->get_value();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
//transform=Matrix32();
|
2017-03-05 16:44:50 +01:00
|
|
|
transform.elements[2] = -ofs * zoom;
|
2017-01-15 01:56:22 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
editor->get_scene_root()->set_global_canvas_transform(transform);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_scroll = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
//transform.scale_basis(Vector2(zoom,zoom));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditor::_update_scroll(float) {
|
|
|
|
|
|
|
|
if (updating_scroll)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Point2 ofs;
|
2017-03-05 16:44:50 +01:00
|
|
|
ofs.x = h_scroll->get_value();
|
|
|
|
ofs.y = v_scroll->get_value();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
//current_window->set_scroll(-ofs);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
transform = Transform2D();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
transform.scale_basis(Size2(zoom, zoom));
|
|
|
|
transform.elements[2] = -ofs;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
editor->get_scene_root()->set_global_canvas_transform(transform);
|
|
|
|
|
|
|
|
viewport->update();
|
|
|
|
}
|
|
|
|
|
2017-08-11 18:16:28 +02:00
|
|
|
void CanvasItemEditor::_set_anchors_preset(Control::LayoutPreset p_preset) {
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2015-08-24 06:00:39 +02:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Change Anchors"));
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2015-08-24 06:00:39 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *c = Object::cast_to<Control>(E->get());
|
2015-08-24 06:00:39 +02:00
|
|
|
|
2017-08-11 18:16:28 +02:00
|
|
|
undo_redo->add_do_method(c, "set_anchors_preset", p_preset);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_undo_method(c, "set_anchor", MARGIN_LEFT, c->get_anchor(MARGIN_LEFT));
|
|
|
|
undo_redo->add_undo_method(c, "set_anchor", MARGIN_TOP, c->get_anchor(MARGIN_TOP));
|
|
|
|
undo_redo->add_undo_method(c, "set_anchor", MARGIN_RIGHT, c->get_anchor(MARGIN_RIGHT));
|
|
|
|
undo_redo->add_undo_method(c, "set_anchor", MARGIN_BOTTOM, c->get_anchor(MARGIN_BOTTOM));
|
2015-08-24 06:00:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-09 15:54:49 +02:00
|
|
|
void CanvasItemEditor::_set_full_rect() {
|
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Change Anchors"));
|
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *c = Object::cast_to<Control>(E->get());
|
2017-07-09 15:54:49 +02:00
|
|
|
|
2017-08-11 18:16:28 +02:00
|
|
|
undo_redo->add_do_method(c, "set_anchors_preset", PRESET_WIDE);
|
2017-07-09 15:54:49 +02:00
|
|
|
undo_redo->add_do_method(c, "set_margin", MARGIN_LEFT, 0);
|
|
|
|
undo_redo->add_do_method(c, "set_margin", MARGIN_TOP, 0);
|
|
|
|
undo_redo->add_do_method(c, "set_margin", MARGIN_RIGHT, 0);
|
|
|
|
undo_redo->add_do_method(c, "set_margin", MARGIN_BOTTOM, 0);
|
|
|
|
undo_redo->add_undo_method(c, "set_anchor", MARGIN_LEFT, c->get_anchor(MARGIN_LEFT));
|
|
|
|
undo_redo->add_undo_method(c, "set_anchor", MARGIN_TOP, c->get_anchor(MARGIN_TOP));
|
|
|
|
undo_redo->add_undo_method(c, "set_anchor", MARGIN_RIGHT, c->get_anchor(MARGIN_RIGHT));
|
|
|
|
undo_redo->add_undo_method(c, "set_anchor", MARGIN_BOTTOM, c->get_anchor(MARGIN_BOTTOM));
|
|
|
|
undo_redo->add_undo_method(c, "set_margin", MARGIN_LEFT, c->get_margin(MARGIN_LEFT));
|
|
|
|
undo_redo->add_undo_method(c, "set_margin", MARGIN_TOP, c->get_margin(MARGIN_TOP));
|
|
|
|
undo_redo->add_undo_method(c, "set_margin", MARGIN_RIGHT, c->get_margin(MARGIN_RIGHT));
|
|
|
|
undo_redo->add_undo_method(c, "set_margin", MARGIN_BOTTOM, c->get_margin(MARGIN_BOTTOM));
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void CanvasItemEditor::_popup_callback(int p_op) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
last_option = MenuOption(p_op);
|
|
|
|
switch (p_op) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
case SNAP_USE: {
|
2015-02-15 09:00:55 +01:00
|
|
|
snap_grid = !snap_grid;
|
2014-02-10 02:10:30 +01:00
|
|
|
int idx = edit_menu->get_popup()->get_item_index(SNAP_USE);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->set_item_checked(idx, snap_grid);
|
2017-07-25 21:09:32 +02:00
|
|
|
viewport->update();
|
2015-02-15 09:00:55 +01:00
|
|
|
} break;
|
|
|
|
case SNAP_SHOW_GRID: {
|
|
|
|
snap_show_grid = !snap_show_grid;
|
|
|
|
int idx = edit_menu->get_popup()->get_item_index(SNAP_SHOW_GRID);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->set_item_checked(idx, snap_show_grid);
|
2014-02-10 02:10:30 +01:00
|
|
|
viewport->update();
|
|
|
|
} break;
|
2015-02-15 09:00:55 +01:00
|
|
|
case SNAP_USE_ROTATION: {
|
|
|
|
snap_rotation = !snap_rotation;
|
|
|
|
int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_ROTATION);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->set_item_checked(idx, snap_rotation);
|
2015-02-15 09:00:55 +01:00
|
|
|
} break;
|
2015-02-20 13:21:59 +01:00
|
|
|
case SNAP_RELATIVE: {
|
|
|
|
snap_relative = !snap_relative;
|
|
|
|
int idx = edit_menu->get_popup()->get_item_index(SNAP_RELATIVE);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->set_item_checked(idx, snap_relative);
|
2017-07-25 21:09:32 +02:00
|
|
|
viewport->update();
|
2015-02-15 09:00:55 +01:00
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
case SNAP_USE_PIXEL: {
|
2015-02-15 09:00:55 +01:00
|
|
|
snap_pixel = !snap_pixel;
|
2014-02-10 02:10:30 +01:00
|
|
|
int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_PIXEL);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->set_item_checked(idx, snap_pixel);
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case SNAP_CONFIGURE: {
|
2015-02-15 09:00:55 +01:00
|
|
|
((SnapDialog *)snap_dialog)->set_fields(snap_offset, snap_step, snap_rotation_offset, snap_rotation_step);
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_dialog->popup_centered(Size2(220, 160));
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2016-09-07 11:10:00 +02:00
|
|
|
case SKELETON_SHOW_BONES: {
|
|
|
|
skeleton_show_bones = !skeleton_show_bones;
|
|
|
|
int idx = skeleton_menu->get_item_index(SKELETON_SHOW_BONES);
|
2017-03-05 16:44:50 +01:00
|
|
|
skeleton_menu->set_item_checked(idx, skeleton_show_bones);
|
2016-09-07 11:10:00 +02:00
|
|
|
viewport->update();
|
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
case ZOOM_IN: {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (zoom > MAX_ZOOM)
|
2016-07-21 15:06:38 +02:00
|
|
|
return;
|
2017-03-05 16:44:50 +01:00
|
|
|
zoom = zoom * (1.0 / 0.5);
|
2014-02-10 02:10:30 +01:00
|
|
|
_update_scroll(0);
|
|
|
|
viewport->update();
|
|
|
|
return;
|
|
|
|
} break;
|
|
|
|
case ZOOM_OUT: {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (zoom < MIN_ZOOM)
|
2016-07-21 15:06:38 +02:00
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
zoom = zoom * 0.5;
|
2014-02-10 02:10:30 +01:00
|
|
|
_update_scroll(0);
|
|
|
|
viewport->update();
|
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ZOOM_RESET: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
zoom = 1;
|
2014-02-10 02:10:30 +01:00
|
|
|
_update_scroll(0);
|
|
|
|
viewport->update();
|
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ZOOM_SET: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_value_dialog = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
dialog_label->set_text(TTR("Zoom (%):"));
|
2014-02-10 02:10:30 +01:00
|
|
|
dialog_val->set_min(0.1);
|
|
|
|
dialog_val->set_step(0.1);
|
|
|
|
dialog_val->set_max(800);
|
2017-03-05 16:44:50 +01:00
|
|
|
dialog_val->set_value(zoom * 100);
|
|
|
|
value_dialog->popup_centered(Size2(200, 85));
|
|
|
|
updating_value_dialog = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case LOCK_SELECTED: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
canvas_item->set_meta("_edit_lock_", true);
|
2014-05-08 07:43:19 +02:00
|
|
|
emit_signal("item_lock_status_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
viewport->update();
|
|
|
|
} break;
|
|
|
|
case UNLOCK_SELECTED: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
canvas_item->set_meta("_edit_lock_", Variant());
|
2014-05-08 07:43:19 +02:00
|
|
|
emit_signal("item_lock_status_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
viewport->update();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case GROUP_SELECTED: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
canvas_item->set_meta("_edit_group_", true);
|
2014-05-08 07:43:19 +02:00
|
|
|
emit_signal("item_group_status_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
viewport->update();
|
|
|
|
} break;
|
|
|
|
case UNGROUP_SELECTED: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
canvas_item->set_meta("_edit_group_", Variant());
|
2014-05-08 07:43:19 +02:00
|
|
|
emit_signal("item_group_status_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
viewport->update();
|
|
|
|
|
|
|
|
} break;
|
2015-08-24 06:00:39 +02:00
|
|
|
case ANCHOR_ALIGN_TOP_LEFT: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_TOP_LEFT);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_TOP_RIGHT: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_TOP_RIGHT);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_BOTTOM_LEFT: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_BOTTOM_LEFT);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_BOTTOM_RIGHT: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_BOTTOM_RIGHT);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_CENTER_LEFT: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_CENTER_LEFT);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_CENTER_RIGHT: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_CENTER_RIGHT);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_CENTER_TOP: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_CENTER_TOP);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_CENTER_BOTTOM: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_CENTER_BOTTOM);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_CENTER: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_CENTER);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_TOP_WIDE: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_TOP_WIDE);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_LEFT_WIDE: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_LEFT_WIDE);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_RIGHT_WIDE: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_RIGHT_WIDE);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_BOTTOM_WIDE: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_BOTTOM_WIDE);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_VCENTER_WIDE: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_VCENTER_WIDE);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_HCENTER_WIDE: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_HCENTER_WIDE);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
|
|
|
case ANCHOR_ALIGN_WIDE: {
|
2017-08-11 18:16:28 +02:00
|
|
|
_set_anchors_preset(PRESET_WIDE);
|
2015-08-24 06:00:39 +02:00
|
|
|
} break;
|
2017-07-09 15:54:49 +02:00
|
|
|
case ANCHOR_ALIGN_WIDE_FIT: {
|
|
|
|
_set_full_rect();
|
|
|
|
} break;
|
2015-08-24 06:00:39 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
case ANIM_INSERT_KEY:
|
|
|
|
case ANIM_INSERT_KEY_EXISTING: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool existing = p_op == ANIM_INSERT_KEY_EXISTING;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<Node *, Object *> &selection = editor_selection->get_selection();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item)) {
|
|
|
|
Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (key_pos)
|
2017-06-24 11:39:57 +02:00
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "position", n2d->get_position(), existing);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (key_rot)
|
2017-06-24 11:39:57 +02:00
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "rotation_deg", Math::rad2deg(n2d->get_rotation()), existing);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (key_scale)
|
2017-06-24 11:39:57 +02:00
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "scale", n2d->get_scale(), existing);
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
if (n2d->has_meta("_edit_bone_") && n2d->get_parent_item()) {
|
|
|
|
//look for an IK chain
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node2D *> ik_chain;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *n = Object::cast_to<Node2D>(n2d->get_parent_item());
|
2017-03-05 16:44:50 +01:00
|
|
|
bool has_chain = false;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (n) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
ik_chain.push_back(n);
|
|
|
|
if (n->has_meta("_edit_ik_")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
has_chain = true;
|
2014-07-06 16:49:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!n->get_parent_item())
|
|
|
|
break;
|
2017-08-24 22:58:51 +02:00
|
|
|
n = Object::cast_to<Node2D>(n->get_parent_item());
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (has_chain && ik_chain.size()) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node2D *>::Element *F = ik_chain.front(); F; F = F->next()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
if (key_pos)
|
2017-06-24 11:39:57 +02:00
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(), "position", F->get()->get_position(), existing);
|
2014-07-06 16:49:27 +02:00
|
|
|
if (key_rot)
|
2017-06-24 11:39:57 +02:00
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(), "rotation_deg", Math::rad2deg(F->get()->get_rotation()), existing);
|
2014-07-06 16:49:27 +02:00
|
|
|
if (key_scale)
|
2017-06-24 11:39:57 +02:00
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(), "scale", F->get()->get_scale(), existing);
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
} else if (Object::cast_to<Control>(canvas_item)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *ctrl = Object::cast_to<Control>(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (key_pos)
|
2017-06-24 11:39:57 +02:00
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl, "rect_position", ctrl->get_position(), existing);
|
|
|
|
if (key_rot)
|
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl, "rect_rotation", ctrl->get_rotation_deg(), existing);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (key_scale)
|
2017-06-24 11:39:57 +02:00
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl, "rect_size", ctrl->get_size(), existing);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2014-07-06 16:49:27 +02:00
|
|
|
case ANIM_INSERT_POS: {
|
|
|
|
|
|
|
|
key_pos = key_loc_button->is_pressed();
|
|
|
|
} break;
|
|
|
|
case ANIM_INSERT_ROT: {
|
|
|
|
|
2015-01-02 21:31:43 +01:00
|
|
|
key_rot = key_rot_button->is_pressed();
|
2014-07-06 16:49:27 +02:00
|
|
|
} break;
|
|
|
|
case ANIM_INSERT_SCALE: {
|
|
|
|
|
|
|
|
key_scale = key_scale_button->is_pressed();
|
|
|
|
} break;
|
2017-03-05 16:44:50 +01:00
|
|
|
/*
|
2014-07-06 16:49:27 +02:00
|
|
|
case ANIM_INSERT_POS_ROT
|
2014-02-10 02:10:30 +01:00
|
|
|
case ANIM_INSERT_POS_SCALE:
|
|
|
|
case ANIM_INSERT_ROT_SCALE:
|
|
|
|
case ANIM_INSERT_POS_ROT_SCALE: {
|
|
|
|
|
|
|
|
static const bool key_toggles[7][3]={
|
|
|
|
{true,false,false},
|
|
|
|
{false,true,false},
|
|
|
|
{false,false,true},
|
|
|
|
{true,true,false},
|
|
|
|
{true,false,true},
|
|
|
|
{false,true,true},
|
|
|
|
{true,true,true}
|
|
|
|
};
|
|
|
|
key_pos=key_toggles[p_op-ANIM_INSERT_POS][0];
|
|
|
|
key_rot=key_toggles[p_op-ANIM_INSERT_POS][1];
|
|
|
|
key_scale=key_toggles[p_op-ANIM_INSERT_POS][2];
|
|
|
|
|
|
|
|
for(int i=ANIM_INSERT_POS;i<=ANIM_INSERT_POS_ROT_SCALE;i++) {
|
|
|
|
int idx = animation_menu->get_popup()->get_item_index(i);
|
|
|
|
animation_menu->get_popup()->set_item_checked(idx,i==p_op);
|
|
|
|
}
|
|
|
|
|
2014-07-06 16:49:27 +02:00
|
|
|
} break;*/
|
2014-02-10 02:10:30 +01:00
|
|
|
case ANIM_COPY_POSE: {
|
|
|
|
|
2017-01-14 18:03:38 +01:00
|
|
|
pose_clipboard.clear();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<Node *, Object *> &selection = editor_selection->get_selection();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
PoseClipboard pc;
|
2017-03-05 16:44:50 +01:00
|
|
|
pc.pos = n2d->get_position();
|
|
|
|
pc.rot = n2d->get_rotation();
|
|
|
|
pc.scale = n2d->get_scale();
|
2017-08-07 12:17:31 +02:00
|
|
|
pc.id = n2d->get_instance_id();
|
2014-02-10 02:10:30 +01:00
|
|
|
pose_clipboard.push_back(pc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ANIM_PASTE_POSE: {
|
|
|
|
|
|
|
|
if (!pose_clipboard.size())
|
|
|
|
break;
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Paste Pose"));
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<PoseClipboard>::Element *E = pose_clipboard.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E->get().id));
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!n2d)
|
|
|
|
continue;
|
2017-03-29 17:29:38 +02:00
|
|
|
undo_redo->add_do_method(n2d, "set_position", E->get().pos);
|
2017-06-24 11:39:57 +02:00
|
|
|
undo_redo->add_do_method(n2d, "set_rotation", E->get().rot);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(n2d, "set_scale", E->get().scale);
|
2017-03-29 17:29:38 +02:00
|
|
|
undo_redo->add_undo_method(n2d, "set_position", n2d->get_position());
|
2017-06-24 11:39:57 +02:00
|
|
|
undo_redo->add_undo_method(n2d, "set_rotation", n2d->get_rotation());
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_undo_method(n2d, "set_scale", n2d->get_scale());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ANIM_CLEAR_POSE: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<Node *, Object *> &selection = editor_selection->get_selection();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
if (Object::cast_to<Node2D>(canvas_item)) {
|
|
|
|
Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (key_pos)
|
2017-01-04 05:16:14 +01:00
|
|
|
n2d->set_position(Vector2());
|
2014-02-10 02:10:30 +01:00
|
|
|
if (key_rot)
|
2017-01-04 05:16:14 +01:00
|
|
|
n2d->set_rotation(0);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (key_scale)
|
2017-03-05 16:44:50 +01:00
|
|
|
n2d->set_scale(Vector2(1, 1));
|
2017-08-24 22:58:51 +02:00
|
|
|
} else if (Object::cast_to<Control>(canvas_item)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *ctrl = Object::cast_to<Control>(canvas_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (key_pos)
|
2017-03-29 17:29:38 +02:00
|
|
|
ctrl->set_position(Point2());
|
2017-01-14 12:26:56 +01:00
|
|
|
/*
|
|
|
|
if (key_scale)
|
|
|
|
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size());
|
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2014-05-03 19:36:59 +02:00
|
|
|
case VIEW_CENTER_TO_SELECTION:
|
|
|
|
case VIEW_FRAME_TO_SELECTION: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-07-28 21:37:52 +02:00
|
|
|
_focus_selection(p_op);
|
2014-05-03 19:36:59 +02:00
|
|
|
|
|
|
|
} break;
|
2014-07-06 16:49:27 +02:00
|
|
|
case SKELETON_MAKE_BONES: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<Node *, Object *> &selection = editor_selection->get_selection();
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *n2d = Object::cast_to<Node2D>(E->key());
|
2014-07-06 16:49:27 +02:00
|
|
|
if (!n2d)
|
|
|
|
continue;
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!n2d->is_visible_in_tree())
|
2014-07-06 16:49:27 +02:00
|
|
|
continue;
|
|
|
|
if (!n2d->get_parent_item())
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
n2d->set_meta("_edit_bone_", true);
|
2016-09-07 11:10:00 +02:00
|
|
|
if (!skeleton_show_bones)
|
|
|
|
skeleton_menu->activate_item(skeleton_menu->get_item_index(SKELETON_SHOW_BONES));
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
viewport->update();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SKELETON_CLEAR_BONES: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<Node *, Object *> &selection = editor_selection->get_selection();
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *n2d = Object::cast_to<Node2D>(E->key());
|
2014-07-06 16:49:27 +02:00
|
|
|
if (!n2d)
|
|
|
|
continue;
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!n2d->is_visible_in_tree())
|
2014-07-06 16:49:27 +02:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
n2d->set_meta("_edit_bone_", Variant());
|
2016-09-07 11:10:00 +02:00
|
|
|
if (!skeleton_show_bones)
|
|
|
|
skeleton_menu->activate_item(skeleton_menu->get_item_index(SKELETON_SHOW_BONES));
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
viewport->update();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SKELETON_SET_IK_CHAIN: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> &selection = editor_selection->get_selected_node_list();
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!canvas_item || !canvas_item->is_visible_in_tree())
|
2014-07-06 16:49:27 +02:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-01-24 20:41:50 +01:00
|
|
|
continue;
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
canvas_item->set_meta("_edit_ik_", true);
|
2016-09-07 11:10:00 +02:00
|
|
|
if (!skeleton_show_bones)
|
|
|
|
skeleton_menu->activate_item(skeleton_menu->get_item_index(SKELETON_SHOW_BONES));
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
viewport->update();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SKELETON_CLEAR_IK_CHAIN: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<Node *, Object *> &selection = editor_selection->get_selection();
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-07-06 16:49:27 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *n2d = Object::cast_to<CanvasItem>(E->key());
|
2014-07-06 16:49:27 +02:00
|
|
|
if (!n2d)
|
|
|
|
continue;
|
2017-01-13 14:45:50 +01:00
|
|
|
if (!n2d->is_visible_in_tree())
|
2014-07-06 16:49:27 +02:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
n2d->set_meta("_edit_ik_", Variant());
|
2016-09-07 11:10:00 +02:00
|
|
|
if (!skeleton_show_bones)
|
|
|
|
skeleton_menu->activate_item(skeleton_menu->get_item_index(SKELETON_SHOW_BONES));
|
2014-07-06 16:49:27 +02:00
|
|
|
}
|
|
|
|
viewport->update();
|
|
|
|
|
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-28 21:37:52 +02:00
|
|
|
void CanvasItemEditor::_focus_selection(int p_op) {
|
|
|
|
Vector2 center(0.f, 0.f);
|
|
|
|
Rect2 rect;
|
|
|
|
int count = 0;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<Node *, Object *> &selection = editor_selection->get_selection();
|
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2017-08-24 22:58:51 +02:00
|
|
|
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
|
2016-07-28 21:37:52 +02:00
|
|
|
if (!canvas_item) continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
|
2016-07-28 21:37:52 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// counting invisible items, for now
|
2017-01-13 14:45:50 +01:00
|
|
|
//if (!canvas_item->is_visible_in_tree()) continue;
|
2016-07-28 21:37:52 +02:00
|
|
|
++count;
|
|
|
|
|
|
|
|
Rect2 item_rect = canvas_item->get_item_rect();
|
|
|
|
|
|
|
|
Vector2 pos = canvas_item->get_global_transform().get_origin();
|
|
|
|
Vector2 scale = canvas_item->get_global_transform().get_scale();
|
|
|
|
real_t angle = canvas_item->get_global_transform().get_rotation();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform2D t(angle, Vector2(0.f, 0.f));
|
2016-07-28 21:37:52 +02:00
|
|
|
item_rect = t.xform(item_rect);
|
2017-06-04 00:25:13 +02:00
|
|
|
Rect2 canvas_item_rect(pos + scale * item_rect.position, scale * item_rect.size);
|
2016-07-28 21:37:52 +02:00
|
|
|
if (count == 1) {
|
|
|
|
rect = canvas_item_rect;
|
|
|
|
} else {
|
|
|
|
rect = rect.merge(canvas_item_rect);
|
|
|
|
}
|
|
|
|
};
|
2017-03-05 16:44:50 +01:00
|
|
|
if (count == 0) return;
|
2016-07-28 21:37:52 +02:00
|
|
|
|
|
|
|
if (p_op == VIEW_CENTER_TO_SELECTION) {
|
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
center = rect.position + rect.size / 2;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 offset = viewport->get_size() / 2 - editor->get_scene_root()->get_global_canvas_transform().xform(center);
|
|
|
|
h_scroll->set_value(h_scroll->get_value() - offset.x / zoom);
|
|
|
|
v_scroll->set_value(v_scroll->get_value() - offset.y / zoom);
|
2016-07-28 21:37:52 +02:00
|
|
|
|
|
|
|
} else { // VIEW_FRAME_TO_SELECTION
|
|
|
|
|
|
|
|
if (rect.size.x > CMP_EPSILON && rect.size.y > CMP_EPSILON) {
|
2017-03-05 16:44:50 +01:00
|
|
|
float scale_x = viewport->get_size().x / rect.size.x;
|
|
|
|
float scale_y = viewport->get_size().y / rect.size.y;
|
|
|
|
zoom = scale_x < scale_y ? scale_x : scale_y;
|
2016-07-28 21:37:52 +02:00
|
|
|
zoom *= 0.90;
|
|
|
|
_update_scroll(0);
|
|
|
|
call_deferred("_popup_callback", VIEW_CENTER_TO_SELECTION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void CanvasItemEditor::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method("_update_scroll", &CanvasItemEditor::_update_scroll);
|
|
|
|
ClassDB::bind_method("_popup_callback", &CanvasItemEditor::_popup_callback);
|
|
|
|
ClassDB::bind_method("_dialog_value_changed", &CanvasItemEditor::_dialog_value_changed);
|
|
|
|
ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data);
|
|
|
|
ClassDB::bind_method("_tool_select", &CanvasItemEditor::_tool_select);
|
|
|
|
ClassDB::bind_method("_keying_changed", &CanvasItemEditor::_keying_changed);
|
|
|
|
ClassDB::bind_method("_unhandled_key_input", &CanvasItemEditor::_unhandled_key_input);
|
|
|
|
ClassDB::bind_method("_viewport_draw", &CanvasItemEditor::_viewport_draw);
|
|
|
|
ClassDB::bind_method("_viewport_gui_input", &CanvasItemEditor::_viewport_gui_input);
|
|
|
|
ClassDB::bind_method("_snap_changed", &CanvasItemEditor::_snap_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_selection_result_pressed"), &CanvasItemEditor::_selection_result_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_selection_menu_hide"), &CanvasItemEditor::_selection_menu_hide);
|
|
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("item_lock_status_changed"));
|
|
|
|
ADD_SIGNAL(MethodInfo("item_group_status_changed"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) {
|
|
|
|
|
|
|
|
hb->add_child(p_control);
|
|
|
|
}
|
|
|
|
|
2014-12-28 23:37:25 +01:00
|
|
|
HSplitContainer *CanvasItemEditor::get_palette_split() {
|
|
|
|
|
|
|
|
return palette_split;
|
|
|
|
}
|
|
|
|
|
2015-01-12 00:52:42 +01:00
|
|
|
VSplitContainer *CanvasItemEditor::get_bottom_split() {
|
|
|
|
|
|
|
|
return bottom_split;
|
|
|
|
}
|
|
|
|
|
2016-07-28 21:37:52 +02:00
|
|
|
void CanvasItemEditor::focus_selection() {
|
|
|
|
_focus_selection(VIEW_CENTER_TO_SELECTION);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
|
|
|
|
|
|
|
|
tool = TOOL_SELECT;
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo = p_editor->get_undo_redo();
|
|
|
|
editor = p_editor;
|
|
|
|
editor_selection = p_editor->get_editor_selection();
|
2014-02-10 02:10:30 +01:00
|
|
|
editor_selection->add_editor_plugin(this);
|
2017-03-05 16:44:50 +01:00
|
|
|
editor_selection->connect("selection_changed", this, "update");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
hb = memnew(HBoxContainer);
|
|
|
|
add_child(hb);
|
2014-02-10 02:10:30 +01:00
|
|
|
hb->set_area_as_parent_rect();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bottom_split = memnew(VSplitContainer);
|
2015-01-12 00:52:42 +01:00
|
|
|
bottom_split->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
add_child(bottom_split);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
palette_split = memnew(HSplitContainer);
|
2014-12-28 23:37:25 +01:00
|
|
|
palette_split->set_v_size_flags(SIZE_EXPAND_FILL);
|
2015-01-12 00:52:42 +01:00
|
|
|
bottom_split->add_child(palette_split);
|
2014-12-28 23:37:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Control *vp_base = memnew(Control);
|
2014-02-10 02:10:30 +01:00
|
|
|
vp_base->set_v_size_flags(SIZE_EXPAND_FILL);
|
2014-12-28 23:37:25 +01:00
|
|
|
palette_split->add_child(vp_base);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ViewportContainer *vp = memnew(ViewportContainer);
|
2016-10-05 06:26:35 +02:00
|
|
|
vp->set_stretch(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
vp_base->add_child(vp);
|
|
|
|
vp->set_area_as_parent_rect();
|
|
|
|
vp->add_child(p_editor->get_scene_root());
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
viewport = memnew(CanvasItemEditorViewport(p_editor, this));
|
2014-02-10 02:10:30 +01:00
|
|
|
vp_base->add_child(viewport);
|
|
|
|
viewport->set_area_as_parent_rect();
|
2017-01-09 19:50:08 +01:00
|
|
|
viewport->set_clip_contents(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
h_scroll = memnew(HScrollBar);
|
|
|
|
v_scroll = memnew(VScrollBar);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
viewport->add_child(h_scroll);
|
|
|
|
viewport->add_child(v_scroll);
|
2017-03-05 16:44:50 +01:00
|
|
|
viewport->connect("draw", this, "_viewport_draw");
|
|
|
|
viewport->connect("gui_input", this, "_viewport_gui_input");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
h_scroll->connect("value_changed", this, "_update_scroll", Vector<Variant>(), Object::CONNECT_DEFERRED);
|
|
|
|
v_scroll->connect("value_changed", this, "_update_scroll", Vector<Variant>(), Object::CONNECT_DEFERRED);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
h_scroll->hide();
|
|
|
|
v_scroll->hide();
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_scroll = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
viewport->set_focus_mode(FOCUS_ALL);
|
2017-03-05 16:44:50 +01:00
|
|
|
handle_len = 10;
|
|
|
|
first_update = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
select_button = memnew(ToolButton);
|
2014-02-10 02:10:30 +01:00
|
|
|
select_button->set_toggle_mode(true);
|
|
|
|
hb->add_child(select_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
select_button->connect("pressed", this, "_tool_select", make_binds(TOOL_SELECT));
|
2014-02-10 02:10:30 +01:00
|
|
|
select_button->set_pressed(true);
|
2017-03-05 16:44:50 +01:00
|
|
|
select_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/select_mode", TTR("Select Mode"), KEY_Q));
|
|
|
|
select_button->set_tooltip(TTR("Select Mode") + " $sc\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate") + "\n" + TTR("Alt+Drag: Move") + "\n" + TTR("Press 'v' to Change Pivot, 'Shift+v' to Drag Pivot (while moving).") + "\n" + TTR("Alt+RMB: Depth list selection"));
|
2015-12-13 21:16:13 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
move_button = memnew(ToolButton);
|
2014-02-10 02:10:30 +01:00
|
|
|
move_button->set_toggle_mode(true);
|
|
|
|
hb->add_child(move_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
move_button->connect("pressed", this, "_tool_select", make_binds(TOOL_MOVE));
|
|
|
|
move_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/move_mode", TTR("Move Mode"), KEY_W));
|
2016-07-15 21:22:01 +02:00
|
|
|
move_button->set_tooltip(TTR("Move Mode"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
rotate_button = memnew(ToolButton);
|
2014-02-10 02:10:30 +01:00
|
|
|
rotate_button->set_toggle_mode(true);
|
|
|
|
hb->add_child(rotate_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
rotate_button->connect("pressed", this, "_tool_select", make_binds(TOOL_ROTATE));
|
|
|
|
rotate_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/rotate_mode", TTR("Rotate Mode"), KEY_E));
|
2016-07-15 21:22:01 +02:00
|
|
|
rotate_button->set_tooltip(TTR("Rotate Mode"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
hb->add_child(memnew(VSeparator));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
list_select_button = memnew(ToolButton);
|
2015-12-13 21:16:13 +01:00
|
|
|
list_select_button->set_toggle_mode(true);
|
|
|
|
hb->add_child(list_select_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
list_select_button->connect("pressed", this, "_tool_select", make_binds(TOOL_LIST_SELECT));
|
2016-05-19 00:08:12 +02:00
|
|
|
list_select_button->set_tooltip(TTR("Show a list of all objects at the position clicked\n(same as Alt+RMB in select mode)."));
|
2015-12-13 21:16:13 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pivot_button = memnew(ToolButton);
|
2015-12-28 13:38:15 +01:00
|
|
|
pivot_button->set_toggle_mode(true);
|
|
|
|
hb->add_child(pivot_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
pivot_button->connect("pressed", this, "_tool_select", make_binds(TOOL_EDIT_PIVOT));
|
2016-05-19 00:08:12 +02:00
|
|
|
pivot_button->set_tooltip(TTR("Click to change object's rotation pivot."));
|
2015-12-28 13:38:15 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pan_button = memnew(ToolButton);
|
2014-05-02 13:39:12 +02:00
|
|
|
pan_button->set_toggle_mode(true);
|
|
|
|
hb->add_child(pan_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
pan_button->connect("pressed", this, "_tool_select", make_binds(TOOL_PAN));
|
2016-05-04 03:25:37 +02:00
|
|
|
pan_button->set_tooltip(TTR("Pan Mode"));
|
2014-05-02 13:39:12 +02:00
|
|
|
|
|
|
|
hb->add_child(memnew(VSeparator));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
lock_button = memnew(ToolButton);
|
2014-02-10 02:10:30 +01:00
|
|
|
hb->add_child(lock_button);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
lock_button->connect("pressed", this, "_popup_callback", varray(LOCK_SELECTED));
|
2016-05-19 00:08:12 +02:00
|
|
|
lock_button->set_tooltip(TTR("Lock the selected object in place (can't be moved)."));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
unlock_button = memnew(ToolButton);
|
2014-02-10 02:10:30 +01:00
|
|
|
hb->add_child(unlock_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
unlock_button->connect("pressed", this, "_popup_callback", varray(UNLOCK_SELECTED));
|
2016-05-04 03:25:37 +02:00
|
|
|
unlock_button->set_tooltip(TTR("Unlock the selected object (can be moved)."));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
group_button = memnew(ToolButton);
|
2014-02-10 02:10:30 +01:00
|
|
|
hb->add_child(group_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
group_button->connect("pressed", this, "_popup_callback", varray(GROUP_SELECTED));
|
2016-05-19 00:08:12 +02:00
|
|
|
group_button->set_tooltip(TTR("Makes sure the object's children are not selectable."));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ungroup_button = memnew(ToolButton);
|
2014-02-10 02:10:30 +01:00
|
|
|
hb->add_child(ungroup_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
ungroup_button->connect("pressed", this, "_popup_callback", varray(UNGROUP_SELECTED));
|
2016-05-19 00:08:12 +02:00
|
|
|
ungroup_button->set_tooltip(TTR("Restores the object's children's ability to be selected."));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
hb->add_child(memnew(VSeparator));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu = memnew(MenuButton);
|
2016-05-04 03:25:37 +02:00
|
|
|
edit_menu->set_text(TTR("Edit"));
|
2014-02-10 02:10:30 +01:00
|
|
|
hb->add_child(edit_menu);
|
2017-03-05 16:44:50 +01:00
|
|
|
edit_menu->get_popup()->connect("id_pressed", this, "_popup_callback");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
PopupMenu *p;
|
|
|
|
p = edit_menu->get_popup();
|
2017-04-14 13:49:50 +02:00
|
|
|
p->set_hide_on_checkable_item_selection(false);
|
2016-06-29 22:02:26 +02:00
|
|
|
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_snap", TTR("Use Snap")), SNAP_USE);
|
|
|
|
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_grid", TTR("Show Grid")), SNAP_SHOW_GRID);
|
|
|
|
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_rotation_snap", TTR("Use Rotation Snap")), SNAP_USE_ROTATION);
|
|
|
|
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_relative", TTR("Snap Relative")), SNAP_RELATIVE);
|
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/configure_snap", TTR("Configure Snap..")), SNAP_CONFIGURE);
|
2014-02-10 02:10:30 +01:00
|
|
|
p->add_separator();
|
2016-06-29 22:02:26 +02:00
|
|
|
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_pixel_snap", TTR("Use Pixel Snap")), SNAP_USE_PIXEL);
|
2014-02-10 02:10:30 +01:00
|
|
|
p->add_separator();
|
2017-03-05 16:44:50 +01:00
|
|
|
p->add_submenu_item(TTR("Skeleton.."), "skeleton");
|
2016-09-07 11:10:00 +02:00
|
|
|
skeleton_menu = memnew(PopupMenu);
|
|
|
|
p->add_child(skeleton_menu);
|
|
|
|
skeleton_menu->set_name("skeleton");
|
2017-03-05 16:44:50 +01:00
|
|
|
skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_make_bones", TTR("Make Bones"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B), SKELETON_MAKE_BONES);
|
2016-09-07 11:10:00 +02:00
|
|
|
skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_clear_bones", TTR("Clear Bones")), SKELETON_CLEAR_BONES);
|
|
|
|
skeleton_menu->add_separator();
|
|
|
|
skeleton_menu->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_show_bones", TTR("Show Bones")), SKELETON_SHOW_BONES);
|
|
|
|
skeleton_menu->add_separator();
|
|
|
|
skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_set_ik_chain", TTR("Make IK Chain")), SKELETON_SET_IK_CHAIN);
|
|
|
|
skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_clear_ik_chain", TTR("Clear IK Chain")), SKELETON_CLEAR_IK_CHAIN);
|
2017-04-14 13:49:50 +02:00
|
|
|
skeleton_menu->set_hide_on_checkable_item_selection(false);
|
2017-03-05 16:44:50 +01:00
|
|
|
skeleton_menu->connect("id_pressed", this, "_popup_callback");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
view_menu = memnew(MenuButton);
|
2016-05-04 03:25:37 +02:00
|
|
|
view_menu->set_text(TTR("View"));
|
2014-02-10 02:10:30 +01:00
|
|
|
hb->add_child(view_menu);
|
2017-03-05 16:44:50 +01:00
|
|
|
view_menu->get_popup()->connect("id_pressed", this, "_popup_callback");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
p = view_menu->get_popup();
|
|
|
|
|
2016-06-29 22:02:26 +02:00
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_in", TTR("Zoom In")), ZOOM_IN);
|
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_out", TTR("Zoom Out")), ZOOM_OUT);
|
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_reset", TTR("Zoom Reset")), ZOOM_RESET);
|
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_set", TTR("Zoom Set..")), ZOOM_SET);
|
2014-07-06 16:49:27 +02:00
|
|
|
p->add_separator();
|
2016-06-29 22:02:26 +02:00
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION);
|
2016-07-15 21:38:43 +02:00
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/frame_selection", TTR("Frame Selection"), KEY_MASK_SHIFT | KEY_F), VIEW_FRAME_TO_SELECTION);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
anchor_menu = memnew(MenuButton);
|
2016-05-04 03:25:37 +02:00
|
|
|
anchor_menu->set_text(TTR("Anchor"));
|
2015-08-24 06:00:39 +02:00
|
|
|
hb->add_child(anchor_menu);
|
2017-03-05 16:44:50 +01:00
|
|
|
anchor_menu->get_popup()->connect("id_pressed", this, "_popup_callback");
|
2015-08-24 06:00:39 +02:00
|
|
|
anchor_menu->hide();
|
|
|
|
|
|
|
|
//p = anchor_menu->get_popup();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
animation_hb = memnew(HBoxContainer);
|
2014-07-06 16:49:27 +02:00
|
|
|
hb->add_child(animation_hb);
|
2017-03-05 16:44:50 +01:00
|
|
|
animation_hb->add_child(memnew(VSeparator));
|
2014-07-06 16:49:27 +02:00
|
|
|
animation_hb->hide();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
key_loc_button = memnew(Button("loc"));
|
2014-07-06 16:49:27 +02:00
|
|
|
key_loc_button->set_toggle_mode(true);
|
2017-07-18 18:03:06 +02:00
|
|
|
key_loc_button->set_flat(true);
|
2014-07-06 16:49:27 +02:00
|
|
|
key_loc_button->set_pressed(true);
|
|
|
|
key_loc_button->set_focus_mode(FOCUS_NONE);
|
2017-03-05 16:44:50 +01:00
|
|
|
key_loc_button->add_color_override("font_color", Color(1, 0.6, 0.6));
|
|
|
|
key_loc_button->add_color_override("font_color_pressed", Color(0.6, 1, 0.6));
|
|
|
|
key_loc_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_POS));
|
2014-07-06 16:49:27 +02:00
|
|
|
animation_hb->add_child(key_loc_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
key_rot_button = memnew(Button("rot"));
|
2014-07-06 16:49:27 +02:00
|
|
|
key_rot_button->set_toggle_mode(true);
|
2017-07-18 18:03:06 +02:00
|
|
|
key_rot_button->set_flat(true);
|
2014-07-06 16:49:27 +02:00
|
|
|
key_rot_button->set_pressed(true);
|
|
|
|
key_rot_button->set_focus_mode(FOCUS_NONE);
|
2017-03-05 16:44:50 +01:00
|
|
|
key_rot_button->add_color_override("font_color", Color(1, 0.6, 0.6));
|
|
|
|
key_rot_button->add_color_override("font_color_pressed", Color(0.6, 1, 0.6));
|
|
|
|
key_rot_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_ROT));
|
2014-07-06 16:49:27 +02:00
|
|
|
animation_hb->add_child(key_rot_button);
|
2017-03-05 16:44:50 +01:00
|
|
|
key_scale_button = memnew(Button("scl"));
|
2014-07-06 16:49:27 +02:00
|
|
|
key_scale_button->set_toggle_mode(true);
|
2017-07-18 18:03:06 +02:00
|
|
|
key_scale_button->set_flat(true);
|
2014-07-06 16:49:27 +02:00
|
|
|
key_scale_button->set_focus_mode(FOCUS_NONE);
|
2017-03-05 16:44:50 +01:00
|
|
|
key_scale_button->add_color_override("font_color", Color(1, 0.6, 0.6));
|
|
|
|
key_scale_button->add_color_override("font_color_pressed", Color(0.6, 1, 0.6));
|
|
|
|
key_scale_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_SCALE));
|
2014-07-06 16:49:27 +02:00
|
|
|
animation_hb->add_child(key_scale_button);
|
2017-05-02 23:02:06 +02:00
|
|
|
key_insert_button = memnew(Button);
|
2017-07-18 18:03:06 +02:00
|
|
|
key_insert_button->set_flat(true);
|
2014-07-06 16:49:27 +02:00
|
|
|
key_insert_button->set_focus_mode(FOCUS_NONE);
|
2017-03-05 16:44:50 +01:00
|
|
|
key_insert_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_KEY));
|
2016-06-29 22:02:26 +02:00
|
|
|
key_insert_button->set_tooltip(TTR("Insert Keys"));
|
|
|
|
key_insert_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/anim_insert_key", TTR("Insert Key"), KEY_INSERT));
|
2014-07-06 16:49:27 +02:00
|
|
|
|
|
|
|
animation_hb->add_child(key_insert_button);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
animation_menu = memnew(MenuButton);
|
2016-06-01 13:32:20 +02:00
|
|
|
animation_menu->set_text(TTR("Animation"));
|
2014-07-06 16:49:27 +02:00
|
|
|
animation_hb->add_child(animation_menu);
|
2017-03-05 16:44:50 +01:00
|
|
|
animation_menu->get_popup()->connect("id_pressed", this, "_popup_callback");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
p = animation_menu->get_popup();
|
|
|
|
|
2016-06-29 22:02:26 +02:00
|
|
|
p->add_shortcut(ED_GET_SHORTCUT("canvas_item_editor/anim_insert_key"), ANIM_INSERT_KEY);
|
2017-03-05 16:44:50 +01:00
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_insert_key_existing_tracks", TTR("Insert Key (Existing Tracks)"), KEY_MASK_CMD + KEY_INSERT), ANIM_INSERT_KEY_EXISTING);
|
2014-02-10 02:10:30 +01:00
|
|
|
p->add_separator();
|
2016-06-29 22:02:26 +02:00
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_copy_pose", TTR("Copy Pose")), ANIM_COPY_POSE);
|
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_paste_pose", TTR("Paste Pose")), ANIM_PASTE_POSE);
|
|
|
|
p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_clear_pose", TTR("Clear Pose"), KEY_MASK_SHIFT | KEY_K), ANIM_CLEAR_POSE);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
snap_dialog = memnew(SnapDialog);
|
|
|
|
snap_dialog->connect("confirmed", this, "_snap_changed");
|
2015-02-15 09:00:55 +01:00
|
|
|
add_child(snap_dialog);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
value_dialog = memnew(AcceptDialog);
|
2016-05-04 03:25:37 +02:00
|
|
|
value_dialog->set_title(TTR("Set a Value"));
|
|
|
|
value_dialog->get_ok()->set_text(TTR("Close"));
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(value_dialog);
|
|
|
|
|
|
|
|
Label *l = memnew(Label);
|
2016-05-04 03:25:37 +02:00
|
|
|
l->set_text(TTR("Snap (Pixels):"));
|
2017-03-29 17:29:38 +02:00
|
|
|
l->set_position(Point2(5, 5));
|
2014-02-10 02:10:30 +01:00
|
|
|
value_dialog->add_child(l);
|
2017-03-05 16:44:50 +01:00
|
|
|
dialog_label = l;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
dialog_val = memnew(SpinBox);
|
|
|
|
dialog_val->set_anchor(MARGIN_RIGHT, ANCHOR_END);
|
|
|
|
dialog_val->set_begin(Point2(15, 25));
|
2017-07-06 09:16:27 +02:00
|
|
|
dialog_val->set_end(Point2(-10, 25));
|
2014-02-10 02:10:30 +01:00
|
|
|
value_dialog->add_child(dialog_val);
|
2017-03-05 16:44:50 +01:00
|
|
|
dialog_val->connect("value_changed", this, "_dialog_value_changed");
|
|
|
|
select_sb = Ref<StyleBoxTexture>(memnew(StyleBoxTexture));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selection_menu = memnew(PopupMenu);
|
2015-11-04 22:39:07 +01:00
|
|
|
add_child(selection_menu);
|
|
|
|
selection_menu->set_custom_minimum_size(Vector2(100, 0));
|
2017-01-08 22:18:54 +01:00
|
|
|
selection_menu->connect("id_pressed", this, "_selection_result_pressed");
|
2015-11-04 22:39:07 +01:00
|
|
|
selection_menu->connect("popup_hide", this, "_selection_menu_hide");
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
key_pos = true;
|
|
|
|
key_rot = true;
|
|
|
|
key_scale = false;
|
|
|
|
|
|
|
|
zoom = 1;
|
|
|
|
snap_offset = Vector2(0, 0);
|
|
|
|
snap_step = Vector2(10, 10);
|
|
|
|
snap_rotation_offset = 0;
|
|
|
|
snap_rotation_step = 15 / (180 / Math_PI);
|
|
|
|
snap_grid = false;
|
|
|
|
snap_show_grid = false;
|
|
|
|
snap_rotation = false;
|
|
|
|
snap_pixel = false;
|
|
|
|
skeleton_show_bones = true;
|
|
|
|
skeleton_menu->set_item_checked(skeleton_menu->get_item_index(SKELETON_SHOW_BONES), true);
|
|
|
|
updating_value_dialog = false;
|
|
|
|
box_selecting = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
//zoom=0.5;
|
2017-03-05 16:44:50 +01:00
|
|
|
singleton = this;
|
2016-02-09 20:09:29 +01:00
|
|
|
|
2014-04-10 05:18:27 +02:00
|
|
|
set_process_unhandled_key_input(true);
|
2017-03-05 16:44:50 +01:00
|
|
|
can_move_pivot = false;
|
|
|
|
drag = DRAG_NONE;
|
|
|
|
bone_last_frame = 0;
|
|
|
|
additive_selection = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditor *CanvasItemEditor::singleton = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void CanvasItemEditorPlugin::edit(Object *p_object) {
|
|
|
|
|
|
|
|
canvas_item_editor->set_undo_redo(&get_undo_redo());
|
2017-08-24 22:58:51 +02:00
|
|
|
canvas_item_editor->edit(Object::cast_to<CanvasItem>(p_object));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CanvasItemEditorPlugin::handles(Object *p_object) const {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
return p_object->is_class("CanvasItem");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
|
|
|
|
if (p_visible) {
|
|
|
|
canvas_item_editor->show();
|
|
|
|
canvas_item_editor->set_fixed_process(true);
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(), false);
|
2014-02-10 02:10:30 +01:00
|
|
|
canvas_item_editor->viewport->grab_focus();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
canvas_item_editor->hide();
|
|
|
|
canvas_item_editor->set_fixed_process(false);
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(), true);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary CanvasItemEditorPlugin::get_state() const {
|
|
|
|
|
|
|
|
return canvas_item_editor->get_state();
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditorPlugin::set_state(const Dictionary &p_state) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
canvas_item_editor->set_state(p_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
CanvasItemEditorPlugin::CanvasItemEditorPlugin(EditorNode *p_node) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
editor = p_node;
|
|
|
|
canvas_item_editor = memnew(CanvasItemEditor(editor));
|
2016-02-08 17:01:54 +01:00
|
|
|
canvas_item_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2014-02-10 02:10:30 +01:00
|
|
|
editor->get_viewport()->add_child(canvas_item_editor);
|
|
|
|
canvas_item_editor->set_area_as_parent_rect();
|
|
|
|
canvas_item_editor->hide();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorPlugin::~CanvasItemEditorPlugin() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-25 21:27:24 +02:00
|
|
|
void CanvasItemEditorViewport::_on_mouse_exit() {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!selector->is_visible()) {
|
2016-10-25 21:27:24 +02:00
|
|
|
_remove_preview();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditorViewport::_on_select_type(Object *selected) {
|
2017-08-24 22:58:51 +02:00
|
|
|
CheckBox *check = Object::cast_to<CheckBox>(selected);
|
2016-10-25 21:27:24 +02:00
|
|
|
String type = check->get_text();
|
2017-03-05 16:44:50 +01:00
|
|
|
selector_label->set_text(vformat(TTR("Add %s"), type));
|
|
|
|
label->set_text(vformat(TTR("Adding %s..."), type));
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditorViewport::_on_change_type() {
|
2017-01-10 05:04:31 +01:00
|
|
|
if (!button_group->get_pressed_button())
|
|
|
|
return;
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
CheckBox *check = Object::cast_to<CheckBox>(button_group->get_pressed_button());
|
2017-03-05 16:44:50 +01:00
|
|
|
default_type = check->get_text();
|
2016-10-25 21:27:24 +02:00
|
|
|
_perform_drop_data();
|
|
|
|
selector->hide();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) const {
|
2017-08-10 18:40:28 +02:00
|
|
|
label->set_position(get_global_position() + Point2(14, 14) * EDSCALE);
|
2017-03-29 17:29:38 +02:00
|
|
|
label_desc->set_position(label->get_position() + Point2(0, label->get_size().height));
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
String path = files[i];
|
|
|
|
RES res = ResourceLoader::load(path);
|
2017-08-24 22:58:51 +02:00
|
|
|
Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(*res));
|
|
|
|
Ref<PackedScene> scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*res));
|
2017-03-13 11:35:27 +01:00
|
|
|
if (texture != NULL || scene != NULL) {
|
|
|
|
if (texture != NULL) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Sprite *sprite = memnew(Sprite);
|
2016-10-25 21:27:24 +02:00
|
|
|
sprite->set_texture(texture);
|
2017-03-05 16:44:50 +01:00
|
|
|
sprite->set_modulate(Color(1, 1, 1, 0.7f));
|
2016-10-25 21:27:24 +02:00
|
|
|
preview->add_child(sprite);
|
|
|
|
label->show();
|
|
|
|
label_desc->show();
|
2017-03-13 11:35:27 +01:00
|
|
|
} else {
|
|
|
|
if (scene.is_valid()) {
|
|
|
|
Node *instance = scene->instance();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (instance) {
|
2016-10-25 21:27:24 +02:00
|
|
|
preview->add_child(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editor->get_scene_root()->add_child(preview);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditorViewport::_remove_preview() {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (preview->get_parent()) {
|
2016-10-25 21:27:24 +02:00
|
|
|
editor->get_scene_root()->remove_child(preview);
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = preview->get_child_count() - 1; i >= 0; i--) {
|
|
|
|
Node *node = preview->get_child(i);
|
2016-10-25 21:27:24 +02:00
|
|
|
memdelete(node);
|
|
|
|
}
|
|
|
|
label->hide();
|
|
|
|
label_desc->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) {
|
|
|
|
if (p_desired_node->get_filename() == p_target_scene_path) {
|
2016-10-25 21:27:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int childCount = p_desired_node->get_child_count();
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
Node *child = p_desired_node->get_child(i);
|
|
|
|
if (_cyclical_dependency_exists(p_target_scene_path, child)) {
|
2016-10-25 21:27:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point) {
|
2017-01-14 04:51:09 +01:00
|
|
|
child->set_name(path.get_file().get_basename());
|
2017-08-25 17:14:33 +02:00
|
|
|
Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(ResourceCache::get(path)));
|
2016-10-25 21:27:24 +02:00
|
|
|
Size2 texture_size = texture->get_size();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
editor_data->get_undo_redo().add_do_method(parent, "add_child", child);
|
|
|
|
editor_data->get_undo_redo().add_do_method(child, "set_owner", editor->get_edited_scene());
|
2016-10-25 21:27:24 +02:00
|
|
|
editor_data->get_undo_redo().add_do_reference(child);
|
2017-03-05 16:44:50 +01:00
|
|
|
editor_data->get_undo_redo().add_undo_method(parent, "remove_child", child);
|
2016-10-25 21:27:24 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String new_name = parent->validate_child_name(child);
|
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
|
|
|
editor_data->get_undo_redo().add_do_method(sed, "live_debug_create_node", editor->get_edited_scene()->get_path_to(parent), child->get_class(), new_name);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name));
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
// handle with different property for texture
|
|
|
|
String property = "texture";
|
|
|
|
List<PropertyInfo> props;
|
|
|
|
child->get_property_list(&props);
|
2017-03-05 16:44:50 +01:00
|
|
|
for (const List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
|
|
|
|
if (E->get().name == "config/texture") { // Particles2D
|
|
|
|
property = "config/texture";
|
2016-10-25 21:27:24 +02:00
|
|
|
break;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (E->get().name == "texture/texture") { // Polygon2D
|
|
|
|
property = "texture/texture";
|
2016-10-25 21:27:24 +02:00
|
|
|
break;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (E->get().name == "normal") { // TouchScreenButton
|
|
|
|
property = "normal";
|
2016-10-25 21:27:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
editor_data->get_undo_redo().add_do_property(child, property, texture);
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
// make visible for certain node type
|
2017-03-05 16:44:50 +01:00
|
|
|
if (default_type == "Patch9Rect") {
|
|
|
|
editor_data->get_undo_redo().add_do_property(child, "rect/size", texture_size);
|
|
|
|
} else if (default_type == "Polygon2D") {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> list;
|
2017-03-05 16:44:50 +01:00
|
|
|
list.push_back(Vector2(0, 0));
|
|
|
|
list.push_back(Vector2(texture_size.width, 0));
|
|
|
|
list.push_back(Vector2(texture_size.width, texture_size.height));
|
|
|
|
list.push_back(Vector2(0, texture_size.height));
|
|
|
|
editor_data->get_undo_redo().add_do_property(child, "polygon", list);
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// locate at preview position
|
|
|
|
Point2 pos;
|
2017-03-29 17:29:38 +02:00
|
|
|
if (parent->has_method("get_global_position")) {
|
|
|
|
pos = parent->call("get_global_position");
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform2D trans = canvas->get_canvas_transform();
|
|
|
|
Point2 target_pos = (p_point - trans.get_origin()) / trans.get_scale().x - pos;
|
|
|
|
if (default_type == "Polygon2D" || default_type == "TouchScreenButton" || default_type == "TextureRect" || default_type == "Patch9Rect") {
|
|
|
|
target_pos -= texture_size / 2;
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
2017-03-23 00:47:51 +01:00
|
|
|
// there's nothing to be used as source position so snapping will work as absolute if enabled
|
|
|
|
target_pos = canvas->snap_point(target_pos, Vector2());
|
2017-03-13 11:35:27 +01:00
|
|
|
editor_data->get_undo_redo().add_do_method(child, "set_position", target_pos);
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, const Point2 &p_point) {
|
|
|
|
Ref<PackedScene> sdata = ResourceLoader::load(path);
|
2016-10-25 21:27:24 +02:00
|
|
|
if (!sdata.is_valid()) { // invalid scene
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *instanced_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE);
|
2016-10-25 21:27:24 +02:00
|
|
|
if (!instanced_scene) { // error on instancing
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (editor->get_edited_scene()->get_filename() != "") { // cyclical instancing
|
2016-10-25 21:27:24 +02:00
|
|
|
if (_cyclical_dependency_exists(editor->get_edited_scene()->get_filename(), instanced_scene)) {
|
2016-10-31 03:50:34 +01:00
|
|
|
memdelete(instanced_scene);
|
2016-10-25 21:27:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
instanced_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path));
|
2016-10-25 21:27:24 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
editor_data->get_undo_redo().add_do_method(parent, "add_child", instanced_scene);
|
|
|
|
editor_data->get_undo_redo().add_do_method(instanced_scene, "set_owner", editor->get_edited_scene());
|
2016-10-25 21:27:24 +02:00
|
|
|
editor_data->get_undo_redo().add_do_reference(instanced_scene);
|
2017-03-05 16:44:50 +01:00
|
|
|
editor_data->get_undo_redo().add_undo_method(parent, "remove_child", instanced_scene);
|
2016-10-25 21:27:24 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String new_name = parent->validate_child_name(instanced_scene);
|
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
|
|
|
editor_data->get_undo_redo().add_do_method(sed, "live_debug_instance_node", editor->get_edited_scene()->get_path_to(parent), path, new_name);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name));
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
Point2 pos;
|
2017-08-24 22:58:51 +02:00
|
|
|
Node2D *parent_node2d = Object::cast_to<Node2D>(parent);
|
2016-10-25 21:27:24 +02:00
|
|
|
if (parent_node2d) {
|
2017-03-05 16:44:50 +01:00
|
|
|
pos = parent_node2d->get_global_position();
|
2016-10-25 21:27:24 +02:00
|
|
|
} else {
|
2017-08-24 22:58:51 +02:00
|
|
|
Control *parent_control = Object::cast_to<Control>(parent);
|
2016-10-25 21:27:24 +02:00
|
|
|
if (parent_control) {
|
2017-03-29 17:29:38 +02:00
|
|
|
pos = parent_control->get_global_position();
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform2D trans = canvas->get_canvas_transform();
|
2017-03-23 00:47:51 +01:00
|
|
|
Vector2 target_pos = (p_point - trans.get_origin()) / trans.get_scale().x - pos;
|
|
|
|
// in relative snapping it may be useful for the user to take the original node position into account
|
2017-08-24 22:58:51 +02:00
|
|
|
Vector2 start_pos = Object::cast_to<Node2D>(instanced_scene) ? Object::cast_to<Node2D>(instanced_scene)->get_position() : target_pos;
|
2017-03-23 00:47:51 +01:00
|
|
|
target_pos = canvas->snap_point(target_pos, start_pos);
|
|
|
|
editor_data->get_undo_redo().add_do_method(instanced_scene, "set_position", target_pos);
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditorViewport::_perform_drop_data() {
|
2016-10-25 21:27:24 +02:00
|
|
|
_remove_preview();
|
|
|
|
|
|
|
|
Vector<String> error_files;
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().create_action(TTR("Create Node"));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < selected_files.size(); i++) {
|
|
|
|
String path = selected_files[i];
|
|
|
|
RES res = ResourceLoader::load(path);
|
2016-10-25 21:27:24 +02:00
|
|
|
if (res.is_null()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-24 22:58:51 +02:00
|
|
|
Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(*res));
|
|
|
|
Ref<PackedScene> scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*res));
|
2017-03-13 11:35:27 +01:00
|
|
|
if (texture != NULL) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *child;
|
|
|
|
if (default_type == "Light2D")
|
|
|
|
child = memnew(Light2D);
|
|
|
|
else if (default_type == "Particles2D")
|
|
|
|
child = memnew(Particles2D);
|
|
|
|
else if (default_type == "Polygon2D")
|
|
|
|
child = memnew(Polygon2D);
|
|
|
|
else if (default_type == "TouchScreenButton")
|
|
|
|
child = memnew(TouchScreenButton);
|
|
|
|
else if (default_type == "TextureRect")
|
|
|
|
child = memnew(TextureRect);
|
|
|
|
else if (default_type == "Patch9Rect")
|
|
|
|
child = memnew(NinePatchRect);
|
|
|
|
else
|
|
|
|
child = memnew(Sprite); // default
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
_create_nodes(target_node, child, path, drop_pos);
|
2017-03-13 11:35:27 +01:00
|
|
|
} else if (scene != NULL) {
|
2017-03-05 16:44:50 +01:00
|
|
|
bool success = _create_instance(target_node, path, drop_pos);
|
2016-10-25 21:27:24 +02:00
|
|
|
if (!success) {
|
|
|
|
error_files.push_back(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().commit_action();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (error_files.size() > 0) {
|
2016-10-25 21:27:24 +02:00
|
|
|
String files_str;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < error_files.size(); i++) {
|
2017-01-14 04:51:09 +01:00
|
|
|
files_str += error_files[i].get_file().get_basename() + ",";
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
files_str = files_str.substr(0, files_str.length() - 1);
|
2016-10-25 21:27:24 +02:00
|
|
|
accept->get_ok()->set_text(TTR("Ugh"));
|
2017-03-05 16:44:50 +01:00
|
|
|
accept->set_text(vformat(TTR("Error instancing scene from %s"), files_str.c_str()));
|
2016-10-25 21:27:24 +02:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
|
|
|
|
Dictionary d = p_data;
|
2016-10-25 21:27:24 +02:00
|
|
|
if (d.has("type")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (String(d["type"]) == "files") {
|
|
|
|
Vector<String> files = d["files"];
|
|
|
|
bool can_instance = false;
|
|
|
|
for (int i = 0; i < files.size(); i++) { // check if dragged files contain resource or scene can be created at least one
|
|
|
|
RES res = ResourceLoader::load(files[i]);
|
2016-10-25 21:27:24 +02:00
|
|
|
if (res.is_null()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
String type = res->get_class();
|
|
|
|
if (type == "PackedScene") {
|
|
|
|
Ref<PackedScene> sdata = ResourceLoader::load(files[i]);
|
|
|
|
Node *instanced_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE);
|
2016-10-25 21:27:24 +02:00
|
|
|
if (!instanced_scene) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
memdelete(instanced_scene);
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
can_instance = true;
|
2016-10-25 21:27:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (can_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!preview->get_parent()) { // create preview only once
|
2016-10-25 21:27:24 +02:00
|
|
|
_create_preview(files);
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform2D trans = canvas->get_canvas_transform();
|
|
|
|
preview->set_position((p_point - trans.get_origin()) / trans.get_scale().x);
|
|
|
|
label->set_text(vformat(TTR("Adding %s..."), default_type));
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
|
|
|
return can_instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
label->hide();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p_data) {
|
|
|
|
bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT);
|
|
|
|
bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT);
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
selected_files.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
Dictionary d = p_data;
|
|
|
|
if (d.has("type") && String(d["type"]) == "files") {
|
|
|
|
selected_files = d["files"];
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> list = editor->get_editor_selection()->get_selected_node_list();
|
|
|
|
if (list.size() == 0) {
|
2016-10-25 21:27:24 +02:00
|
|
|
accept->get_ok()->set_text(TTR("OK :("));
|
|
|
|
accept->set_text(TTR("No parent to instance a child at."));
|
|
|
|
accept->popup_centered_minsize();
|
|
|
|
_remove_preview();
|
|
|
|
return;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (list.size() != 1) {
|
2016-10-25 21:27:24 +02:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("This operation requires a single selected node."));
|
|
|
|
accept->popup_centered_minsize();
|
|
|
|
_remove_preview();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
target_node = list[0];
|
|
|
|
if (is_shift && target_node != editor->get_edited_scene()) {
|
|
|
|
target_node = target_node->get_parent();
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
drop_pos = p_point;
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
if (is_alt) {
|
2017-03-05 16:44:50 +01:00
|
|
|
List<BaseButton *> btn_list;
|
2017-01-10 05:04:31 +01:00
|
|
|
button_group->get_buttons(&btn_list);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < btn_list.size(); i++) {
|
2017-08-24 22:58:51 +02:00
|
|
|
CheckBox *check = Object::cast_to<CheckBox>(btn_list[i]);
|
2017-03-05 16:44:50 +01:00
|
|
|
check->set_pressed(check->get_text() == default_type);
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
selector_label->set_text(vformat(TTR("Add %s"), default_type));
|
2016-10-25 21:27:24 +02:00
|
|
|
selector->popup_centered_minsize();
|
|
|
|
} else {
|
|
|
|
_perform_drop_data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditorViewport::_notification(int p_what) {
|
2017-08-10 18:40:28 +02:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
connect("mouse_exited", this, "_on_mouse_exit");
|
|
|
|
label->add_color_override("font_color", get_color("warning_color", "Editor"));
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
|
disconnect("mouse_exited", this, "_on_mouse_exit");
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: break;
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasItemEditorViewport::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_on_select_type"), &CanvasItemEditorViewport::_on_select_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("_on_change_type"), &CanvasItemEditorViewport::_on_change_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("_on_mouse_exit"), &CanvasItemEditorViewport::_on_mouse_exit);
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas) {
|
|
|
|
default_type = "Sprite";
|
2016-10-25 21:27:24 +02:00
|
|
|
// Node2D
|
|
|
|
types.push_back("Sprite");
|
|
|
|
types.push_back("Light2D");
|
|
|
|
types.push_back("Particles2D");
|
|
|
|
types.push_back("Polygon2D");
|
|
|
|
types.push_back("TouchScreenButton");
|
|
|
|
// Control
|
2017-01-12 22:27:27 +01:00
|
|
|
types.push_back("TextureRect");
|
2017-01-14 10:52:54 +01:00
|
|
|
types.push_back("Patch9Rect");
|
2016-10-25 21:27:24 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
target_node = NULL;
|
|
|
|
editor = p_node;
|
|
|
|
editor_data = editor->get_scene_tree_dock()->get_editor_data();
|
|
|
|
canvas = p_canvas;
|
|
|
|
preview = memnew(Node2D);
|
|
|
|
accept = memnew(AcceptDialog);
|
2016-10-25 21:27:24 +02:00
|
|
|
editor->get_gui_base()->add_child(accept);
|
|
|
|
|
2017-08-10 18:40:28 +02:00
|
|
|
selector = memnew(AcceptDialog);
|
2016-10-25 21:27:24 +02:00
|
|
|
selector->set_title(TTR("Change default type"));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2017-08-10 18:40:28 +02:00
|
|
|
vbc->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
vbc->set_v_size_flags(SIZE_EXPAND_FILL);
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc->set_custom_minimum_size(Size2(200, 260) * EDSCALE);
|
2016-10-25 21:27:24 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selector_label = memnew(Label);
|
2016-10-25 21:27:24 +02:00
|
|
|
selector_label->set_align(Label::ALIGN_CENTER);
|
|
|
|
selector_label->set_valign(Label::VALIGN_BOTTOM);
|
2017-03-05 16:44:50 +01:00
|
|
|
selector_label->set_custom_minimum_size(Size2(0, 30) * EDSCALE);
|
2016-10-25 21:27:24 +02:00
|
|
|
vbc->add_child(selector_label);
|
|
|
|
|
2017-01-10 05:04:31 +01:00
|
|
|
button_group.instance();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
btn_group = memnew(VBoxContainer);
|
2016-10-25 21:27:24 +02:00
|
|
|
btn_group->set_h_size_flags(0);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < types.size(); i++) {
|
|
|
|
CheckBox *check = memnew(CheckBox);
|
2016-10-25 21:27:24 +02:00
|
|
|
check->set_text(types[i]);
|
2017-04-10 06:00:08 +02:00
|
|
|
check->connect("button_down", this, "_on_select_type", varray(check));
|
2016-10-25 21:27:24 +02:00
|
|
|
btn_group->add_child(check);
|
2017-01-10 05:04:31 +01:00
|
|
|
check->set_button_group(button_group);
|
2016-10-25 21:27:24 +02:00
|
|
|
}
|
|
|
|
vbc->add_child(btn_group);
|
|
|
|
|
2017-08-10 18:40:28 +02:00
|
|
|
selector->connect("confirmed", this, "_on_change_type");
|
2016-10-25 21:27:24 +02:00
|
|
|
|
|
|
|
selector->add_child(vbc);
|
|
|
|
editor->get_gui_base()->add_child(selector);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
label = memnew(Label);
|
|
|
|
label->add_color_override("font_color_shadow", Color(0, 0, 0, 1));
|
|
|
|
label->add_constant_override("shadow_as_outline", 1 * EDSCALE);
|
2016-10-25 21:27:24 +02:00
|
|
|
label->hide();
|
|
|
|
editor->get_gui_base()->add_child(label);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
label_desc = memnew(Label);
|
2016-10-25 21:27:24 +02:00
|
|
|
label_desc->set_text(TTR("Drag & drop + Shift : Add node as sibling\nDrag & drop + Alt : Change node type"));
|
2017-03-13 11:35:27 +01:00
|
|
|
label_desc->add_color_override("font_color", Color(0.6f, 0.6f, 0.6f, 1));
|
|
|
|
label_desc->add_color_override("font_color_shadow", Color(0.2f, 0.2f, 0.2f, 1));
|
2017-03-05 16:44:50 +01:00
|
|
|
label_desc->add_constant_override("shadow_as_outline", 1 * EDSCALE);
|
2016-10-25 21:27:24 +02:00
|
|
|
label_desc->add_constant_override("line_spacing", 0);
|
|
|
|
label_desc->hide();
|
|
|
|
editor->get_gui_base()->add_child(label_desc);
|
|
|
|
}
|
2017-08-24 18:51:28 +02:00
|
|
|
|
|
|
|
CanvasItemEditorViewport::~CanvasItemEditorViewport() {
|
|
|
|
memdelete(preview);
|
|
|
|
}
|