Skip to content

Commit

Permalink
Merge pull request #82853 from KoBeWi/line_surgery
Browse files Browse the repository at this point in the history
Prioritize points in polygon editor hover
  • Loading branch information
akien-mga committed Oct 27, 2023
2 parents 8919d1c + 7cffb30 commit d88ef22
Showing 1 changed file with 50 additions and 49 deletions.
99 changes: 50 additions & 49 deletions editor/plugins/abstract_polygon_2d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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<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 {
Expand Down Expand Up @@ -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();
}
}
}

Expand Down

0 comments on commit d88ef22

Please sign in to comment.