Hello,
I try to draw a rectangle with a line pattern, e.g.
white
green
white
green
To complicate things, I give it shading.
My drawing routine (relevant part) is:
# select Pen width
if len(colors) == 1:
K = 1
else:
K = 2
# create lines
for yi in range(int(h/(1*K)+1)):
hue, sat, val = colors[yi % N]
val = val * (1 + cos(fac * yi)) / 2
newcol = hsv2rgb(hue, sat, val)
pen = Pen(newcol, K, SOLID)
lines.append((x0, h1 + K * yi, x1, h1 + K * yi))
pens.append(pen)
# draw lines
dc.DrawLineList(lines, pens)
# draw surrounding box
dc.SetPen(Pen('BLACK'))
dc.DrawLine((x0, y0), (x0, y1))
dc.DrawLine((x0, y1), (x1, y1))
dc.DrawLine((x0, y0), (x1, y0))
dc.DrawLine((x1, y0), (x1, y1 + 1))
Now, if I have to draw only one (shaded) color, I use lines 1 pixel wide.
If I have more colors, I use lines 2 pixels wide.
If the line width is 1, the drawing is within the surrounding box.
But if the line width is 2, the drawing is outside the box, depending on the OS.
On MacOS, the lines extend one pixel to the right, although that is governed by
x0 and x1, that do not change.
On GTK1, the lines also extend one pixel to the right, but that extension is only
one pixel wide (per line of 2 pixels wide).
I solved this by using dc.SetClippingRegion(), but I was wondering why.
And I also want to know why I have to add 1 in the last statement,
or I do not draw the right-down corner point.
Pim Buurman
X>support