Re: [cairo] Hit detect surface?



<quote who="Bill Spitzak">
> Gustavo J. A. M. Carneiro wrote:
>
>>   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 :)
>
> What I am proposing *is* to do this "nearest the pointer" type hit
> detection.
>
> There is only one "pixel" in the surface, and the caller has to set the
> transformation so that the region of interest is mapped to the area of
> this pixel. You can thus hit-detect anything that draws into any
> parallelogram-shaped region, though typically a square around the mouse
> cursor will be used. If the square is 20 pixels on a side, this will
> pick up everything within 10 pixels of the mouse.
>
> To find the nearest, you must draw several times, with smaller and
> smaller squares, until either you reach a minimum size, or only one
> object is detected (or it goes to zero, in which case you use the
> previous pass). (actually now that I think about it, it may be more
> efficient to start at the minimum size and go up until you hit something.)

  It sounds like a lot of drawing just to find if the mouse pointer is
near an object.  I suppose it could be useful in very complex shapes,
but I would imagine it would be much more efficient in most cases to
pretend an item is approximately a rectangle, circle, or another simple
shape, and then use  plain old math to determine the distance from the
mouse pointer to the shape.

  I would therefore propose that a distance_to_point(x, y) virtual
method/signal be included in the canvas item.  Implementations can then
choose the best method to implement it, which can be simple math
calculus or more complex cairo surface manipulations (for really complex
shapes).

  Regards.

PS: sorry for entering this discussion without even looking at Sven's
canvas code :-P




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]