[cairo] Hit detect surface?

David Trallero Mena ditiem at gmail.com
Wed Mar 1 02:27:38 PST 2006


Bill Spitzak escribió:
> This talk about GnomeCanvas needing complicated hit detection made me 
> wonder if Cairo could support hit detection. This could be done with an 
> entire new surface type and thus not affect any existing cairo backends. 
> As I see it it would work something like this:

I also have needed to do that. In fact I think complicating cairo is 
unnecessary. I just create another surface of 32 bits-per-color and 
render everything again there. This new surface I use I refer to as 
select surface (hit-surface for you). The color used when re-rendering 
is indeed and ID (I have to talk with cairo guys about this) of the 
figure (rectangle, ellipse, circle...) that was rendered on the 
"original-surface".

Taking external events like mouse or joystick-motion or whatever I just 
have to read in the "hit-surface" and see the ID to know which element 
was drawn on that point. In my case the ID means the widgets drawn 
there, in yours, it can means the structure that contains the figure 
with the operators and colors used,

This is similar to a method used in OpenGL.

Cheers,
David


More information about the cairo mailing list