R – Drawing lines in win32/GDI with a custom pen style

gdi+graphicswinapiwindows

I have a need to do some drawing using win32/GDI (Native, not .NET), and I've run into the following problem:

I need to draw lines that are "styled." For example, in the attached image, the line marked "A" is a straight line as far as my application data is concerned, it just needs to be drawn with the additional zigzag as a style. Of course, this is easy to do programatically, but it gets more complicated when the line can be at any angle ("B") or even a bezier curve ("C").

Now, I could do this all programatically, painstakingly doing the math to put a zigzag around each line possibility, but that will take a lot of time and, more importantly, be rather error prone.

Is it possible to just give windows/GDI a "style" to apply to the line, perhaps a bitmap like the one marked "D", and have it use that as a pen to draw the lines? If not, is there a more flexible and less error-prone way of doing this than writing a bunch of specific drawing code for each of the "styled" lines?

*Apparently first timers can't post images. Examples can be found at http://i.imgur.com/IC0T2.png

Best Answer

This is not possible in Win32 GDI. You will need to do the math yourself.

It should be noted however, that you can obtain the points used to make up the line or curve which should make it substantially easier.

See this "Hit-Testing" tutorial for an example.

For a bezier curve you would use Path Functions:

For straight lines you could use:

LineDDA

Related Topic