Skip to content

Commit c6c305d

Browse files
committed
Highlight points on hover in the Polygon2D editor
1 parent d7bdc0b commit c6c305d

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

editor/plugins/polygon_2d_editor_plugin.cpp

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ void Polygon2DEditor::_canvas_input(const Ref<InputEvent> &p_input) {
589589
if (closest == -1) {
590590
return;
591591
}
592+
if (closest == highlighed_point) {
593+
highlighed_point = -1;
594+
}
592595

593596
previous_polygon.remove_at(closest);
594597
previous_uv.remove_at(closest);
@@ -776,6 +779,38 @@ void Polygon2DEditor::_canvas_input(const Ref<InputEvent> &p_input) {
776779
Ref<InputEventMouseMotion> mm = p_input;
777780

778781
if (mm.is_valid()) {
782+
// Highlight a point near the cursor
783+
if (current_mode == MODE_POINTS || current_mode == MODE_POLYGONS || current_mode == MODE_UV) {
784+
if (is_creating) {
785+
if (editing_points.size() > 2 && mtx.affine_inverse().xform(mm->get_position()).distance_to(node->get_polygon()[0]) < (8 / draw_zoom)) {
786+
highlighed_point = 0;
787+
canvas->queue_redraw();
788+
}
789+
} else {
790+
Vector<Vector2> points;
791+
if (current_mode == MODE_POINTS || current_mode == MODE_POLYGONS) {
792+
points = node->get_polygon();
793+
} else {
794+
points = node->get_uv();
795+
}
796+
int i = points.size() - 1;
797+
for (; i >= 0; i--) {
798+
if (mtx.affine_inverse().xform(mm->get_position()).distance_to(points[i]) < (8 / draw_zoom)) {
799+
if (highlighed_point != i) {
800+
highlighed_point = i;
801+
canvas->queue_redraw();
802+
}
803+
break;
804+
}
805+
}
806+
if (i == -1) {
807+
if (highlighed_point >= 0) {
808+
highlighed_point = -1;
809+
canvas->queue_redraw();
810+
}
811+
}
812+
}
813+
}
779814
if (is_dragging) {
780815
Vector2 uv_drag_to = mm->get_position();
781816
uv_drag_to = snap_point(uv_drag_to);
@@ -1179,12 +1214,17 @@ void Polygon2DEditor::_canvas_draw() {
11791214
float weight = weight_r[i];
11801215
canvas->draw_rect(Rect2(draw_pos - Vector2(2, 2) * EDSCALE, Vector2(5, 5) * EDSCALE), Color(weight, weight, weight, 1.0), Math::round(EDSCALE));
11811216
} else {
1182-
if (i < uv_draw_max) {
1183-
canvas->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5);
1184-
} else {
1217+
Color mod(1, 1, 1);
1218+
Color highlight = Color(0.4, 0.4, 0.4, 0);
1219+
if (i >= uv_draw_max) {
11851220
// Internal vertex
1186-
canvas->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5, Color(0.6, 0.8, 1));
1221+
mod = Color(0.6, 0.8, 1);
1222+
highlight = Color(0.25, 0.25, 0.25, 0);
1223+
}
1224+
if (i == highlighed_point) {
1225+
mod -= Color(0.25, 0.25, 0.25, 0);
11871226
}
1227+
canvas->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5, mod);
11881228
}
11891229
}
11901230

editor/plugins/polygon_2d_editor_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class Polygon2DEditor : public AbstractPolygon2DEditor {
135135
int point_drag_index = -1;
136136
bool is_dragging = false;
137137
bool is_creating = false;
138+
int highlighed_point = -1;
138139
Vector<int> polygon_create;
139140
Action current_action = ACTION_CREATE;
140141
Vector2 drag_from;

0 commit comments

Comments
 (0)