Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Nikitf777
Copy link
Contributor

@Nikitf777 Nikitf777 commented Jun 23, 2025

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.

@AdriaandeJongh
Copy link
Contributor

AdriaandeJongh commented Jun 23, 2025

Does this also apply to the polygon editor in the scene view? If not, it should!

@Nikitf777
Copy link
Contributor Author

If I understand correctly what you mean, it seems like it was already implemented.

polygon2d-editor-highlighting-2.mp4

@AdriaandeJongh
Copy link
Contributor

Ah, yup! Maybe use the same colors then?

@Nikitf777
Copy link
Contributor Author

Nikitf777 commented Jun 23, 2025

But they already look differenlty in a few ways. So I don't think that the color must be the same.
image

Also, when you add an internal vertex, you lose the ability to view and edit it in the scene view. So making the highlighted color of internal vertices the same, as in scene view, is impossible (because there're no internal vertices in the scene view).
image

A much closer reference is the AnimationPlayer editor. But it applies the same (or almost the same) color, that the Polygon2D editor uses for unhighlighted internal vertices:

animation-player-highlight.mp4

@smix8
Copy link
Contributor

smix8 commented Jun 23, 2025

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

@Nikitf777 Nikitf777 force-pushed the polygon2d-editor-highlighting branch from 9bf2e67 to c6c305d Compare June 23, 2025 13:57
@Nikitf777
Copy link
Contributor Author

Nikitf777 commented Jun 23, 2025

Should be switched to use static meshes and multimeshes like done for Path2D editor in PR #105606

Do you think I should apply the same fix in this PR? It's a little bit out of its scope.

@smix8
Copy link
Contributor

smix8 commented Jun 23, 2025

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.

@@ -135,6 +135,7 @@ class Polygon2DEditor : public AbstractPolygon2DEditor {
int point_drag_index = -1;
bool is_dragging = false;
bool is_creating = false;
int highlighted_point = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int highlighted_point = -1;
int hovered_point = -1;

More accurate.

@@ -776,6 +779,41 @@ void Polygon2DEditor::_canvas_input(const Ref<InputEvent> &p_input) {
Ref<InputEventMouseMotion> mm = p_input;

if (mm.is_valid()) {
// Highlight a point near the cursor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Highlight a point near the cursor
// Highlight a point near the cursor.

@Nikitf777 Nikitf777 force-pushed the polygon2d-editor-highlighting branch from ec5ca6e to 8ea9fbb Compare June 28, 2025 17:26
@KoBeWi KoBeWi modified the milestones: 4.x, 4.6 Jun 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants