Fixes snapping and replaces the _draw_canvas by forward_canvas_draw

This commit is contained in:
Gilles Roudiere 2017-10-15 22:33:25 +02:00
parent 6e960c7d6b
commit fc02605b49
21 changed files with 118 additions and 164 deletions

View file

@ -5691,12 +5691,12 @@ void EditorPluginList::edit(Object *p_object) {
}
}
bool EditorPluginList::forward_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) {
bool EditorPluginList::forward_gui_input(const Ref<InputEvent> &p_event) {
bool discard = false;
for (int i = 0; i < plugins_list.size(); i++) {
if (plugins_list[i]->forward_canvas_gui_input(p_canvas_xform, p_event)) {
if (plugins_list[i]->forward_canvas_gui_input(p_event)) {
discard = true;
}
}
@ -5720,10 +5720,10 @@ bool EditorPluginList::forward_spatial_gui_input(Camera *p_camera, const Ref<Inp
return discard;
}
void EditorPluginList::forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas) {
void EditorPluginList::forward_draw_over_canvas(Control *p_canvas) {
for (int i = 0; i < plugins_list.size(); i++) {
plugins_list[i]->forward_draw_over_canvas(p_canvas_xform, p_canvas);
plugins_list[i]->forward_draw_over_canvas(p_canvas);
}
}

View file

@ -812,9 +812,9 @@ public:
void make_visible(bool p_visible);
void edit(Object *p_object);
bool forward_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event);
bool forward_gui_input(const Ref<InputEvent> &p_event);
bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
void forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas);
void forward_draw_over_canvas(Control *p_canvas);
void add_plugin(EditorPlugin *p_plugin);
void clear();
bool empty();

View file

@ -402,18 +402,18 @@ Ref<SpatialEditorGizmo> EditorPlugin::create_spatial_gizmo(Spatial *p_spatial) {
return Ref<SpatialEditorGizmo>();
}
bool EditorPlugin::forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) {
bool EditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
if (get_script_instance() && get_script_instance()->has_method("forward_canvas_gui_input")) {
return get_script_instance()->call("forward_canvas_gui_input", p_canvas_xform, p_event);
return get_script_instance()->call("forward_canvas_gui_input", p_event);
}
return false;
}
void EditorPlugin::forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas) {
void EditorPlugin::forward_draw_over_canvas(Control *p_canvas) {
if (get_script_instance() && get_script_instance()->has_method("forward_draw_over_canvas")) {
get_script_instance()->call("forward_draw_over_canvas", p_canvas_xform, p_canvas);
get_script_instance()->call("forward_draw_over_canvas", p_canvas);
}
}

View file

@ -156,8 +156,8 @@ public:
void notify_scene_closed(const String &scene_filepath);
virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event);
virtual void forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas);
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
virtual void forward_draw_over_canvas(Control *p_canvas);
virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event);
virtual String get_name() const;
virtual bool has_main_screen() const;

View file

