Skip to content

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.

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.

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
@KoBeWi
Copy link
Member

KoBeWi commented Jun 30, 2025

There is actually a minor bug. When you undo deleting a point, it's not immediately hovered:

qa75H4PB1Q.mp4

@Nikitf777
Copy link
Contributor Author

Well, I wouldn't even call it a bug. It's a normal behavior for this kind of thing.
Here is the same thing:

the-same-behavior.mp4

@Nikitf777
Copy link
Contributor Author

Nikitf777 commented Jun 30, 2025

Also there is a similar "bug" in the GNOME desktop:

Screencast.From.2025-06-30.15-11-25.mp4

Copy link
Contributor Author

@Nikitf777 Nikitf777 left a 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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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);
		}
	}

@Nikitf777 Nikitf777 force-pushed the polygon2d-editor-highlighting branch from 8ea9fbb to 857288d Compare July 2, 2025 22:20
@Nikitf777
Copy link
Contributor Author

Now this code even more optimized that before the PR

@Repiteo
Copy link
Contributor

Repiteo commented Nov 14, 2025

Needs rebase

@Nikitf777 Nikitf777 force-pushed the polygon2d-editor-highlighting branch from 0d5da4b to 209986b Compare November 14, 2025 20:43
@Repiteo Repiteo merged commit d5c0a11 into godotengine:master Nov 14, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 14, 2025

Thanks!

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.

5 participants