[pygtk] Cairo Line Width
Laszlo Pandy
laszlok2 at gmail.com
Sat Sep 27 09:36:44 WST 2008
In Cairo, the coordinates do not refer to a particular pixel. Instead
"...integer coordinates map to points half way between sample point
locations."
http://www.cairographics.org/FAQ/#sharp_lines
Laszlo
2008/9/26 Jeffrey Drake <jeffd at techsociety.ca>:
> In my code below, I set a line width of 1 and then when I go to draw a
> grid, what appears is an antialiased line of still width of 2. I need a
> single pixel, not the ugly 2 width beast as shown before.
>
> The problem is when drawing the horizontal grid below.
>
> Any ideas on how to fix this?
>
> My original code (without the set_line_width(1) is available at
> https://launchpad.net/starz/demo1
>
>
> - Jeff.
>
> def draw(self, context):
> rect = self.get_allocation()
> # x = rect.x + rect.width / 2
> # y = rect.y + rect.height / 2
> cx = rect.width
> cy = rect.height
>
> context.set_line_width(1)
>
> # white background
> context.set_source_rgb(1,1,1)
> context.rectangle(0, 0, cx, cy)
> context.fill()
>
> context.stroke()
>
> # no grid if no model
> if self.model == None:
> return
>
> cx = self.width
> cy = self.height
>
> # black grid
> context.set_source_rgb(0,0,0)
>
> # horizontal lines
> for i in xrange(self.model.cy+1):
> context.move_to(0, i * 33)
> context.line_to(cx, i * 33)
> print i*33
>
> for i in xrange(self.model.cx+1):
> context.move_to(i * 33, 0)
> context.line_to(i * 33, cy)
>
> context.stroke()
>
> # draw planets
> context.set_source_rgb(0.5, 0.5, 0.5)
>
> for x,y in self.model.map:
> context.arc(x * 33 + 10, y * 33 + 10, 8, 0, 2 * math.pi)
> context.fill()
> context.stroke()
>
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>
More information about the pygtk
mailing list