[cairo] Hit detect surface?

Bill Spitzak spitzak at d2.com
Wed Mar 1 12:06:58 PST 2006

Vladimir Vukicevic wrote:

> This sounds impossible to implement with any surface but the image
> backend -- cairo has no knowledge of what pixels actually get touched
> by underlying platform methods.  What are the use cases for this?

Yes, that is why I said it was a *new* surface type. I would expect the 
code to start from the code for the Image backend. However it needs to 
add the code to do the callback.

Conversely removing the need to think about anything other than one 
pixel (or perhaps it does not bother remembering the color at all) 
should simplify it a lot, which may be important. In my experience with 
hit-detection, you have to draw the image many times, so that you can 
start with a larger area and narrow down until a single object is 
chosen. I don't believe there is any other reliable method for finding 
the nearest object to a click. Drawing multiple times also allows 
detection areas that are not rectangles, by intersecting several. In any 
case the Image backend is too slow for such gui work, the redraws for 
hit detection may slow down GUI feedback far more than the 
hardware-accelerated back end. Thus making a very efficient hit detect 
surface with no extra overhead for doing anything else is probably a 
good idea.

More information about the cairo mailing list