[cairo] Hit detect surface?

Gustavo J. A. M. Carneiro gjc at inescporto.pt
Wed Mar 1 14:37:32 PST 2006


On Qua, 2006-03-01 at 12:06 -0800, Bill Spitzak wrote:
> 
> 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.

  Extra overhead is what is worrying to me.  You'd have to draw an
object twice, once for screen, one more time for hit detection surface.
You'd need to save the hit detection surface in memory.  Maybe if this
surface is 1 bit per pixel the memory overhead will be small,
otherwise...

  But there is a stronger argument against this approach: some
applications are more interested in "how far is the mouse pointer from
every object", or "what is the object nearest to the pointer" than "give
me the object under the mouse pointer".  Because most times it is not
comfortable for the user to have to place the pointer exactly over an
pixel that happens to be painted by some object.  For instance, I
remember how early nautilus used a very precise (to the pixel) hit
detection for file icons; guess what, usability studies later showed
that users were annoyed by the fact that clicking on a CD icon wouldn't
work in some cases, particularly when the pointer is exactly over the
hole :)

  In spite of this, maybe hit detection surface is useful in some cases,
I'm just saying it may not be useful as generally as you think.

  Regards,
-- 
Gustavo J. A. M. Carneiro
<gjc at inescporto.pt> <gustavo at users.sourceforge.net>
The universe is always one step beyond logic



More information about the cairo mailing list