tags:

views:

462

answers:

2

Is there any way to set the style for the lineends for the TCanvas.LineTo method? It seems to default to rounded ends, which looks very bad for several lines in a row of different colours when Pen.Width is set to a large value (e.g. 9).

It looks like this (rounded ends):

 ********........******
**********........******
**********........******
 ********........******

(where * is e.g. blue and . is yellow)

It is even worse if the two outer lines are drawn after the middle line:

 ********........******
**********......********
**********......********
 ********........******

I'd like it to look like this (streight ends):

 ********........******
 ********........******
 ********........******
 ********........******

Pen does not seem to offer any setting for this and neither does the LineTo method. Is there maybe a windows API function I could call?

A: 

I don't think this is possible with Delphi, perhaps Windows API LineTo has better functions (in other programming languages, this is often referenced as linecap or something similar).

A workaround would be to draw two squares at the start- and endpoint of your line, but this only works for horizontal/vertical lines, you would've to rotate the squares for other lines.

You can also try to use OpenGL for linedrawing, when using glLineWidth caps are not rounded, although they remain horizontal/vertical even for diagonal lines like this:

........            .........
..xxxxx.            ..x......            
.xxxxx.. OpenGL way .xxx..... correct way (not quite exact, I hope you get it)
xxxxx...            xxxxx.... 
xxxx....            xxxx.....
schnaader
+4  A: 

Maybe ExtCreatePen helps. Check the PS_ENDCAP_* and PS_JOIN_* flags.

Ulrich Gerhardt
That seems to be what I am looking for, but it also is not easy to integrate into the TCanvas method.
Thomas Mueller
Have a look here: http://qc.codegear.com/wc/qcmain.aspx?d=9661. Never tried that but maybe it works in the meantime?
Ulrich Gerhardt