Skip to content
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

Add anti alias support for linear Canvasitem draw primitives #84497

Closed

Conversation

xiongyaohua
Copy link
Contributor

@xiongyaohua xiongyaohua commented Nov 6, 2023

(This PR is an follow-up for #84472, kept as draft for now. see #84472 (comment))

Add anti alias to the following canvasitem draw primitives

  • unfilled circle and rect
  • multiline and dashed_line
func _draw():
	draw_circle(Vector2(100,100), 100, Color.BROWN, false, 10)
	draw_circle(Vector2(100,400), 100, Color.BROWN, false, 10, true)
	
	draw_rect(Rect2(400, 0, 200, 200), Color.AQUA, false, 10)
	draw_rect(Rect2(400, 300, 200, 200), Color.AQUA, false, 10, true)
	
	draw_dashed_line(Vector2(700, 0), Vector2(900, 200), Color.CADET_BLUE, 10, 20, true)
	draw_dashed_line(Vector2(700, 50), Vector2(900, 250), Color.CADET_BLUE, 10, 20, true, true)

image

Make it possible to draw unfilled circle, like draw_rect().
- unfilled rect and circle
- multiline and dashed_line
@xiongyaohua xiongyaohua requested review from a team as code owners November 6, 2023 02:06
@xiongyaohua xiongyaohua changed the title Add anti alias support for linear canvas items Add anti alias support for linear Canvasitem draw primitives Nov 6, 2023
@AThousandShips AThousandShips added this to the 4.x milestone Nov 7, 2023
@xiongyaohua xiongyaohua marked this pull request as draft November 8, 2023 02:55
Draws a circle. See also [method draw_arc], [method draw_polyline] and [method draw_polygon].
If [param filled] is [code]true[/code], the cricle will be filled with the [param color] specified. If [param filled] is [code]false[/code], the circle will be drawn as a stroke with the [param color] and [param width] specified.
If [param width] is negative, then two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive [param width] like [code]1.0[/code].
[b]Note:[/b] [param width] and [param antialiased] is only effective if [param filled] is [code]false[/code].
Copy link
Contributor

Choose a reason for hiding this comment

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

is -> are

<description>
Draws a rectangle. If [param filled] is [code]true[/code], the rectangle will be filled with the [param color] specified. If [param filled] is [code]false[/code], the rectangle will be drawn as a stroke with the [param color] and [param width] specified. See also [method draw_texture_rect].
If [param width] is negative, then two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive [param width] like [code]1.0[/code].
[b]Note:[/b] [param width] is only effective if [param filled] is [code]false[/code].
[b]Note:[/b] [param width] and [param antialiased] is only effective if [param filled] is [code]false[/code].
Copy link
Contributor

Choose a reason for hiding this comment

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

is -> are

@MewPurPur
Copy link
Contributor

MewPurPur commented Jan 9, 2024

Could you show how antialiased multiline looks? I'm also interested in how transparency affects its drawing

@xiongyaohua
Copy link
Contributor Author

xiongyaohua commented Jan 19, 2024

@MewPurPur The multiline drawing behaviour should be identical to the original line. Here are some examples.

func _draw():
	var points := [
		Vector2(100, 100),
		Vector2(200, 200),
		Vector2(400, 100),
		Vector2(500, 200),
	]
	var colors :=  [
		Color(1,0.5,0.5,0.2),
		Color(1,0.5,0.5,0.4),
		Color(1,0.5,0.5,0.6),
		Color(1,0.5,0.5,0.8)
	]
	#draw_multiline_colors(points, colors, 10, false)
	for i in range(4):
		var new_points := points.map(func(v): return v+Vector2(0, 30*i))
		draw_polyline_colors(new_points, colors, 2 + i*2, false)
		new_points = points.map(func(v): return v+Vector2(0, 200 + 30*i))
		draw_polyline_colors(new_points, colors, 2 + i*2, true)
		
		new_points = points.map(func(v): return v+Vector2(600, 30*i))
		draw_multiline_colors(new_points, [colors[3]], 2 + i*2, false)
		new_points = points.map(func(v): return v+Vector2(600, 200 + 30*i))
		draw_multiline_colors(new_points, [colors[3]], 2 + i*2, true)

Original Size:
Screenshot 2024-01-19 at 09 43 55
Enlarged:
Screenshot 2024-01-19 at 09 38 57

Copy link
Contributor

@MewPurPur MewPurPur left a comment

Choose a reason for hiding this comment

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

Reviewed the code, looks good to me.

@MewPurPur
Copy link
Contributor

Any updates on this?

@AThousandShips
Copy link
Member

It's intended as a follow-up to a PR that hasn't been merged yet, so see:

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Tested locally (rebased on top of master 6118592), it works as expected in all rendering methods.

Testing project: test-antialiased-rect-line.zip

output

Remember to add GDExtension compatibility methods as you did in #84472.

@Calinou
Copy link
Member

Calinou commented May 2, 2024

@xiongyaohua Now that #84472 has been merged, you should be able to rebase this PR onto the latest master branch.

@xiongyaohua
Copy link
Contributor Author

xiongyaohua commented May 9, 2024

@Calinou will do in the next week. And thanks for the test.

Now that #84472 has been merged, you should be able to rebase this PR onto the latest master branch.

@xiongyaohua
Copy link
Contributor Author

I'm going to close this PR, as all codes are incorporated into the following PR #84523. Review can be done over there.

@xiongyaohua xiongyaohua closed this May 9, 2024
@AThousandShips AThousandShips removed this from the 4.x milestone May 9, 2024
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