[cairo] Set opacity for surface
Jerónimo Barraco
jerobarraco at yahoo.com.ar
Mon Nov 1 20:08:00 PDT 2010
Hi everyone, i've been working on a software wich is some kind of
abstraction on top of cairo, and i'm having a problem.
I'm using objects that extends vectors (there's no inheritance) and have
some methods for specifying how to stroke and fill thems.
Using solids and patterns is ok, but when i need to use a texture (a
surface loaded from a PNG) i can't find a way to specify an alpha.
i'm using "ctx.set_surface" to assign a surface, and using "ctx.fill" or
"ctx.stroke_preserve" acordingly.
I'm setting the source in one part of my code (using interchangeable
methods for different "predesigned" effects) and calling
fill, stroke_preserve (and a hand-made shadow) in another part of the code.
so i need a solution that doesnt affect the other functions (rgba and
patterns), wont require me to change where i use stroke/fill,
and is as fast as posible, as i need to redraw it a lot of times, (and
simulating a opacity animation)
Thanks in advance..
here's the code:
here are the methods that set a source:
Line 13 is where i use a "texture" (png surface wich will change from
object to object and part of the object), and i need a random opacity that
will probably will be used once.
http://www.assembla.com/code/kafx/subversion/nodes/branches/Implementacion/Cairo/libs/cairo_basic.py
here is where i call the methods from above:
Line 428 is the method that will call them.
http://www.assembla.com/code/kafx/subversion/nodes/branches/Implementacion/Cairo/libs/cairo_extra.py
notice lines 458, 462 and 472, those __S* methods are pointers to one of
the methods in the file from above, that's why i need them to be
interchangeable
for using with stroke and fill.
i only came up with the idea of creating a new surface, create a mask with
the opacity, paint the source using the mask, and reusing the result, but
that will be TOO costly.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
More information about the cairo
mailing list