[cairo] pycairo - translate question

Gerdus van Zyl gerdusvanzyl at gmail.com
Mon Nov 5 10:48:23 PST 2007


Use the ctx.save() and ctx.restore() to wrap the cairo drawing commands:
eg.
ctx.save()
ctx.translate(50,50)
ctx.rectangle(0,0,5,5)
ctx.fill()
ctx.restore()

or what i have used before but is probably bad (slighly faster though
since it does not save/restore entire state)
ctx.translate(50,50)
ctx.rectangle(0,0,5,5)
ctx.fill()
ctx.translate(-50,-50)

Hope this helps.

~Gerdus van Zyl

On 11/5/07, Donn <donn.ingle at gmail.com> wrote:
> Hi, not sure if this is the appropriate list.
>
> Can one, within a single cairo context, do this:
>
> while True:
>   ctx.translate(0,0)
>   <pycairo commands to draw a square at 0,0>
>   ctx.translate(10,10)
>   <pycairo commands to draw a circle at 0,0>
>   ctx.translate(50,50)
>   <pycairo commands to draw a Black Night at 11,44>
>
> The idea is to keep all the <drawing commands> relative to 0,0 and use
> translate (and scale etc later) to actually move the results around the
> canvas. I picture it a bit like a stamp that moves to (x,y) and then draws
> the vectors in <> down at that point, then moves on.
>
> My actual code is building a stack of pointers to draw() functions (in other
> objects) that gets run in a tight loop: pop, draw, pop, draw, etc.
>
> At the moment my tests are all over the place. Is there a way to reset the
> overall transform between each <> section?
>
> /d
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>


More information about the cairo mailing list