jaquadro / LilyPath

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

Dashed line #6

Open ischyrus opened 10 years ago

ischyrus commented 10 years ago

I could really use a dashed line, at least only for straight lines. Would that be an enhancement that could be added?

jaquadro commented 10 years ago

I've thought about it on and off. There might be a decent texture-based approach, otherwise it's a more computationally expensive segmenting of the lines.

If you want dashed single line-segments, you could use the workaround of a striped texture brush and a texture matrix transform to align the texture to repeat the texture along the length of the line. Obviously won't work if you have a multi-segment path, straight or not.

ischyrus commented 10 years ago

I have several segments, I was thinking about just drawing lines along the path between points. I'm not really worried about the intersections lining up perfectly. It might not give the best performance, but in my scenario it's not a huge issue as the resulting texture is cached and the content isn't dynamic so it's just an initial loading cost. I'm also dealing with a relatively small number of these dashed lines.

ischyrus commented 10 years ago

It ended up working out pretty well: untitled-1

jaquadro commented 10 years ago

Great - if it does the job you need it to, that's what counts.

I will leave this issue open though, as I'm going to look more into it. I already laid some of the necessary groundwork that will be useful for things like path length gradients as well.