@ -195,9 +195,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event)
Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform();
Vector2 gpoint = mb->get_position();
Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
cpoint = canvas_item_editor->snap_point(cpoint);
cpoint = _get_node()->get_global_transform().affine_inverse().xform(cpoint);
Vector2 cpoint = _get_node()->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position())));
//first check if a point is to be added (segment split)
real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
@ -425,15 +423,14 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event)
if (edited_point != -1 && (wip_active || (mm->get_button_mask() & BUTTON_MASK_LEFT))) {
Vector2 gpoint = mm->get_position();
Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
cpoint = canvas_item_editor->snap_point(cpoint);
edited_point_pos = _get_node()->get_global_transform().affine_inverse().xform(cpoint);
Vector2 cpoint = _get_node()->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mm->get_position())));
edited_point_pos = cpoint;
if (!wip_active) {
Vector<Vector2> vertices = _get_polygon(edited_polygon);
ERR_FAIL_INDEX_V(edited_point, vertices.size(), false);
vertices[edited_point] = edited_point_pos - _get_offset(edited_polygon);
vertices[edited_point] = cpoint - _get_offset(edited_polygon);
_set_polygon(edited_polygon, vertices);
}
@ -444,8 +441,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event)
return false;
}
void AbstractPolygon2DEditor::_canvas_draw() {
void AbstractPolygon2DEditor::forward_draw_over_canvas(Control *p_canvas) {
if (!_get_node())
return;
@ -527,9 +523,6 @@ void AbstractPolygon2DEditor::edit(Node *p_polygon) {
if (_is_empty())
_menu_option(MODE_CREATE);
if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
wip.clear();
wip_active = false;
edited_point = -1;
@ -539,15 +532,11 @@ void AbstractPolygon2DEditor::edit(Node *p_polygon) {
} else {
_set_node(NULL);
if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw");
}
}
void AbstractPolygon2DEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_canvas_draw"), &AbstractPolygon2DEditor::_canvas_draw);
ClassDB::bind_method(D_METHOD("_node_removed"), &AbstractPolygon2DEditor::_node_removed);
ClassDB::bind_method(D_METHOD("_menu_option"), &AbstractPolygon2DEditor::_menu_option);
ClassDB::bind_method(D_METHOD("_create_resource"), &AbstractPolygon2DEditor::_create_resource);

View file

@ -75,7 +75,6 @@ protected:
virtual void _menu_option(int p_option);
void _wip_close();
void _canvas_draw();
void _notification(int p_what);
void _node_removed(Node *p_node);
@ -103,6 +102,8 @@ protected:
public:
bool forward_gui_input(const Ref<InputEvent> &p_event);
void forward_draw_over_canvas(Control *p_canvas);
void edit(Node *p_polygon);
AbstractPolygon2DEditor(EditorNode *p_editor, bool p_wip_destructive = true);
};
@ -116,7 +117,8 @@ class AbstractPolygon2DEditorPlugin : public EditorPlugin {
String klass;
public:
virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return polygon_editor->forward_gui_input(p_event); }
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return polygon_editor->forward_gui_input(p_event); }
virtual void forward_draw_over_canvas(Control *p_canvas) { polygon_editor->forward_draw_over_canvas(p_canvas); }
bool has_main_screen() const { return false; }
virtual String get_name() const { return klass; }

View file

