[cairo] I don't see the pattern
Carl Worth
cworth at cworth.org
Thu Dec 6 10:45:43 PST 2007
On Thu, 6 Dec 2007 15:17:56 +0200, Donn wrote:
> ctx = widget.window.cairo_create() # this is a pyGTK based app.
> for obj in list:
> obj.draw(ctx,frame)
I would imagine something like this:
ctx = widget.window.cairo_create()
for obj in list:
if ! obj.cached_surface:
ctx.cached_surface = ctx.get_target().create_similar (...)
ctx_obj = cairo_create(ctx.cached_surface)
obj.draw (ctx_obj, frame)
ctx.set_source_surface (obj.cached_surface, x, y)
ctx.paint
I know I've got that "cairo_create(ctx.cached_surface)" line
wrong. With the python binding there's probably some ugly syntax like
"cairo.CairoContext.new(ctx.cached_surface)" or something, but I can
never remember what that looks like. In C the function is
"cairo_create" which is the same thing that the window's
"cairo_create" method is modeled after.
Similarly, within create_similar you'll need a content value. In C,
this is a simple enum like CAIRO_CONTENT_COLOR_ALPHA or
CAIRO_CONTENT_COLOR. But again, in python, you have to have some
mixed-syntax thing for the namespace like cairo.CONTENT_COLOR_ALPHA or
whatever.
But you probably know how to get the syntax right. (Maybe next time I
should just write the example code in C and let people that know
python do the transliteration---then I could avoid all these apologies
for broken syntax).
Anyway, I hope that helps. The above is how I would probably cache
pre-drawn objects.
And you could create a pattern for each object as well, (instead of
just a surface). That would even give you a place to lodge an
appropriate per-object transformation if that would be useful. But
it's not strictly necessary.
-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071206/75ff2584/attachment.pgp
More information about the cairo
mailing list