[cairo] context.save and in_fill - still lost in the woods

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Mon Nov 26 01:00:02 PST 2007


Donn wrote:
> Hello,
>  I seem to have days when everything works and then I add something to my app 
> and all the old stuff breaks. I'm having one of those now. I have attached a 
> short script that boils the question down and I hope someone can give me a 
> hand.
> 
> The action is in MyStuff.draw and there's a note explaining my question in 
> there.
> 
> It's to do with in_fill and when/where it gets used in relation to a series of 
> contexts (each with a matrix) and probably displays my ignorance more than I 
> care to :)

The trick is to create a path and then reset the transformation matrix to
the identity transform before calling in_fill, like this:

        # create path
        self.drawHitShape ( )

	# now reset
        cr.save ( )
        cr.identity_matrix ( )
        hit = cr.in_fill ( self.x, self.y )
        cr.restore ( )

        # clear the path again
	cr.new_path ( )

The coordinates that you pass to  cr.in_fill  will be transformed
according to whatever transformation matrix is currently active
(i.e. the ctm) before the test is made.

It's important to note that changing the transformation matrix
does not affect the previously created path.

HTH,

Bertram


More information about the cairo mailing list