@ -1198,14 +1198,23 @@ void CanvasItemEditor::_update_cursor() {
viewport->set_default_cursor_shape(c);
}
void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event) {
void CanvasItemEditor::_gui_input_viewport_base(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> m = p_event;
if (m.is_valid()) {
if (!viewport_base->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
viewport_base->call_deferred("grab_focus");
}
}
void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
{
EditorNode *en = editor;
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
if (!over_plugin_list->empty()) {
bool discard = over_plugin_list->forward_gui_input(transform, p_event);
bool discard = over_plugin_list->forward_gui_input(p_event);
if (discard) {
accept_event();
return;
@ -1224,7 +1233,7 @@ void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event)
_update_scroll(0);
viewport->update();
} else {
_zoom_on_position(zoom * (1 - (0.05 * b->get_factor())), viewport_scrollable->get_transform().affine_inverse().xform(b->get_position()));
_zoom_on_position(zoom * (1 - (0.05 * b->get_factor())), b->get_position());
}
return;
@ -1237,7 +1246,7 @@ void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event)
_update_scroll(0);
viewport->update();
} else {
_zoom_on_position(zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95), viewport_scrollable->get_transform().affine_inverse().xform(b->get_position()));
_zoom_on_position(zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95), b->get_position());
}
return;
@ -1320,7 +1329,7 @@ void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event)
if (b->get_button_index() == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) {
if (b->is_pressed()) {
// Set the pivot point
Point2 mouse_pos = viewport_scrollable->get_transform().affine_inverse().xform(b->get_position());
Point2 mouse_pos = b->get_position();
mouse_pos = transform.affine_inverse().xform(mouse_pos);
mouse_pos = snap_point(mouse_pos, SNAP_DEFAULT, _get_single_item());
_edit_set_pivot(mouse_pos);
@ -1443,8 +1452,8 @@ void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event)
E->get().to
};
Vector2 p = Geometry::get_closest_point_to_segment_2d(viewport_scrollable->get_transform().affine_inverse().xform(b->get_position()), s);
float d = p.distance_to(viewport_scrollable->get_transform().affine_inverse().xform(b->get_position()));
Vector2 p = Geometry::get_closest_point_to_segment_2d(b->get_position(), s);
float d = p.distance_to(b->get_position());
if (d < bone_width && d < closest_dist) {
Cbone = E;
closest_dist = d;
@ -1506,7 +1515,7 @@ void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event)
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
ERR_FAIL_COND(!se);
Point2 click = viewport_scrollable->get_transform().affine_inverse().xform(b->get_position());
Point2 click = b->get_position();
// Rotation
if ((b->get_control() && tool == TOOL_SELECT) || tool == TOOL_ROTATE) {
@ -1561,7 +1570,7 @@ void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event)
}
// Multiple selected items
Point2 click = viewport_scrollable->get_transform().affine_inverse().xform(b->get_position());
Point2 click = b->get_position();
if ((b->get_alt() || tool == TOOL_MOVE) && get_item_count()) {
// Drag the nodes
@ -1621,12 +1630,9 @@ void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event)
// Mouse motion event
_update_cursor();
if (!viewport_base->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
viewport_base->call_deferred("grab_focus");
if (box_selecting) {
// Update box selection
box_selecting_to = transform.affine_inverse().xform(viewport_scrollable->get_transform().affine_inverse().xform(m->get_position()));
box_selecting_to = transform.affine_inverse().xform(m->get_position());
viewport->update();
return;
}
@ -1672,7 +1678,7 @@ void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event)
}
Vector2 dfrom = drag_from;
Vector2 dto = transform.affine_inverse().xform(viewport_scrollable->get_transform().affine_inverse().xform(m->get_position()));
Vector2 dto = transform.affine_inverse().xform(m->get_position());
if (canvas_item->has_meta("_edit_lock_"))
continue;
@ -2681,9 +2687,8 @@ void CanvasItemEditor::_draw_viewport() {
EditorPluginList *over_plugin_list = editor->get_editor_plugins_over();
if (!over_plugin_list->empty()) {
over_plugin_list->forward_draw_over_canvas(transform, viewport);
over_plugin_list->forward_draw_over_canvas(viewport);
}
_draw_focus();
_draw_bones();
}
@ -3694,7 +3699,8 @@ void CanvasItemEditor::_bind_methods() {
ClassDB::bind_method("_unhandled_key_input", &CanvasItemEditor::_unhandled_key_input);
ClassDB::bind_method("_draw_viewport", &CanvasItemEditor::_draw_viewport);
ClassDB::bind_method("_draw_viewport_base", &CanvasItemEditor::_draw_viewport_base);
ClassDB::bind_method("_viewport_base_gui_input", &CanvasItemEditor::_viewport_base_gui_input);
ClassDB::bind_method("_gui_input_viewport", &CanvasItemEditor::_gui_input_viewport);
ClassDB::bind_method("_gui_input_viewport_base", &CanvasItemEditor::_gui_input_viewport_base);
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);
@ -3747,7 +3753,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
palette_split->add_child(viewport_base);
viewport_base->set_clip_contents(true);
viewport_base->connect("draw", this, "_draw_viewport_base");
viewport_base->connect("gui_input", this, "_viewport_base_gui_input");
viewport_base->connect("gui_input", this, "_gui_input_viewport_base");
viewport_base->set_focus_mode(FOCUS_ALL);
viewport_base->set_v_size_flags(SIZE_EXPAND_FILL);
viewport_base->set_h_size_flags(SIZE_EXPAND_FILL);
@ -3771,6 +3777,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
viewport->set_anchors_and_margins_preset(Control::PRESET_WIDE);
viewport->set_clip_contents(true);
viewport->connect("draw", this, "_draw_viewport");
viewport->connect("gui_input", this, "_gui_input_viewport");
h_scroll = memnew(HScrollBar);
viewport->add_child(h_scroll);

View file

