jaquadro / LilyPath

A 2D path and shape drawing library for MonoGame and XNA.
MIT License
93 stars 12 forks source link

Path outline #4

Closed ischyrus closed 10 years ago

ischyrus commented 10 years ago

Not sure how easy it would be. I need draw a path and rather than have the resulting line\path filled, just have it be outlined.

ischyrus commented 10 years ago

I can actually get really close to what I need with a GradientPen.

If I set the Pen's alignment to Inset and then draw the path, then draw another path using the points in reverse it gives me an outline of a path. The only change I would need at this point is to have a gradient pen that can have more stops.

Here is what I have now.

untitled

jaquadro commented 10 years ago

Well, I can see why it might be desirable to have an outline. There isn't really an easy way to add this. I have an idea that that would tack this responsibility onto PathBuilder, so you could derive a new path representing the outline. I have a little time this evening to try playing around with the idea and see if it goes anywhere.

Adding new gradient points would be difficult, because the path would need to be tessellated with new interior vertices to hold the intermediate color control points. Not impossible, but would require significant effort.

If you can make a few assumptions, I think you can get around this with a dirty hack. As long as you stick with mitered joins, and your do not exceed the miter limit (turn really sharp points into bevels), then once you stroke a PathBuilder (or vector list) to obtain a GraphicsPath, you can access the underlying VertexPositionData array. Sticking with the above assumptions, every odd vertex in the array will define the path for one edge of the figure, and every even vertex will define the path for the other edge. Pull these apart into separate vector lists, and then use them to construct new GraphicsPaths that represent your stroked outlines. If you're trying to do this with a path that is not closed, then you'll have to append those lists together and create a single GraphicsPath instead.

jaquadro commented 10 years ago

I've got an implementation of outline stroking mostly working, I'll probably have something pushed up in a day or two.

ischyrus commented 10 years ago

That's awesome. Thanks for all your efforts and the library.

jaquadro commented 10 years ago

I've pushed up a set of changes that adds a new set of GraphicsPath constructors with a second Pen parameter for outline stroke. The fill pen is still required, though I intend to make it optional going forward. In the meantime you can take the small performance hit and use a transparent pen.

The test sheets are still rendering correctly, but I had to change a lot of path stroking code, so I'd be surprised if there aren't a few bugs creeping around.

jaquadro commented 10 years ago

Outline support is now complete and can be used independent of standard path stroke (on GraphicsPath only).

lilypathoutline