From 7cffb302544a98eaa998375eb5a3fbdba2226b52 Mon Sep 17 00:00:00 2001 From: kobewi Date: Thu, 5 Oct 2023 15:53:38 +0200 Subject: [PATCH] Prioritize points in polygon editor hover --- editor/plugins/abstract_polygon_2d_editor.cpp | 99 ++++++++++--------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index bc8c8f6f79a7..a15875fd93df 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -289,43 +289,40 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref &p_event) return false; } - const PosVertex insert = closest_edge_point(gpoint); - - if (insert.valid()) { - Vector vertices = _get_polygon(insert.polygon); - - if (vertices.size() < (_is_line() ? 2 : 3)) { - vertices.push_back(cpoint); - undo_redo->create_action(TTR("Edit Polygon")); - selected_point = Vertex(insert.polygon, vertices.size()); - _action_set_polygon(insert.polygon, vertices); - _commit_action(); - return true; - } else { - edited_point = PosVertex(insert.polygon, insert.vertex + 1, xform.affine_inverse().xform(insert.pos)); - vertices.insert(edited_point.vertex, edited_point.pos); - pre_move_edit = vertices; - selected_point = Vertex(edited_point.polygon, edited_point.vertex); - edge_point = PosVertex(); - - undo_redo->create_action(TTR("Insert Point")); - _action_set_polygon(insert.polygon, vertices); - _commit_action(); - return true; - } + const PosVertex closest = closest_point(gpoint); + if (closest.valid()) { + pre_move_edit = _get_polygon(closest.polygon); + edited_point = PosVertex(closest, xform.affine_inverse().xform(closest.pos)); + selected_point = closest; + edge_point = PosVertex(); + canvas_item_editor->update_viewport(); + return true; } else { - //look for points to move - const PosVertex closest = closest_point(gpoint); - - if (closest.valid()) { - pre_move_edit = _get_polygon(closest.polygon); - edited_point = PosVertex(closest, xform.affine_inverse().xform(closest.pos)); - selected_point = closest; - edge_point = PosVertex(); - canvas_item_editor->update_viewport(); - return true; - } else { - selected_point = Vertex(); + selected_point = Vertex(); + + const PosVertex insert = closest_edge_point(gpoint); + if (insert.valid()) { + Vector vertices = _get_polygon(insert.polygon); + + if (vertices.size() < (_is_line() ? 2 : 3)) { + vertices.push_back(cpoint); + undo_redo->create_action(TTR("Edit Polygon")); + selected_point = Vertex(insert.polygon, vertices.size()); + _action_set_polygon(insert.polygon, vertices); + _commit_action(); + return true; + } else { + edited_point = PosVertex(insert.polygon, insert.vertex + 1, xform.affine_inverse().xform(insert.pos)); + vertices.insert(edited_point.vertex, edited_point.pos); + pre_move_edit = vertices; + selected_point = Vertex(edited_point.polygon, edited_point.vertex); + edge_point = PosVertex(); + + undo_redo->create_action(TTR("Insert Point")); + _action_set_polygon(insert.polygon, vertices); + _commit_action(); + return true; + } } } } else { @@ -437,24 +434,28 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref &p_event) canvas_item_editor->update_viewport(); } else if (mode == MODE_EDIT || (_is_line() && mode == MODE_CREATE)) { - const PosVertex onEdgeVertex = closest_edge_point(gpoint); - - if (onEdgeVertex.valid()) { - hover_point = Vertex(); - edge_point = onEdgeVertex; + const PosVertex new_hover_point = closest_point(gpoint); + if (hover_point != new_hover_point) { + hover_point = new_hover_point; canvas_item_editor->update_viewport(); - } else { - if (edge_point.valid()) { - edge_point = PosVertex(); - canvas_item_editor->update_viewport(); - } + } - const PosVertex new_hover_point = closest_point(gpoint); - if (hover_point != new_hover_point) { - hover_point = new_hover_point; + bool edge_hover = false; + if (!hover_point.valid()) { + const PosVertex on_edge_vertex = closest_edge_point(gpoint); + + if (on_edge_vertex.valid()) { + hover_point = Vertex(); + edge_point = on_edge_vertex; canvas_item_editor->update_viewport(); + edge_hover = true; } } + + if (!edge_hover && edge_point.valid()) { + edge_point = PosVertex(); + canvas_item_editor->update_viewport(); + } } }