@ -410,10 +410,11 @@ class CanvasItemEditor : public VBoxContainer {
void _draw_locks_and_groups(Node *p_node, const Transform2D &p_xform);
void _draw_viewport();
void _viewport_base_gui_input(const Ref<InputEvent> &p_event);
void _draw_viewport_base();
void _gui_input_viewport(const Ref<InputEvent> &p_event);
void _gui_input_viewport_base(const Ref<InputEvent> &p_event);
void _focus_selection(int p_op);
void _snap_if_closer(Point2 p_value, Point2 p_target_snap, Point2 &r_current_snap, bool (&r_snapped)[2], real_t rotation = 0.0, float p_radius = 10.0);

0
editor/plugins/collision_polygon_2d_editor_plugin.h Executable file → Normal file
View file

View file

@ -302,7 +302,7 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) {
undo_redo->commit_action();
}
bool CollisionShape2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
bool CollisionShape2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
if (!node) {
return false;
@ -317,17 +317,17 @@ bool CollisionShape2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
}
Ref<InputEventMouseButton> mb = p_event;
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
if (mb.is_valid()) {
Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Point2 gpoint(mb->get_position().x, mb->get_position().y);
Vector2 gpoint = mb->get_position();
Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position())));
if (mb->get_button_index() == BUTTON_LEFT) {
if (mb->is_pressed()) {
for (int i = 0; i < handles.size(); i++) {
if (gt.xform(handles[i]).distance_to(gpoint) < 8) {
if (xform.xform(handles[i]).distance_to(gpoint) < 8) {
edit_handle = i;
break;
@ -368,9 +368,7 @@ bool CollisionShape2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
return false;
}
Point2 gpoint = mm->get_position();
Point2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
cpoint = canvas_item_editor->snap_point(cpoint);
Vector2 cpoint = canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mm->get_position()));
cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
set_handle(edit_handle, cpoint);
@ -416,7 +414,7 @@ void CollisionShape2DEditor::_get_current_shape_type() {
canvas_item_editor->get_viewport_control()->update();
}
void CollisionShape2DEditor::_canvas_draw() {
void CollisionShape2DEditor::forward_draw_over_canvas(Control *p_canvas) {
if (!node) {
return;
@ -432,7 +430,6 @@ void CollisionShape2DEditor::_canvas_draw() {
return;
}
Control *c = canvas_item_editor->get_viewport_control();
Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Ref<Texture> h = get_icon("EditorHandle", "EditorIcons");
@ -451,8 +448,8 @@ void CollisionShape2DEditor::_canvas_draw() {
handles[0] = Point2(radius, -height);
handles[1] = Point2(0, -(height + radius));
c->draw_texture(h, gt.xform(handles[0]) - size);
c->draw_texture(h, gt.xform(handles[1]) - size);
p_canvas->draw_texture(h, gt.xform(handles[0]) - size);
p_canvas->draw_texture(h, gt.xform(handles[1]) - size);
} break;
@ -462,7 +459,7 @@ void CollisionShape2DEditor::_canvas_draw() {
handles.resize(1);
handles[0] = Point2(shape->get_radius(), 0);
c->draw_texture(h, gt.xform(handles[0]) - size);
p_canvas->draw_texture(h, gt.xform(handles[0]) - size);
} break;
@ -481,8 +478,8 @@ void CollisionShape2DEditor::_canvas_draw() {
handles[0] = shape->get_normal() * shape->get_d();
handles[1] = shape->get_normal() * (shape->get_d() + 30.0);
c->draw_texture(h, gt.xform(handles[0]) - size);
c->draw_texture(h, gt.xform(handles[1]) - size);
p_canvas->draw_texture(h, gt.xform(handles[0]) - size);
p_canvas->draw_texture(h, gt.xform(handles[1]) - size);
} break;
@ -492,7 +489,7 @@ void CollisionShape2DEditor::_canvas_draw() {
handles.resize(1);
handles[0] = Point2(0, shape->get_length());
c->draw_texture(h, gt.xform(handles[0]) - size);
p_canvas->draw_texture(h, gt.xform(handles[0]) - size);
} break;
@ -504,8 +501,8 @@ void CollisionShape2DEditor::_canvas_draw() {
handles[0] = Point2(ext.x, 0);
handles[1] = Point2(0, -ext.y);
c->draw_texture(h, gt.xform(handles[0]) - size);
c->draw_texture(h, gt.xform(handles[1]) - size);
p_canvas->draw_texture(h, gt.xform(handles[0]) - size);
p_canvas->draw_texture(h, gt.xform(handles[1]) - size);
} break;
@ -516,8 +513,8 @@ void CollisionShape2DEditor::_canvas_draw() {
handles[0] = shape->get_a();
handles[1] = shape->get_b();
c->draw_texture(h, gt.xform(handles[0]) - size);
c->draw_texture(h, gt.xform(handles[1]) - size);
p_canvas->draw_texture(h, gt.xform(handles[0]) - size);
p_canvas->draw_texture(h, gt.xform(handles[1]) - size);
} break;
}
@ -532,18 +529,12 @@ void CollisionShape2DEditor::edit(Node *p_node) {
if (p_node) {
node = Object::cast_to<CollisionShape2D>(p_node);
if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
_get_current_shape_type();
} else {
edit_handle = -1;
shape_type = -1;
if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw");
node = NULL;
}
@ -552,7 +543,6 @@ void CollisionShape2DEditor::edit(Node *p_node) {
void CollisionShape2DEditor::_bind_methods() {
ClassDB::bind_method("_canvas_draw", &CollisionShape2DEditor::_canvas_draw);
ClassDB::bind_method("_get_current_shape_type", &CollisionShape2DEditor::_get_current_shape_type);
}

View file

@ -68,13 +68,13 @@ class CollisionShape2DEditor : public Control {
void commit_handle(int idx, Variant &p_org);
void _get_current_shape_type();
void _canvas_draw();
protected:
static void _bind_methods();
public:
bool forward_gui_input(const Ref<InputEvent> &p_event);
bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
void forward_draw_over_canvas(Control *p_canvas);
void edit(Node *p_node);
CollisionShape2DEditor(EditorNode *p_editor);
@ -87,7 +87,8 @@ class CollisionShape2DEditorPlugin : public EditorPlugin {
EditorNode *editor;
public:
virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return collision_shape_2d_editor->forward_gui_input(p_event); }
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return collision_shape_2d_editor->forward_canvas_gui_input(p_event); }
virtual void forward_draw_over_canvas(Control *p_canvas) { return collision_shape_2d_editor->forward_draw_over_canvas(p_canvas); }
virtual String get_name() const { return "CollisionShape2D"; }
bool has_main_screen() const { return false; }

View file

@ -119,9 +119,7 @@ bool LightOccluder2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Vector2 gpoint = mb->get_position();
Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
cpoint = canvas_item_editor->snap_point(cpoint);
cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position())));
Vector<Vector2> poly = Variant(node->get_occluder_polygon()->get_polygon());
@ -319,7 +317,8 @@ bool LightOccluder2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
return false;
}
void LightOccluder2DEditor::_canvas_draw() {
void LightOccluder2DEditor::forward_draw_over_canvas(Control *p_canvas) {
if (!node || !node->get_occluder_polygon().is_valid())
return;
@ -368,17 +367,12 @@ void LightOccluder2DEditor::edit(Node *p_collision_polygon) {
if (p_collision_polygon) {
node = Object::cast_to<LightOccluder2D>(p_collision_polygon);
if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
wip.clear();
wip_active = false;
edited_point = -1;
canvas_item_editor->get_viewport_control()->update();
} else {
node = NULL;
if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw");
}
}
@ -395,7 +389,6 @@ void LightOccluder2DEditor::_create_poly() {
void LightOccluder2DEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_menu_option"), &LightOccluder2DEditor::_menu_option);
ClassDB::bind_method(D_METHOD("_canvas_draw"), &LightOccluder2DEditor::_canvas_draw);
ClassDB::bind_method(D_METHOD("_node_removed"), &LightOccluder2DEditor::_node_removed);
ClassDB::bind_method(D_METHOD("_create_poly"), &LightOccluder2DEditor::_create_poly);
}
@ -430,7 +423,7 @@ LightOccluder2DEditor::LightOccluder2DEditor(EditorNode *p_editor) {
void LightOccluder2DEditorPlugin::edit(Object *p_object) {
collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
light_occluder_editor->edit(Object::cast_to<Node>(p_object));
}
bool LightOccluder2DEditorPlugin::handles(Object *p_object) const {
@ -441,21 +434,21 @@ bool LightOccluder2DEditorPlugin::handles(Object *p_object) const {
void LightOccluder2DEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
collision_polygon_editor->show();
light_occluder_editor->show();
} else {
collision_polygon_editor->hide();
collision_polygon_editor->edit(NULL);
light_occluder_editor->hide();
light_occluder_editor->edit(NULL);
}
}
LightOccluder2DEditorPlugin::LightOccluder2DEditorPlugin(EditorNode *p_node) {
editor = p_node;
collision_polygon_editor = memnew(LightOccluder2DEditor(p_node));
CanvasItemEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor);
light_occluder_editor = memnew(LightOccluder2DEditor(p_node));
CanvasItemEditor::get_singleton()->add_control_to_menu_panel(light_occluder_editor);
collision_polygon_editor->hide();
light_occluder_editor->hide();
}
LightOccluder2DEditorPlugin::~LightOccluder2DEditorPlugin() {

View file

@ -72,7 +72,6 @@ class LightOccluder2DEditor : public HBoxContainer {
ConfirmationDialog *create_poly;
void _wip_close(bool p_closed);
void _canvas_draw();
void _menu_option(int p_option);
void _create_poly();
@ -83,6 +82,7 @@ protected:
public:
Vector2 snap_point(const Vector2 &p_point) const;
void forward_draw_over_canvas(Control *p_canvas);
bool forward_gui_input(const Ref<InputEvent> &p_event);
void edit(Node *p_collision_polygon);
LightOccluder2DEditor(EditorNode *p_editor);
@ -92,11 +92,12 @@ class LightOccluder2DEditorPlugin : public EditorPlugin {
GDCLASS(LightOccluder2DEditorPlugin, EditorPlugin);
LightOccluder2DEditor *collision_polygon_editor;
LightOccluder2DEditor *light_occluder_editor;
EditorNode *editor;
public:
virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return light_occluder_editor->forward_gui_input(p_event); }
virtual void forward_draw_over_canvas(Control *p_canvas) { return light_occluder_editor->forward_draw_over_canvas(p_canvas); }
virtual String get_name() const { return "LightOccluder2D"; }
bool has_main_screen() const { return false; }

View file

@ -54,16 +54,10 @@ void Line2DEditor::_notification(int p_what) {
}
}
Vector2 Line2DEditor::mouse_to_local_pos(Vector2 gpos, bool alt) {
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
return !alt ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpos)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpos)));
}
int Line2DEditor::get_point_index_at(Vector2 gpos) {
int Line2DEditor::get_point_index_at(const Transform2D &xform, Vector2 gpos) {
ERR_FAIL_COND_V(node == 0, -1);
real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
for (int i = 0; i < node->get_point_count(); ++i) {
Point2 p = xform.xform(node->get_point_position(i));
@ -75,7 +69,7 @@ int Line2DEditor::get_point_index_at(Vector2 gpos) {
return -1;
}
bool Line2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
bool Line2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
if (!node)
return false;
@ -88,10 +82,10 @@ bool Line2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid()) {
Vector2 gpoint = mb->get_position();
Vector2 cpoint = mouse_to_local_pos(gpoint, mb->get_alt());
Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position())));
if (mb->is_pressed() && _dragging == false) {
int i = get_point_index_at(gpoint);
int i = get_point_index_at(canvas_item_editor->get_canvas_transform() * node->get_global_transform(), gpoint);
if (i != -1) {
if (mb->get_button_index() == BUTTON_LEFT && !mb->get_shift() && mode == MODE_EDIT) {
_dragging = true;
@ -146,7 +140,8 @@ bool Line2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (mm.is_valid()) {
if (_dragging) {
Vector2 cpoint = mouse_to_local_pos(mm->get_position(), mm->get_alt());
Vector2 gpoint = mm->get_position();
Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mm->get_position())));
node->set_point_position(action_point, cpoint);
canvas_item_editor->get_viewport_control()->update();
return true;
@ -156,7 +151,7 @@ bool Line2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
return false;
}
void Line2DEditor::_canvas_draw() {
void Line2DEditor::forward_draw_over_canvas(Control *p_canvas) {
if (!node)
return;
@ -190,13 +185,9 @@ void Line2DEditor::edit(Node *p_line2d) {
if (p_line2d) {
node = Object::cast_to<Line2D>(p_line2d);
if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
if (!node->is_connected("visibility_changed", this, "_node_visibility_changed"))
node->connect("visibility_changed", this, "_node_visibility_changed");
} else {
if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw");
// node may have been deleted at this point
if (node && node->is_connected("visibility_changed", this, "_node_visibility_changed"))
node->disconnect("visibility_changed", this, "_node_visibility_changed");
@ -205,7 +196,6 @@ void Line2DEditor::edit(Node *p_line2d) {
}
void Line2DEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_canvas_draw"), &Line2DEditor::_canvas_draw);
ClassDB::bind_method(D_METHOD("_node_visibility_changed"), &Line2DEditor::_node_visibility_changed);
ClassDB::bind_method(D_METHOD("_mode_selected"), &Line2DEditor::_mode_selected);
}

View file

@ -40,27 +40,11 @@ class CanvasItemEditor;
class Line2DEditor : public HBoxContainer {
GDCLASS(Line2DEditor, HBoxContainer)
public:
bool forward_gui_input(const Ref<InputEvent> &p_event);
void edit(Node *p_line2d);
Line2DEditor(EditorNode *p_editor);
protected:
void _node_removed(Node *p_node);
void _notification(int p_what);
Vector2 mouse_to_local_pos(Vector2 mpos);
static void _bind_methods();
private:
void _mode_selected(int p_mode);
void _canvas_draw();
void _node_visibility_changed();
int get_point_index_at(Vector2 gpos);
Vector2 mouse_to_local_pos(Vector2 gpos, bool alt);
int get_point_index_at(const Transform2D &xform, Vector2 gpos);
UndoRedo *undo_redo;
@ -86,17 +70,26 @@ private:
int action_point;
Point2 moving_from;
Point2 moving_screen_from;
protected:
void _node_removed(Node *p_node);
void _notification(int p_what);
static void _bind_methods();
public:
bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
void forward_draw_over_canvas(Control *p_canvas);
void edit(Node *p_line2d);
Line2DEditor(EditorNode *p_editor);
};
class Line2DEditorPlugin : public EditorPlugin {
GDCLASS(Line2DEditorPlugin, EditorPlugin)
public:
virtual bool forward_canvas_gui_input(
const Transform2D &p_canvas_xform,
const Ref<InputEvent> &p_event) {
return line2d_editor->forward_gui_input(p_event);
}
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return line2d_editor->forward_canvas_gui_input(p_event); }
virtual void forward_draw_over_canvas(Control *p_canvas) { return line2d_editor->forward_draw_over_canvas(p_canvas); }
virtual String get_name() const { return "Line2D"; }
bool has_main_screen() const { return false; }

0
editor/plugins/navigation_polygon_editor_plugin.h Executable file → Normal file
View file

View file

@ -76,10 +76,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Vector2 gpoint = mb->get_position();
Vector2 cpoint =
!mb->get_alt() ?
canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) :
node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)));
Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position())));
real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
@ -239,10 +236,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
// Handle point/control movement.
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Vector2 gpoint = mm->get_position();
Vector2 cpoint =
!mm->get_alt() ?
canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) :
node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)));
Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mm->get_position())));
Ref<Curve2D> curve = node->get_curve();
@ -274,7 +268,8 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
return false;
}
void Path2DEditor::_canvas_draw() {
void Path2DEditor::forward_draw_over_canvas(Control *p_canvas) {
if (!node)
return;
@ -329,16 +324,11 @@ void Path2DEditor::edit(Node *p_path2d) {
if (p_path2d) {
node = Object::cast_to<Path2D>(p_path2d);
if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
if (!node->is_connected("visibility_changed", this, "_node_visibility_changed"))
node->connect("visibility_changed", this, "_node_visibility_changed");
} else {
if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw");
// node may have been deleted at this point
if (node && node->is_connected("visibility_changed", this, "_node_visibility_changed"))
node->disconnect("visibility_changed", this, "_node_visibility_changed");
@ -349,7 +339,6 @@ void Path2DEditor::edit(Node *p_path2d) {
void Path2DEditor::_bind_methods() {
//ClassDB::bind_method(D_METHOD("_menu_option"),&Path2DEditor::_menu_option);
ClassDB::bind_method(D_METHOD("_canvas_draw"), &Path2DEditor::_canvas_draw);
ClassDB::bind_method(D_METHOD("_node_visibility_changed"), &Path2DEditor::_node_visibility_changed);
ClassDB::bind_method(D_METHOD("_mode_selected"), &Path2DEditor::_mode_selected);
}

View file

@ -84,7 +84,6 @@ class Path2DEditor : public HBoxContainer {
void _mode_selected(int p_mode);
void _canvas_draw();
void _node_visibility_changed();
friend class Path2DEditorPlugin;
@ -95,6 +94,7 @@ protected:
public:
bool forward_gui_input(const Ref<InputEvent> &p_event);
void forward_draw_over_canvas(Control *p_canvas);
void edit(Node *p_path2d);
Path2DEditor(EditorNode *p_editor);
};
@ -107,7 +107,8 @@ class Path2DEditorPlugin : public EditorPlugin {
EditorNode *editor;
public:
virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return path2d_editor->forward_gui_input(p_event); }
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return path2d_editor->forward_gui_input(p_event); }
virtual void forward_draw_over_canvas(Control *p_canvas) { return path2d_editor->forward_draw_over_canvas(p_canvas); }
virtual String get_name() const { return "Path2D"; }
bool has_main_screen() const { return false; }

0
editor/plugins/polygon_2d_editor_plugin.h Executable file → Normal file
View file

View file

@ -229,7 +229,7 @@ struct _PaletteEntry {
return name < p_rhs.name;
}
};
}
} // namespace
void TileMapEditor::_update_palette() {
@ -1152,7 +1152,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
return false;
}
void TileMapEditor::_canvas_draw() {
void TileMapEditor::forward_draw_over_canvas(Control *p_canvas) {
if (!node)
return;
@ -1379,8 +1379,6 @@ void TileMapEditor::edit(Node *p_tile_map) {
if (p_tile_map) {
node = Object::cast_to<TileMap>(p_tile_map);
if (!canvas_item_editor->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->connect("draw", this, "_canvas_draw");
if (!canvas_item_editor->is_connected("mouse_entered", this, "_canvas_mouse_enter"))
canvas_item_editor->connect("mouse_entered", this, "_canvas_mouse_enter");
if (!canvas_item_editor->is_connected("mouse_exited", this, "_canvas_mouse_exit"))
@ -1391,8 +1389,6 @@ void TileMapEditor::edit(Node *p_tile_map) {
} else {
node = NULL;
if (canvas_item_editor->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->disconnect("draw", this, "_canvas_draw");
if (canvas_item_editor->is_connected("mouse_entered", this, "_canvas_mouse_enter"))
canvas_item_editor->disconnect("mouse_entered", this, "_canvas_mouse_enter");
if (canvas_item_editor->is_connected("mouse_exited", this, "_canvas_mouse_exit"))
@ -1428,7 +1424,6 @@ void TileMapEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_text_changed"), &TileMapEditor::_text_changed);
ClassDB::bind_method(D_METHOD("_sbox_input"), &TileMapEditor::_sbox_input);
ClassDB::bind_method(D_METHOD("_menu_option"), &TileMapEditor::_menu_option);
ClassDB::bind_method(D_METHOD("_canvas_draw"), &TileMapEditor::_canvas_draw);
ClassDB::bind_method(D_METHOD("_canvas_mouse_enter"), &TileMapEditor::_canvas_mouse_enter);
ClassDB::bind_method(D_METHOD("_canvas_mouse_exit"), &TileMapEditor::_canvas_mouse_exit);
ClassDB::bind_method(D_METHOD("_tileset_settings_changed"), &TileMapEditor::_tileset_settings_changed);

View file

@ -163,7 +163,6 @@ class TileMapEditor : public VBoxContainer {
void _text_changed(const String &p_text);
void _sbox_input(const Ref<InputEvent> &p_ie);
void _update_palette();
void _canvas_draw();
void _menu_option(int p_option);
void _set_cell(const Point2i &p_pos, int p_value, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false, bool p_with_undo = false);
@ -183,6 +182,8 @@ public:
HBoxContainer *get_toolbar() const { return toolbar; }
bool forward_gui_input(const Ref<InputEvent> &p_event);
void forward_draw_over_canvas(Control *p_canvas);
void edit(Node *p_tile_map);
TileMapEditor(EditorNode *p_editor);
@ -197,6 +198,7 @@ class TileMapEditorPlugin : public EditorPlugin {
public:
virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return tile_map_editor->forward_gui_input(p_event); }
virtual void forward_draw_over_canvas(Control *p_canvas) { tile_map_editor->forward_draw_over_canvas(p_canvas); }
virtual String get_name() const { return "TileMap"; }
bool has_main_screen() const { return false; }