[cairo] DrawingArea events - cross posted

Carl Worth cworth at cworth.org
Fri Nov 9 10:01:45 PST 2007


On Fri, 9 Nov 2007 15:12:29 +0200, Donn wrote:
> While that sounds great -- I would settle for even a pseudo-code algorithm for
> how to detect x y within a path. I have been searching and coming up blank
> really.

Cairo provides two primitives for this operation:

	cairo_in_fill

	cairo_in_stroke

They both accept an (x,y) user-space coordinate and let you know if
that point would be contained within the fill or stroke of the current
path.

So you could use these directly, (and depending on your scene
complexity that might be enough to start with).

At some point you'll very likely want to do faster things first, (like
trivially rejecting shapes where the point is outside the bounding box
of the shape), since cairo_in_fill is not the fastest operation
around.

Another option is to render all objects opaquely back-to-front and
without antialiasing to an image surface and encoding the object's ID
into the color channels. Then you can read out the relevant object ID
directly from the image surface. Whether this is faster depends on how
static your scene is, (and how fast the drawing backend is).

Of course, another option is to just use an existing cairo-using
canvas library, (such as goocanvas or others), which already have one
or another of the above options implemented.

Have fun,

-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/20071109/a5b7665c/attachment-0001.pgp 


More information about the cairo mailing list