[cairo] I don't see the pattern

Donn donn.ingle at gmail.com
Thu Dec 6 02:29:11 PST 2007


Hi all,
 I have been trying to figure out (what and) how patterns work. This is the 
sort of code I've been using:

        cr.push_group()
        # Create two rects
        cr.set_source_rgb(1,0,0)
        cr.rectangle(0,0,50,50)
        cr.fill()
        cr.set_source_rgb(1,1,0)
        cr.rectangle(0,50,50,50)
        cr.fill()
        #  I want them to be the 'source' for later
        cr.pop_group_to_source()
        
        #cr.translate(100,100) # tried to move the paint ()

        # Attempt to draw a path and fill it from the 'source' above
        cr.move_to ( 128.0, 25.6)
        cr.line_to ( 230.4, 230.4)
        cr.rel_line_to ( -102.4, 0.0)
        cr.curve_to ( 51.2, 230.4, 51.2, 128.0, 128.0, 128.0)
        cr.close_path ()
        #cr.fill() # to see what I just drew

        cr.paint() # paints the two recs in top left: unexpected.

Context:
You see, I have my little retained mode canvas app going now and on 
each 'tick' it runs through all my objects and calls their draw() commands. 
This results in a lot of cairo.this_that_and_the_other() being run over and 
over again. 
 I don't know how to do it, but I want to lessen the burden on each draw() 
such that if it's not changed from last time ( I keep a set of properties 
like x,y and scale) then I want to "stamp" it from a cached 'source' onto the 
canvas (at it's old position) and avoid calling all the code in the draw() 
method.

So, I was hoping to 'record' the paths and fills and whatnot within a draw() 
method by push_group and then keep them in a reference someplace and then pop 
them to source and 'stamp' them again, perhaps even via images of some 
kind -- is this even making sense?

The code above is a test of the basic idea -- I still don't know how to 
preserve the source between loops, which creates a new context each time. 
(unless I cache bitmaps)

\d


More information about the cairo mailing list