From b1619d263930e74165cad25b44ff85e7830caa18 Mon Sep 17 00:00:00 2001 From: aXu-AP <1621768+aXu-AP@users.noreply.github.com> Date: Tue, 19 Nov 2024 19:50:06 +0200 Subject: [PATCH] Rename polygon editor members Remove "uv" prefixes and clarify some names. Reorder/regroup some members in header file. --- editor/plugins/polygon_2d_editor_plugin.cpp | 482 ++++++++++---------- editor/plugins/polygon_2d_editor_plugin.h | 51 ++- 2 files changed, 266 insertions(+), 267 deletions(-) diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index cb0ea51c9dde..f63be45e17eb 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -58,7 +58,7 @@ Node2D *Polygon2DEditor::_get_node() const { } void Polygon2DEditor::_set_node(Node *p_polygon) { - CanvasItem *draw = Object::cast_to(uv_edit_draw); + CanvasItem *draw = Object::cast_to(canvas); if (node) { node->disconnect("draw", callable_mp(draw, &CanvasItem::queue_redraw)); node->disconnect("draw", callable_mp(this, &Polygon2DEditor::_update_available_modes)); @@ -66,14 +66,14 @@ void Polygon2DEditor::_set_node(Node *p_polygon) { node = Object::cast_to(p_polygon); _update_polygon_editing_state(); - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); if (node) { - uv_edit_draw->set_texture_filter(node->get_texture_filter_in_tree()); + canvas->set_texture_filter(node->get_texture_filter_in_tree()); - if (!uv_edit->is_inside_tree()) { - EditorNode::get_bottom_panel()->add_item(TTR("Polygon"), uv_edit); + if (!polygon_edit->is_inside_tree()) { + EditorNode::get_bottom_panel()->add_item(TTR("Polygon"), polygon_edit); } - EditorNode::get_bottom_panel()->make_item_visible(uv_edit); + EditorNode::get_bottom_panel()->make_item_visible(polygon_edit); _update_bone_list(); _update_available_modes(); get_tree()->connect("process_frame", callable_mp(this, &Polygon2DEditor::_center_view), CONNECT_ONE_SHOT); @@ -104,7 +104,7 @@ void Polygon2DEditor::_notification(int p_what) { [[fallthrough]]; } case NOTIFICATION_ENTER_TREE: { - uv_panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EDITOR_GET("editors/panning/simple_panning"))); + panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EDITOR_GET("editors/panning/simple_panning"))); } break; case NOTIFICATION_READY: { @@ -123,23 +123,23 @@ void Polygon2DEditor::_notification(int p_what) { b_snap_grid->set_button_icon(get_editor_theme_icon(SNAME("Grid"))); b_snap_enable->set_button_icon(get_editor_theme_icon(SNAME("SnapGrid"))); - uv_vscroll->set_anchors_and_offsets_preset(PRESET_RIGHT_WIDE); - uv_hscroll->set_anchors_and_offsets_preset(PRESET_BOTTOM_WIDE); + vscroll->set_anchors_and_offsets_preset(PRESET_RIGHT_WIDE); + hscroll->set_anchors_and_offsets_preset(PRESET_BOTTOM_WIDE); // Avoid scrollbar overlapping. - Size2 hmin = uv_hscroll->get_combined_minimum_size(); - Size2 vmin = uv_vscroll->get_combined_minimum_size(); - uv_hscroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, -vmin.width); - uv_vscroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, -hmin.height); + Size2 hmin = hscroll->get_combined_minimum_size(); + Size2 vmin = vscroll->get_combined_minimum_size(); + hscroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, -vmin.width); + vscroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, -hmin.height); [[fallthrough]]; } case NOTIFICATION_THEME_CHANGED: { - uv_edit_draw->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree"))); + canvas->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree"))); bone_scroll->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree"))); } break; case NOTIFICATION_VISIBILITY_CHANGED: { - if (uv_edit->is_inside_tree()) { - EditorNode::get_bottom_panel()->remove_item(uv_edit); + if (polygon_edit->is_inside_tree()) { + EditorNode::get_bottom_panel()->remove_item(polygon_edit); } } break; } @@ -233,11 +233,11 @@ void Polygon2DEditor::_update_bone_list() { cb->connect(SceneStringName(pressed), callable_mp(this, &Polygon2DEditor::_bone_paint_selected).bind(i)); } - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } void Polygon2DEditor::_bone_paint_selected(int p_index) { - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } void Polygon2DEditor::_select_mode(int p_mode) { @@ -318,7 +318,7 @@ void Polygon2DEditor::_select_mode(int p_mode) { default: break; } - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } void Polygon2DEditor::_edit_menu_option(int p_option) { @@ -364,24 +364,24 @@ void Polygon2DEditor::_edit_menu_option(int p_option) { } void Polygon2DEditor::_cancel_editing() { - if (uv_create) { - uv_drag = false; - uv_create = false; - node->set_uv(uv_create_uv_prev); - node->set_polygon(uv_create_poly_prev); - node->set_internal_vertex_count(uv_create_prev_internal_vertices); - node->set_vertex_colors(uv_create_colors_prev); - node->call("_set_bones", uv_create_bones_prev); - node->set_polygons(polygons_prev); + if (is_creating) { + is_dragging = false; + is_creating = false; + node->set_uv(previous_uv); + node->set_polygon(previous_polygon); + node->set_internal_vertex_count(previous_internal_vertices); + node->set_vertex_colors(previous_colors); + node->call("_set_bones", previous_bones); + node->set_polygons(previous_polygons); _update_polygon_editing_state(); _update_available_modes(); - } else if (uv_drag) { - uv_drag = false; + } else if (is_dragging) { + is_dragging = false; if (current_mode == MODE_UV) { - node->set_uv(points_prev); + node->set_uv(editing_points); } else if (current_mode == MODE_POINTS) { - node->set_polygon(points_prev); + node->set_polygon(editing_points); } } @@ -416,58 +416,58 @@ void Polygon2DEditor::_set_use_snap(bool p_use) { void Polygon2DEditor::_set_show_grid(bool p_show) { snap_show_grid = p_show; EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "show_grid", p_show); - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } void Polygon2DEditor::_set_snap_off_x(real_t p_val) { snap_offset.x = p_val; EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_offset", snap_offset); - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } void Polygon2DEditor::_set_snap_off_y(real_t p_val) { snap_offset.y = p_val; EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_offset", snap_offset); - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } void Polygon2DEditor::_set_snap_step_x(real_t p_val) { snap_step.x = p_val; EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_step", snap_step); - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } void Polygon2DEditor::_set_snap_step_y(real_t p_val) { snap_step.y = p_val; EditorSettings::get_singleton()->set_project_metadata("polygon_2d_uv_editor", "snap_step", snap_step); - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } void Polygon2DEditor::_set_action(int p_action) { polygon_create.clear(); - uv_drag = false; - uv_create = false; + is_dragging = false; + is_creating = false; selected_action = Action(p_action); for (int i = 0; i < ACTION_MAX; i++) { action_buttons[i]->set_pressed(p_action == i); } - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } -void Polygon2DEditor::_uv_input(const Ref &p_input) { +void Polygon2DEditor::_canvas_input(const Ref &p_input) { if (!_get_node()) { return; } - if (uv_panner->gui_input(p_input)) { + if (panner->gui_input(p_input)) { accept_event(); return; } Transform2D mtx; - mtx.columns[2] = -uv_draw_ofs * uv_draw_zoom; - mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom)); + mtx.columns[2] = -draw_offset * draw_zoom; + mtx.scale_basis(Vector2(draw_zoom, draw_zoom)); EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); @@ -475,97 +475,95 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { if (mb.is_valid()) { if (mb->get_button_index() == MouseButton::LEFT) { if (mb->is_pressed()) { - uv_drag_from = snap_point(mb->get_position()); - uv_drag = true; - points_prev = node->get_uv(); - + drag_from = snap_point(mb->get_position()); + is_dragging = true; if (current_mode == MODE_UV) { - points_prev = node->get_uv(); + editing_points = node->get_uv(); } else { - points_prev = node->get_polygon(); + editing_points = node->get_polygon(); } current_action = selected_action; if (current_action == ACTION_CREATE) { - if (!uv_create) { - points_prev.clear(); + if (!is_creating) { + editing_points.clear(); Vector2 tuv = mtx.affine_inverse().xform(snap_point(mb->get_position())); - points_prev.push_back(tuv); - uv_create_to = tuv; + editing_points.push_back(tuv); + create_to = tuv; point_drag_index = 0; - uv_drag_from = tuv; - uv_drag = true; - uv_create = true; - uv_create_uv_prev = node->get_uv(); - uv_create_poly_prev = node->get_polygon(); - uv_create_prev_internal_vertices = node->get_internal_vertex_count(); - uv_create_colors_prev = node->get_vertex_colors(); - uv_create_bones_prev = node->call("_get_bones"); - polygons_prev = node->get_polygons(); + drag_from = tuv; + is_dragging = true; + is_creating = true; + previous_uv = node->get_uv(); + previous_polygon = node->get_polygon(); + previous_internal_vertices = node->get_internal_vertex_count(); + previous_colors = node->get_vertex_colors(); + previous_bones = node->call("_get_bones"); + previous_polygons = node->get_polygons(); disable_polygon_editing(false, String()); - node->set_polygon(points_prev); - node->set_uv(points_prev); + node->set_polygon(editing_points); + node->set_uv(editing_points); node->set_internal_vertex_count(0); - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } else { Vector2 tuv = mtx.affine_inverse().xform(snap_point(mb->get_position())); // Close the polygon if selected point is near start. Threshold for closing scaled by zoom level - if (points_prev.size() > 2 && tuv.distance_to(points_prev[0]) < (8 / uv_draw_zoom)) { + if (editing_points.size() > 2 && tuv.distance_to(editing_points[0]) < (8 / draw_zoom)) { undo_redo->create_action(TTR("Create Polygon & UV")); undo_redo->add_do_method(node, "set_uv", node->get_uv()); - undo_redo->add_undo_method(node, "set_uv", uv_create_uv_prev); + undo_redo->add_undo_method(node, "set_uv", previous_uv); undo_redo->add_do_method(node, "set_polygon", node->get_polygon()); - undo_redo->add_undo_method(node, "set_polygon", uv_create_poly_prev); + undo_redo->add_undo_method(node, "set_polygon", previous_polygon); undo_redo->add_do_method(node, "set_internal_vertex_count", 0); - undo_redo->add_undo_method(node, "set_internal_vertex_count", uv_create_prev_internal_vertices); + undo_redo->add_undo_method(node, "set_internal_vertex_count", previous_internal_vertices); undo_redo->add_do_method(node, "set_vertex_colors", Vector()); - undo_redo->add_undo_method(node, "set_vertex_colors", uv_create_colors_prev); + undo_redo->add_undo_method(node, "set_vertex_colors", previous_colors); undo_redo->add_do_method(node, "clear_bones"); - undo_redo->add_undo_method(node, "_set_bones", uv_create_bones_prev); + undo_redo->add_undo_method(node, "_set_bones", previous_bones); undo_redo->add_do_method(this, "_update_polygon_editing_state"); undo_redo->add_undo_method(this, "_update_polygon_editing_state"); undo_redo->commit_action(); - uv_drag = false; - uv_create = false; + is_dragging = false; + is_creating = false; _update_available_modes(); _set_action(ACTION_EDIT_POINT); _menu_option(MODE_EDIT); } else { - points_prev.push_back(tuv); - point_drag_index = points_prev.size() - 1; - uv_drag_from = tuv; + editing_points.push_back(tuv); + point_drag_index = editing_points.size() - 1; + drag_from = tuv; } - node->set_polygon(points_prev); - node->set_uv(points_prev); + node->set_polygon(editing_points); + node->set_uv(editing_points); } CanvasItemEditor::get_singleton()->update_viewport(); } if (current_action == ACTION_CREATE_INTERNAL) { - uv_create_uv_prev = node->get_uv(); - uv_create_poly_prev = node->get_polygon(); - uv_create_colors_prev = node->get_vertex_colors(); - uv_create_bones_prev = node->call("_get_bones"); + previous_uv = node->get_uv(); + previous_polygon = node->get_polygon(); + previous_colors = node->get_vertex_colors(); + previous_bones = node->call("_get_bones"); int internal_vertices = node->get_internal_vertex_count(); Vector2 pos = mtx.affine_inverse().xform(snap_point(mb->get_position())); - uv_create_poly_prev.push_back(pos); - uv_create_uv_prev.push_back(pos); - if (uv_create_colors_prev.size()) { - uv_create_colors_prev.push_back(Color(1, 1, 1)); + previous_polygon.push_back(pos); + previous_uv.push_back(pos); + if (previous_colors.size()) { + previous_colors.push_back(Color(1, 1, 1)); } undo_redo->create_action(TTR("Create Internal Vertex")); - undo_redo->add_do_method(node, "set_uv", uv_create_uv_prev); + undo_redo->add_do_method(node, "set_uv", previous_uv); undo_redo->add_undo_method(node, "set_uv", node->get_uv()); - undo_redo->add_do_method(node, "set_polygon", uv_create_poly_prev); + undo_redo->add_do_method(node, "set_polygon", previous_polygon); undo_redo->add_undo_method(node, "set_polygon", node->get_polygon()); - undo_redo->add_do_method(node, "set_vertex_colors", uv_create_colors_prev); + undo_redo->add_do_method(node, "set_vertex_colors", previous_colors); undo_redo->add_undo_method(node, "set_vertex_colors", node->get_vertex_colors()); for (int i = 0; i < node->get_bone_count(); i++) { Vector bonew = node->get_bone_weights(i); @@ -581,10 +579,10 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { } if (current_action == ACTION_REMOVE_INTERNAL) { - uv_create_uv_prev = node->get_uv(); - uv_create_poly_prev = node->get_polygon(); - uv_create_colors_prev = node->get_vertex_colors(); - uv_create_bones_prev = node->call("_get_bones"); + previous_uv = node->get_uv(); + previous_polygon = node->get_polygon(); + previous_colors = node->get_vertex_colors(); + previous_bones = node->call("_get_bones"); int internal_vertices = node->get_internal_vertex_count(); if (internal_vertices <= 0) { @@ -594,8 +592,8 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { int closest = -1; real_t closest_dist = 1e20; - for (int i = points_prev.size() - internal_vertices; i < points_prev.size(); i++) { - Vector2 tuv = mtx.xform(uv_create_poly_prev[i]); + for (int i = editing_points.size() - internal_vertices; i < editing_points.size(); i++) { + Vector2 tuv = mtx.xform(previous_polygon[i]); real_t dist = tuv.distance_to(mb->get_position()); if (dist < 8 && dist < closest_dist) { closest = i; @@ -607,18 +605,18 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { return; } - uv_create_poly_prev.remove_at(closest); - uv_create_uv_prev.remove_at(closest); - if (uv_create_colors_prev.size()) { - uv_create_colors_prev.remove_at(closest); + previous_polygon.remove_at(closest); + previous_uv.remove_at(closest); + if (previous_colors.size()) { + previous_colors.remove_at(closest); } undo_redo->create_action(TTR("Remove Internal Vertex")); - undo_redo->add_do_method(node, "set_uv", uv_create_uv_prev); + undo_redo->add_do_method(node, "set_uv", previous_uv); undo_redo->add_undo_method(node, "set_uv", node->get_uv()); - undo_redo->add_do_method(node, "set_polygon", uv_create_poly_prev); + undo_redo->add_do_method(node, "set_polygon", previous_polygon); undo_redo->add_undo_method(node, "set_polygon", node->get_polygon()); - undo_redo->add_do_method(node, "set_vertex_colors", uv_create_colors_prev); + undo_redo->add_do_method(node, "set_vertex_colors", previous_colors); undo_redo->add_undo_method(node, "set_vertex_colors", node->get_vertex_colors()); for (int i = 0; i < node->get_bone_count(); i++) { Vector bonew = node->get_bone_weights(i); @@ -645,16 +643,16 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { if (current_action == ACTION_EDIT_POINT) { point_drag_index = -1; - for (int i = 0; i < points_prev.size(); i++) { - Vector2 tuv = mtx.xform(points_prev[i]); + for (int i = 0; i < editing_points.size(); i++) { + Vector2 tuv = mtx.xform(editing_points[i]); if (tuv.distance_to(mb->get_position()) < 8) { - uv_drag_from = tuv; + drag_from = tuv; point_drag_index = i; } } if (point_drag_index == -1) { - uv_drag = false; + is_dragging = false; } } @@ -662,8 +660,8 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { int closest = -1; real_t closest_dist = 1e20; - for (int i = 0; i < points_prev.size(); i++) { - Vector2 tuv = mtx.xform(points_prev[i]); + for (int i = 0; i < editing_points.size(); i++) { + Vector2 tuv = mtx.xform(editing_points[i]); real_t dist = tuv.distance_to(mb->get_position()); if (dist < 8 && dist < closest_dist) { closest = i; @@ -708,10 +706,10 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { polys.resize(points.size()); for (int j = 0; j < polys.size(); j++) { int idx = points[j]; - if (idx < 0 || idx >= points_prev.size()) { + if (idx < 0 || idx >= editing_points.size()) { continue; } - polys.write[j] = mtx.xform(points_prev[idx]); + polys.write[j] = mtx.xform(editing_points[idx]); } if (Geometry2D::is_point_in_polygon(mb->get_position(), polys)) { @@ -739,18 +737,18 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { } } - if (bone_selected != -1 && node->get_bone_weights(bone_selected).size() == points_prev.size()) { + if (bone_selected != -1 && node->get_bone_weights(bone_selected).size() == editing_points.size()) { prev_weights = node->get_bone_weights(bone_selected); bone_painting = true; bone_painting_bone = bone_selected; } } } else { - if (uv_drag && !uv_create) { + if (is_dragging && !is_creating) { if (current_mode == MODE_UV) { undo_redo->create_action(TTR("Transform UV Map")); undo_redo->add_do_method(node, "set_uv", node->get_uv()); - undo_redo->add_undo_method(node, "set_uv", points_prev); + undo_redo->add_undo_method(node, "set_uv", editing_points); undo_redo->commit_action(); } else if (current_mode == MODE_POINTS) { switch (current_action) { @@ -760,7 +758,7 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { case ACTION_SCALE: { undo_redo->create_action(TTR("Transform Polygon")); undo_redo->add_do_method(node, "set_polygon", node->get_polygon()); - undo_redo->add_undo_method(node, "set_polygon", points_prev); + undo_redo->add_undo_method(node, "set_polygon", editing_points); undo_redo->commit_action(); } break; default: { @@ -768,7 +766,7 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { } } - uv_drag = false; + is_dragging = false; } if (bone_painting) { @@ -786,26 +784,26 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { node->set_bone_weights(bone_painting_bone, prev_weights); } - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } } Ref mm = p_input; if (mm.is_valid()) { - if (uv_drag) { + if (is_dragging) { Vector2 uv_drag_to = mm->get_position(); uv_drag_to = snap_point(uv_drag_to); - Vector2 drag = mtx.affine_inverse().basis_xform(uv_drag_to - uv_drag_from); + Vector2 drag = mtx.affine_inverse().basis_xform(uv_drag_to - drag_from); switch (current_action) { case ACTION_CREATE: { - if (uv_create) { - uv_create_to = mtx.affine_inverse().xform(snap_point(mm->get_position())); + if (is_creating) { + create_to = mtx.affine_inverse().xform(snap_point(mm->get_position())); } } break; case ACTION_EDIT_POINT: { - Vector uv_new = points_prev; + Vector uv_new = editing_points; uv_new.set(point_drag_index, uv_new[point_drag_index] + drag); if (current_mode == MODE_UV) { @@ -815,7 +813,7 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { } } break; case ACTION_MOVE: { - Vector uv_new = points_prev; + Vector uv_new = editing_points; for (int i = 0; i < uv_new.size(); i++) { uv_new.set(i, uv_new[i] + drag); } @@ -828,17 +826,17 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { } break; case ACTION_ROTATE: { Vector2 center; - Vector uv_new = points_prev; + Vector uv_new = editing_points; for (int i = 0; i < uv_new.size(); i++) { - center += points_prev[i]; + center += editing_points[i]; } center /= uv_new.size(); - real_t angle = (uv_drag_from - mtx.xform(center)).normalized().angle_to((uv_drag_to - mtx.xform(center)).normalized()); + real_t angle = (drag_from - mtx.xform(center)).normalized().angle_to((uv_drag_to - mtx.xform(center)).normalized()); for (int i = 0; i < uv_new.size(); i++) { - Vector2 rel = points_prev[i] - center; + Vector2 rel = editing_points[i] - center; rel = rel.rotated(angle); uv_new.set(i, center + rel); } @@ -851,14 +849,14 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { } break; case ACTION_SCALE: { Vector2 center; - Vector uv_new = points_prev; + Vector uv_new = editing_points; for (int i = 0; i < uv_new.size(); i++) { - center += points_prev[i]; + center += editing_points[i]; } center /= uv_new.size(); - real_t from_dist = uv_drag_from.distance_to(mtx.xform(center)); + real_t from_dist = drag_from.distance_to(mtx.xform(center)); real_t to_dist = uv_drag_to.distance_to(mtx.xform(center)); if (from_dist < 2) { break; @@ -867,7 +865,7 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { real_t scale = to_dist / from_dist; for (int i = 0; i < uv_new.size(); i++) { - Vector2 rel = points_prev[i] - center; + Vector2 rel = editing_points[i] - center; rel = rel * scale; uv_new.set(i, center + rel); } @@ -900,7 +898,7 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { float *w = painted_weights.ptrw(); const float *r = prev_weights.ptr(); - const Vector2 *rv = points_prev.ptr(); + const Vector2 *rv = editing_points.ptr(); for (int i = 0; i < pc; i++) { if (mtx.xform(rv[i]).distance_to(bone_paint_pos) < radius) { @@ -912,14 +910,14 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { node->set_bone_weights(bone_painting_bone, painted_weights); } - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); CanvasItemEditor::get_singleton()->update_viewport(); } else if (polygon_create.size()) { - uv_create_to = mtx.affine_inverse().xform(mm->get_position()); - uv_edit_draw->queue_redraw(); + create_to = mtx.affine_inverse().xform(mm->get_position()); + canvas->queue_redraw(); } else if (selected_action == ACTION_PAINT_WEIGHT || selected_action == ACTION_CLEAR_WEIGHT) { bone_paint_pos = mm->get_position(); - uv_edit_draw->queue_redraw(); + canvas->queue_redraw(); } } } @@ -944,7 +942,7 @@ void Polygon2DEditor::_center_view() { Size2 texture_size; if (node->get_texture().is_valid()) { texture_size = node->get_texture()->get_size(); - Vector2 zoom_factor = (uv_edit_draw->get_size() - Vector2(1, 1) * 50 * EDSCALE) / texture_size; + Vector2 zoom_factor = (canvas->get_size() - Vector2(1, 1) * 50 * EDSCALE) / texture_size; zoom_widget->set_zoom(MIN(zoom_factor.x, zoom_factor.y)); } else { zoom_widget->set_zoom(EDSCALE); @@ -952,33 +950,33 @@ void Polygon2DEditor::_center_view() { // Recalculate scroll limits. _update_zoom_and_pan(false); - Size2 offset = (texture_size - uv_edit_draw->get_size() / uv_draw_zoom) / 2; - uv_hscroll->set_value_no_signal(offset.x); - uv_vscroll->set_value_no_signal(offset.y); + Size2 offset = (texture_size - canvas->get_size() / draw_zoom) / 2; + hscroll->set_value_no_signal(offset.x); + vscroll->set_value_no_signal(offset.y); _update_zoom_and_pan(false); } -void Polygon2DEditor::_uv_pan_callback(Vector2 p_scroll_vec, Ref p_event) { - uv_hscroll->set_value_no_signal(uv_hscroll->get_value() - p_scroll_vec.x / uv_draw_zoom); - uv_vscroll->set_value_no_signal(uv_vscroll->get_value() - p_scroll_vec.y / uv_draw_zoom); +void Polygon2DEditor::_pan_callback(Vector2 p_scroll_vec, Ref p_event) { + hscroll->set_value_no_signal(hscroll->get_value() - p_scroll_vec.x / draw_zoom); + vscroll->set_value_no_signal(vscroll->get_value() - p_scroll_vec.y / draw_zoom); _update_zoom_and_pan(false); } -void Polygon2DEditor::_uv_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref p_event) { - zoom_widget->set_zoom(uv_draw_zoom * p_zoom_factor); - uv_draw_ofs += p_origin / uv_draw_zoom - p_origin / zoom_widget->get_zoom(); - uv_hscroll->set_value_no_signal(uv_draw_ofs.x); - uv_vscroll->set_value_no_signal(uv_draw_ofs.y); +void Polygon2DEditor::_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref p_event) { + zoom_widget->set_zoom(draw_zoom * p_zoom_factor); + draw_offset += p_origin / draw_zoom - p_origin / zoom_widget->get_zoom(); + hscroll->set_value_no_signal(draw_offset.x); + vscroll->set_value_no_signal(draw_offset.y); _update_zoom_and_pan(false); } void Polygon2DEditor::_update_zoom_and_pan(bool p_zoom_at_center) { - uv_draw_ofs = Vector2(uv_hscroll->get_value(), uv_vscroll->get_value()); - real_t previous_zoom = uv_draw_zoom; - uv_draw_zoom = zoom_widget->get_zoom(); + draw_offset = Vector2(hscroll->get_value(), vscroll->get_value()); + real_t previous_zoom = draw_zoom; + draw_zoom = zoom_widget->get_zoom(); if (p_zoom_at_center) { - Vector2 center = uv_edit_draw->get_size() / 2; - uv_draw_ofs += center / previous_zoom - center / uv_draw_zoom; + Vector2 center = canvas->get_size() / 2; + draw_offset += center / previous_zoom - center / draw_zoom; } Point2 min_corner; @@ -992,30 +990,30 @@ void Polygon2DEditor::_update_zoom_and_pan(bool p_zoom_at_center) { min_corner = min_corner.min(points[i]); max_corner = max_corner.max(points[i]); } - Size2 page_size = uv_edit_draw->get_size() / uv_draw_zoom; - Vector2 margin = Vector2(50, 50) * EDSCALE / uv_draw_zoom; + Size2 page_size = canvas->get_size() / draw_zoom; + Vector2 margin = Vector2(50, 50) * EDSCALE / draw_zoom; min_corner -= page_size - margin; max_corner += page_size - margin; - uv_hscroll->set_block_signals(true); - uv_hscroll->set_min(min_corner.x); - uv_hscroll->set_max(max_corner.x); - uv_hscroll->set_page(page_size.x); - uv_hscroll->set_value(uv_draw_ofs.x); - uv_hscroll->set_block_signals(false); - - uv_vscroll->set_block_signals(true); - uv_vscroll->set_min(min_corner.y); - uv_vscroll->set_max(max_corner.y); - uv_vscroll->set_page(page_size.y); - uv_vscroll->set_value(uv_draw_ofs.y); - uv_vscroll->set_block_signals(false); - - uv_edit_draw->queue_redraw(); + hscroll->set_block_signals(true); + hscroll->set_min(min_corner.x); + hscroll->set_max(max_corner.x); + hscroll->set_page(page_size.x); + hscroll->set_value(draw_offset.x); + hscroll->set_block_signals(false); + + vscroll->set_block_signals(true); + vscroll->set_min(min_corner.y); + vscroll->set_max(max_corner.y); + vscroll->set_page(page_size.y); + vscroll->set_value(draw_offset.y); + vscroll->set_block_signals(false); + + canvas->queue_redraw(); } -void Polygon2DEditor::_uv_draw() { - if (!uv_edit->is_visible() || !_get_node()) { +void Polygon2DEditor::_canvas_draw() { + if (!polygon_edit->is_visible() || !_get_node()) { return; } @@ -1024,8 +1022,8 @@ void Polygon2DEditor::_uv_draw() { String warning; Transform2D mtx; - mtx.columns[2] = -uv_draw_ofs * uv_draw_zoom; - mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom)); + mtx.columns[2] = -draw_offset * draw_zoom; + mtx.scale_basis(Vector2(draw_zoom, draw_zoom)); // Draw texture as a background if editing uvs or no uv mapping exist. if (current_mode == MODE_UV || selected_action == ACTION_CREATE || node->get_polygon().is_empty() || node->get_uv().size() != node->get_polygon().size()) { @@ -1033,9 +1031,9 @@ void Polygon2DEditor::_uv_draw() { Transform2D texture_transform = Transform2D(node->get_texture_rotation(), node->get_texture_offset()); texture_transform.scale(node->get_texture_scale()); texture_transform.affine_invert(); - RS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), mtx * texture_transform); - uv_edit_draw->draw_texture(base_tex, Point2()); - RS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), Transform2D()); + RS::get_singleton()->canvas_item_add_set_transform(canvas->get_canvas_item(), mtx * texture_transform); + canvas->draw_texture(base_tex, Point2()); + RS::get_singleton()->canvas_item_add_set_transform(canvas->get_canvas_item(), Transform2D()); } preview_polygon->hide(); } else { @@ -1062,7 +1060,7 @@ void Polygon2DEditor::_uv_draw() { if (snap_show_grid) { Color grid_color = Color(1.0, 1.0, 1.0, 0.15); - Size2 s = uv_edit_draw->get_size(); + Size2 s = canvas->get_size(); int last_cell = 0; if (snap_step.x != 0) { @@ -1072,7 +1070,7 @@ void Polygon2DEditor::_uv_draw() { last_cell = cell; } if (last_cell != cell) { - uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), grid_color, Math::round(EDSCALE)); + canvas->draw_line(Point2(i, 0), Point2(i, s.height), grid_color, Math::round(EDSCALE)); } last_cell = cell; } @@ -1085,7 +1083,7 @@ void Polygon2DEditor::_uv_draw() { last_cell = cell; } if (last_cell != cell) { - uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), grid_color, Math::round(EDSCALE)); + canvas->draw_line(Point2(0, i), Point2(s.width, i), grid_color, Math::round(EDSCALE)); } last_cell = cell; } @@ -1140,16 +1138,16 @@ void Polygon2DEditor::_uv_draw() { for (int i = 0; i < uvs.size(); i++) { int next = uv_draw_max > 0 ? (i + 1) % uv_draw_max : 0; - if (i < uv_draw_max && uv_drag && current_action == ACTION_EDIT_POINT && EDITOR_GET("editors/polygon_editor/show_previous_outline")) { - uv_edit_draw->draw_line(mtx.xform(points_prev[i]), mtx.xform(points_prev[next]), prev_color, Math::round(EDSCALE)); + if (i < uv_draw_max && is_dragging && current_action == ACTION_EDIT_POINT && EDITOR_GET("editors/polygon_editor/show_previous_outline")) { + canvas->draw_line(mtx.xform(editing_points[i]), mtx.xform(editing_points[next]), prev_color, Math::round(EDSCALE)); } Vector2 next_point = uvs[next]; - if (uv_create && i == uvs.size() - 1) { - next_point = uv_create_to; + if (is_creating && i == uvs.size() - 1) { + next_point = create_to; } if (i < uv_draw_max) { // If using or creating polygons, do not show outline (will show polygons instead). - uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), poly_line_color, Math::round(EDSCALE)); + canvas->draw_line(mtx.xform(uvs[i]), mtx.xform(next_point), poly_line_color, Math::round(EDSCALE)); } } @@ -1169,10 +1167,10 @@ void Polygon2DEditor::_uv_draw() { if (idx_next < 0 || idx_next >= uvs.size()) { continue; } - uv_edit_draw->draw_line(mtx.xform(uvs[idx]), mtx.xform(uvs[idx_next]), polygon_line_color, Math::round(EDSCALE)); + canvas->draw_line(mtx.xform(uvs[idx]), mtx.xform(uvs[idx_next]), polygon_line_color, Math::round(EDSCALE)); } if (points.size() >= 3) { - uv_edit_draw->draw_colored_polygon(polypoints, polygon_fill_color); + canvas->draw_colored_polygon(polypoints, polygon_fill_color); } } @@ -1180,13 +1178,13 @@ void Polygon2DEditor::_uv_draw() { if (weight_r) { Vector2 draw_pos = mtx.xform(uvs[i]); float weight = weight_r[i]; - uv_edit_draw->draw_rect(Rect2(draw_pos - Vector2(2, 2) * EDSCALE, Vector2(5, 5) * EDSCALE), Color(weight, weight, weight, 1.0), Math::round(EDSCALE)); + canvas->draw_rect(Rect2(draw_pos - Vector2(2, 2) * EDSCALE, Vector2(5, 5) * EDSCALE), Color(weight, weight, weight, 1.0), Math::round(EDSCALE)); } else { if (i < uv_draw_max) { - uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5); + canvas->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5); } else { // Internal vertex - uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5, Color(0.6, 0.8, 1)); + canvas->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5, Color(0.6, 0.8, 1)); } } } @@ -1194,8 +1192,8 @@ void Polygon2DEditor::_uv_draw() { if (polygon_create.size()) { for (int i = 0; i < polygon_create.size(); i++) { Vector2 from = uvs[polygon_create[i]]; - Vector2 to = (i + 1) < polygon_create.size() ? uvs[polygon_create[i + 1]] : uv_create_to; - uv_edit_draw->draw_line(mtx.xform(from), mtx.xform(to), polygon_line_color, Math::round(EDSCALE)); + Vector2 to = (i + 1) < polygon_create.size() ? uvs[polygon_create[i + 1]] : create_to; + canvas->draw_line(mtx.xform(from), mtx.xform(to), polygon_line_color, Math::round(EDSCALE)); } } @@ -1236,8 +1234,8 @@ void Polygon2DEditor::_uv_draw() { Transform2D endpoint_xform = bone_xform * n->get_transform(); Color color = current ? Color(1, 1, 1) : Color(0.5, 0.5, 0.5); - uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), Math::round((current ? 5 : 4) * EDSCALE)); - uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), color, Math::round((current ? 3 : 2) * EDSCALE)); + canvas->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), Math::round((current ? 5 : 4) * EDSCALE)); + canvas->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), color, Math::round((current ? 3 : 2) * EDSCALE)); } if (!found_child) { @@ -1246,14 +1244,14 @@ void Polygon2DEditor::_uv_draw() { Transform2D endpoint_xform = bone_xform * Transform2D(0, Vector2(bone->get_length(), 0)).rotated(bone->get_bone_angle()); Color color = current ? Color(1, 1, 1) : Color(0.5, 0.5, 0.5); - uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), Math::round((current ? 5 : 4) * EDSCALE)); - uv_edit_draw->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), color, Math::round((current ? 3 : 2) * EDSCALE)); + canvas->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), Color(0, 0, 0), Math::round((current ? 5 : 4) * EDSCALE)); + canvas->draw_line(mtx.xform(bone_xform.get_origin()), mtx.xform(endpoint_xform.get_origin()), color, Math::round((current ? 3 : 2) * EDSCALE)); } } } //draw paint circle - uv_edit_draw->draw_circle(bone_paint_pos, bone_paint_radius->get_value() * EDSCALE, Color(1, 1, 1, 0.1)); + canvas->draw_circle(bone_paint_pos, bone_paint_radius->get_value() * EDSCALE, Color(1, 1, 1, 0.1)); } } @@ -1264,8 +1262,8 @@ void Polygon2DEditor::_bind_methods() { Vector2 Polygon2DEditor::snap_point(Vector2 p_target) const { if (use_snap) { - p_target.x = Math::snap_scalar((snap_offset.x - uv_draw_ofs.x) * uv_draw_zoom, snap_step.x * uv_draw_zoom, p_target.x); - p_target.y = Math::snap_scalar((snap_offset.y - uv_draw_ofs.y) * uv_draw_zoom, snap_step.y * uv_draw_zoom, p_target.y); + p_target.x = Math::snap_scalar((snap_offset.x - draw_offset.x) * draw_zoom, snap_step.x * draw_zoom, p_target.x); + p_target.y = Math::snap_scalar((snap_offset.y - draw_offset.y) * draw_zoom, snap_step.y * draw_zoom, p_target.y); } return p_target; @@ -1279,7 +1277,7 @@ Polygon2DEditor::Polygon2DEditor() { snap_show_grid = EditorSettings::get_singleton()->get_project_metadata("polygon_2d_uv_editor", "show_grid", false); selected_action = ACTION_EDIT_POINT; - uv_edit = memnew(VBoxContainer); + polygon_edit = memnew(VBoxContainer); HBoxContainer *uv_mode_hb = memnew(HBoxContainer); Ref mode_button_group; @@ -1299,7 +1297,7 @@ Polygon2DEditor::Polygon2DEditor() { uv_mode_hb->add_child(memnew(VSeparator)); - uv_edit->add_child(uv_mode_hb); + polygon_edit->add_child(uv_mode_hb); for (int i = 0; i < ACTION_MAX; i++) { action_buttons[i] = memnew(Button); action_buttons[i]->set_theme_type_variation(SceneStringName(FlatButton)); @@ -1355,38 +1353,38 @@ Polygon2DEditor::Polygon2DEditor() { bone_paint_radius->set_value(32); HSplitContainer *uv_main_hsc = memnew(HSplitContainer); - uv_edit->add_child(uv_main_hsc); + polygon_edit->add_child(uv_main_hsc); uv_main_hsc->set_v_size_flags(SIZE_EXPAND_FILL); - uv_edit_background = memnew(Panel); - uv_main_hsc->add_child(uv_edit_background); - uv_edit_background->set_h_size_flags(SIZE_EXPAND_FILL); - uv_edit_background->set_custom_minimum_size(Size2(200, 200) * EDSCALE); - uv_edit_background->set_clip_contents(true); + canvas_background = memnew(Panel); + uv_main_hsc->add_child(canvas_background); + canvas_background->set_h_size_flags(SIZE_EXPAND_FILL); + canvas_background->set_custom_minimum_size(Size2(200, 200) * EDSCALE); + canvas_background->set_clip_contents(true); preview_polygon = memnew(Polygon2D); - uv_edit_background->add_child(preview_polygon); + canvas_background->add_child(preview_polygon); - uv_edit_draw = memnew(Control); - uv_edit_background->add_child(uv_edit_draw); - uv_edit_draw->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); + canvas = memnew(Control); + canvas_background->add_child(canvas); + canvas->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); Control *space = memnew(Control); uv_mode_hb->add_child(space); space->set_h_size_flags(SIZE_EXPAND_FILL); - uv_menu = memnew(MenuButton); - uv_mode_hb->add_child(uv_menu); - uv_menu->set_flat(false); - uv_menu->set_theme_type_variation("FlatMenuButton"); - uv_menu->set_text(TTR("Edit")); - uv_menu->get_popup()->add_item(TTR("Copy Polygon to UV"), MENU_POLYGON_TO_UV); - uv_menu->get_popup()->add_item(TTR("Copy UV to Polygon"), MENU_UV_TO_POLYGON); - uv_menu->get_popup()->add_separator(); - uv_menu->get_popup()->add_item(TTR("Clear UV"), MENU_UV_CLEAR); - uv_menu->get_popup()->add_separator(); - uv_menu->get_popup()->add_item(TTR("Grid Settings"), MENU_GRID_SETTINGS); - uv_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &Polygon2DEditor::_edit_menu_option)); + edit_menu = memnew(MenuButton); + uv_mode_hb->add_child(edit_menu); + edit_menu->set_flat(false); + edit_menu->set_theme_type_variation("FlatMenuButton"); + edit_menu->set_text(TTR("Edit")); + edit_menu->get_popup()->add_item(TTR("Copy Polygon to UV"), MENU_POLYGON_TO_UV); + edit_menu->get_popup()->add_item(TTR("Copy UV to Polygon"), MENU_UV_TO_POLYGON); + edit_menu->get_popup()->add_separator(); + edit_menu->get_popup()->add_item(TTR("Clear UV"), MENU_UV_CLEAR); + edit_menu->get_popup()->add_separator(); + edit_menu->get_popup()->add_item(TTR("Grid Settings"), MENU_GRID_SETTINGS); + edit_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &Polygon2DEditor::_edit_menu_option)); uv_mode_hb->add_child(memnew(VSeparator)); @@ -1412,7 +1410,7 @@ Polygon2DEditor::Polygon2DEditor() { grid_settings = memnew(AcceptDialog); grid_settings->set_title(TTR("Configure Grid:")); - uv_edit->add_child(grid_settings); + polygon_edit->add_child(grid_settings); VBoxContainer *grid_settings_vb = memnew(VBoxContainer); grid_settings->add_child(grid_settings_vb); @@ -1453,19 +1451,19 @@ Polygon2DEditor::Polygon2DEditor() { grid_settings_vb->add_margin_child(TTR("Grid Step Y:"), sb_step_y); zoom_widget = memnew(EditorZoomWidget); - uv_edit_draw->add_child(zoom_widget); + canvas->add_child(zoom_widget); zoom_widget->set_anchors_and_offsets_preset(Control::PRESET_TOP_LEFT, Control::PRESET_MODE_MINSIZE, 2 * EDSCALE); zoom_widget->connect("zoom_changed", callable_mp(this, &Polygon2DEditor::_update_zoom_and_pan).unbind(1).bind(true)); zoom_widget->set_shortcut_context(nullptr); - uv_vscroll = memnew(VScrollBar); - uv_vscroll->set_step(0.001); - uv_edit_draw->add_child(uv_vscroll); - uv_vscroll->connect(SceneStringName(value_changed), callable_mp(this, &Polygon2DEditor::_update_zoom_and_pan).unbind(1).bind(false)); - uv_hscroll = memnew(HScrollBar); - uv_hscroll->set_step(0.001); - uv_edit_draw->add_child(uv_hscroll); - uv_hscroll->connect(SceneStringName(value_changed), callable_mp(this, &Polygon2DEditor::_update_zoom_and_pan).unbind(1).bind(false)); + vscroll = memnew(VScrollBar); + vscroll->set_step(0.001); + canvas->add_child(vscroll); + vscroll->connect(SceneStringName(value_changed), callable_mp(this, &Polygon2DEditor::_update_zoom_and_pan).unbind(1).bind(false)); + hscroll = memnew(HScrollBar); + hscroll->set_step(0.001); + canvas->add_child(hscroll); + hscroll->connect(SceneStringName(value_changed), callable_mp(this, &Polygon2DEditor::_update_zoom_and_pan).unbind(1).bind(false)); bone_scroll_main_vb = memnew(VBoxContainer); bone_scroll_main_vb->hide(); @@ -1483,17 +1481,17 @@ Polygon2DEditor::Polygon2DEditor() { bone_scroll_vb = memnew(VBoxContainer); bone_scroll->add_child(bone_scroll_vb); - uv_panner.instantiate(); - uv_panner->set_callbacks(callable_mp(this, &Polygon2DEditor::_uv_pan_callback), callable_mp(this, &Polygon2DEditor::_uv_zoom_callback)); + panner.instantiate(); + panner->set_callbacks(callable_mp(this, &Polygon2DEditor::_pan_callback), callable_mp(this, &Polygon2DEditor::_zoom_callback)); - uv_edit_draw->connect(SceneStringName(draw), callable_mp(this, &Polygon2DEditor::_uv_draw)); - uv_edit_draw->connect(SceneStringName(gui_input), callable_mp(this, &Polygon2DEditor::_uv_input)); - uv_edit_draw->connect(SceneStringName(focus_exited), callable_mp(uv_panner.ptr(), &ViewPanner::release_pan_key)); - uv_edit_draw->set_focus_mode(FOCUS_CLICK); - uv_draw_zoom = 1.0; + canvas->connect(SceneStringName(draw), callable_mp(this, &Polygon2DEditor::_canvas_draw)); + canvas->connect(SceneStringName(gui_input), callable_mp(this, &Polygon2DEditor::_canvas_input)); + canvas->connect(SceneStringName(focus_exited), callable_mp(panner.ptr(), &ViewPanner::release_pan_key)); + canvas->set_focus_mode(FOCUS_CLICK); + draw_zoom = 1.0; point_drag_index = -1; - uv_drag = false; - uv_create = false; + is_dragging = false; + is_creating = false; bone_painting = false; error = memnew(AcceptDialog); diff --git a/editor/plugins/polygon_2d_editor_plugin.h b/editor/plugins/polygon_2d_editor_plugin.h index 187b20a57bd3..ef88b4fdaeec 100644 --- a/editor/plugins/polygon_2d_editor_plugin.h +++ b/editor/plugins/polygon_2d_editor_plugin.h @@ -82,24 +82,27 @@ class Polygon2DEditor : public AbstractPolygon2DEditor { Polygon2D *node = nullptr; - VBoxContainer *uv_edit = nullptr; + VBoxContainer *polygon_edit = nullptr; Mode current_mode; Button *mode_buttons[MODE_MAX]; Action selected_action; Button *action_buttons[ACTION_MAX]; Button *b_snap_enable = nullptr; Button *b_snap_grid = nullptr; - Panel *uv_edit_background = nullptr; + MenuButton *edit_menu = nullptr; + + Control *canvas = nullptr; + Panel *canvas_background = nullptr; Polygon2D *preview_polygon = nullptr; - Control *uv_edit_draw = nullptr; EditorZoomWidget *zoom_widget = nullptr; - HScrollBar *uv_hscroll = nullptr; - VScrollBar *uv_vscroll = nullptr; - MenuButton *uv_menu = nullptr; + HScrollBar *hscroll = nullptr; + VScrollBar *vscroll = nullptr; - Ref uv_panner; - void _uv_pan_callback(Vector2 p_scroll_vec, Ref p_event); - void _uv_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref p_event); + Ref panner; + void _pan_callback(Vector2 p_scroll_vec, Ref p_event); + void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref p_event); + Vector2 draw_offset; + real_t draw_zoom; VBoxContainer *bone_scroll_main_vb = nullptr; ScrollContainer *bone_scroll = nullptr; @@ -117,23 +120,21 @@ class Polygon2DEditor : public AbstractPolygon2DEditor { void _sync_bones(); void _update_bone_list(); - Vector2 uv_draw_ofs; - real_t uv_draw_zoom; - Vector points_prev; - Vector uv_create_uv_prev; - Vector uv_create_poly_prev; - Vector uv_create_colors_prev; - int uv_create_prev_internal_vertices = 0; - Array uv_create_bones_prev; - Array polygons_prev; - - Vector2 uv_create_to; + Vector editing_points; + Vector previous_uv; + Vector previous_polygon; + Vector previous_colors; + int previous_internal_vertices = 0; + Array previous_bones; + Array previous_polygons; + + Vector2 create_to; int point_drag_index; - bool uv_drag; - bool uv_create; + bool is_dragging; + bool is_creating; Vector polygon_create; Action current_action; - Vector2 uv_drag_from; + Vector2 drag_from; AcceptDialog *error = nullptr; @@ -150,8 +151,8 @@ class Polygon2DEditor : public AbstractPolygon2DEditor { void _center_view(); void _update_zoom_and_pan(bool p_zoom_at_center); - void _uv_input(const Ref &p_input); - void _uv_draw(); + void _canvas_input(const Ref &p_input); + void _canvas_draw(); void _set_action(int p_mode); void _set_use_snap(bool p_use);