-
-
Notifications
You must be signed in to change notification settings - Fork 23.9k
Highlight points on hover in the Polygon2D editor #107890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highlight points on hover in the Polygon2D editor #107890
Conversation
|
Does this also apply to the polygon editor in the scene view? If not, it should! |
|
If I understand correctly what you mean, it seems like it was already implemented. polygon2d-editor-highlighting-2.mp4 |
|
Ah, yup! Maybe use the same colors then? |
|
The main performance problem of Polygon2D editor is because it still uses the inefficient canvas draw functions for every single line and handle texture, aka every single vertex edge segment is its own canvas item and draw in the editor. It basically creates a new throwaway mesh for every single handle point that it deletes on the next redraw, oc performance is bad with that on larger polygons. Should be switched to use static meshes and multimeshes like done for Path2D editor in PR #105606 |
9bf2e67 to
c6c305d
Compare
Do you think I should apply the same fix in this PR? It's a little bit out of its scope. |
Nono that is very much out of scope and should be its own PR. That was in response to the comment about performance. |
8f7d6c0 to
ec5ca6e
Compare
| int point_drag_index = -1; | ||
| bool is_dragging = false; | ||
| bool is_creating = false; | ||
| int highlighted_point = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| int highlighted_point = -1; | |
| int hovered_point = -1; |
More accurate.
| Ref<InputEventMouseMotion> mm = p_input; | ||
|
|
||
| if (mm.is_valid()) { | ||
| // Highlight a point near the cursor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Highlight a point near the cursor | |
| // Highlight a point near the cursor. |
ec5ca6e to
8ea9fbb
Compare
|
There is actually a minor bug. When you undo deleting a point, it's not immediately hovered: qa75H4PB1Q.mp4 |
|
Well, I wouldn't even call it a bug. It's a normal behavior for this kind of thing. the-same-behavior.mp4 |
|
Also there is a similar "bug" in the GNOME desktop: Screencast.From.2025-06-30.15-11-25.mp4 |
Nikitf777
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I should make another push
|
|
||
| if (mm.is_valid()) { | ||
| // Highlight a point near the cursor. | ||
| if (current_mode == MODE_POINTS || current_mode == MODE_POLYGONS || current_mode == MODE_UV) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to check for selected_action == ACTION_... here
| } else { | ||
| Color mod(1, 1, 1); | ||
| Color highlight = Color(0.35, 0.35, 0.35, 0); | ||
| if (i >= uv_draw_max) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I can split this code into three separate loops to avoid checking for wight_r and i >= uv_draw_max on every iteration and to simplify logic:
if (weight_r) {
for (int i = 0; i < uvs.size(); i++) {
Vector2 draw_pos = mtx.xform(uvs[i]);
float weight = weight_r[i];
canvas->draw_rect(Rect2(draw_pos - Vector2(2, 2) * EDSCALE, Vector2(5, 5) * EDSCALE), Color(weight, weight, weight, 1.0), Math::round(EDSCALE));
}
} else {
Vector2 texture_size_half = handle->get_size() * 0.5;
for (int i = 0; i < uv_draw_max; i++) {
Color mod(1, 1, 1);
if (i == hovered_point && selected_action != ACTION_REMOVE_INTERNAL) {
mod = Color(0.63, 0.63, 0.63);
}
canvas->draw_texture(handle, mtx.xform(uvs[i]) - texture_size_half, mod);
}
// Internal vertices.
for (int i = uv_draw_max; i < uvs.size(); i++) {
Color mod(0.6, 0.8, 1);
if (i == hovered_point) {
mod = Color(0.35, 0.55, 0.75);
}
canvas->draw_texture(handle, mtx.xform(uvs[i]) - texture_size_half, mod);
}
}8ea9fbb to
857288d
Compare
|
Now this code even more optimized that before the PR |
857288d to
0d5da4b
Compare
|
Needs rebase |
0d5da4b to
209986b
Compare
|
Thanks! |


The Polygon2D editor now highlights a point, if it's near the mouse cursor. It especially useful on touchpads, where it's much harder to aim.
But I was surprised how much it improves the mouse experience as well. And now I don't want to go back to the previuos behavior, because it was awful.
However, the Polygon2D editor is far from perfect and still needs a few improvements.
polygon2d-editor-highlighting.mp4
The downside of this improvement is performance, because now the editor needs to redraw more often and iterate through the array of points on every mouse move. However, it's well optimized, because it redraws only when the highlighted point is changed and avoids looping when is_creating is true, checking only the first point.