[pygtk] Re: [cairo] pycairo - translate question

2008-07-09 Thread Carl Worth
On Mon, 5 Nov 2007 19:57:58 +0200, Donn wrote:
> Thanks. Having fun so far!

That warms my heart.

> Is there a way to set the drawing origin of a set of  commands> such that it starts at 0,0 but in the center of the "page"? (Or
> should that be "context", I am still fuzzy about that.)

Center of the "surface" is what I would have said, (a "context" is an
extra piece of state that allows one to direct drawing operations to a
particular surface).

> I guess this will be a width/2, height/2 extra transform, but I'm not sure.

Yes, after ctx.translate(width/2, height/2) a user-space coordinate of
(0,0) will map to a device-space position at the center of the target
surface.

Do note that in general cairo doesn't allow you to query for surface
dimensions, (though it does for an image surface), so you'll generally
need to hang on to the width and height yourself.

-Carl





pgpDOmTPjfxwd.pgp
Description: PGP signature
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Re: [cairo] pycairo - translate question

2008-07-09 Thread Carl Worth
On Mon, 5 Nov 2007 17:38:19 +0200, Donn wrote:
> Hi, not sure if this is the appropriate list.

Yes, definitely the right list. Welcome, Donn!

> Can one, within a single cairo context, do this:
>
> while True:
>   ctx.translate(0,0)
>   
>   ctx.translate(10,10)
>   
>   ctx.translate(50,50)
>   

Absolutely!

> The idea is to keep all the  relative to 0,0 and use
> translate (and scale etc later) to actually move the results around the
> canvas.

That's a good model to use, and cairo supports it quite well.

> At the moment my tests are all over the place. Is there a way to reset the
> overall transform between each <> section?

What you're looking for is save/restore, like so:

ctx.save()
ctx.translate()
scale.scale()
draw_something()
ctx.restore()

Often I will code all of my draw_something functions to also call
save() at the beginning and restore() at the end, which helps them to
act idempotently, (things like change to the source pattern won't
accidentally leak out, for example).

I hope that helps. And have fun with cairo!

-Carl


pgpmQpfQmjKn6.pgp
Description: PGP signature
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Re: [cairo] pycairo - translate question

2007-11-05 Thread Donn
> Yes, definitely the right list. Welcome, Donn!
Thanks. Having fun so far!

> What you're looking for is save/restore, like so:
Excellent. Saved!

> Often I will code all of my draw_something functions to also call
> save() at the beginning and restore() at the end, which helps them to
> act idempotently, (things like change to the source pattern won't
> accidentally leak out, for example).
Good tip. Also good new word "idempotently"! It has grandeur and a touch of 
humility :D

> I hope that helps. And have fun with cairo!
It has, and I have one more quick question:

Is there a way to set the drawing origin of a set of  such that it starts at 0,0 but in the center of the "page"? (Or 
should that be "context", I am still fuzzy about that.)
I guess this will be a width/2, height/2 extra transform, but I'm not sure.

\d
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/