Merge pull request #82853 from KoBeWi/line_surgery

Prioritize points in polygon editor hover
This commit is contained in:
Rémi Verschelde 2023-10-27 11:36:09 +02:00
commit d88ef223e3
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -289,43 +289,40 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event)
return false;
}
const PosVertex insert = closest_edge_point(gpoint);
if (insert.valid()) {
Vector<Vector2> 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);
selected_point = Vertex();
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();
const PosVertex insert = closest_edge_point(gpoint);
if (insert.valid()) {
Vector<Vector2> 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<InputEvent> &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();
}
}
}