[comp.windows.x] Optimal object detection....

tron1@tronsbox.xei.com (Kenneth Jamieson) (01/09/91)

	I want to put up a series of objects under X that may be
either bitmaps or filled polygons. They all need to be the same color
and get highlighted as they are selected.

	Now, the question is, what is the BEST way to get X to tell me
WHAT "icon" was picked ??

	I can:

	1) Check mouse co-ords against the display list (ugly)
	2) Associate a "region" under each object (is this right?)

	Are there other ways ?


-- 
========[ Xanadu Enterprises Inc. Amiga & Unix Software Development]=======
=    "I hate you, take your things and get out of this house!!!!!"        =
=    (pause) - "Hold me!" ( same girl, elapsed time 6.5 seconds)          =
=========== Ken Jamieson: uunet!tronsbox.xei.com!tron1  ===================
=   NONE of the opinions represented here are endorsed by anybody.        =
=== The Romantic Encounters BBS 201-759-8450(PEP) / 201-759-8568(2400) ==== 

sundar@ai.mit.edu (Sundar Narasimhan) (01/13/91)

In article <618@tronsbox.xei.com>, tron1@tronsbox.xei.com (Kenneth Jamieson) writes:
|> 
|> 	I want to put up a series of objects under X that may be
|> either bitmaps or filled polygons. They all need to be the same color
|> and get highlighted as they are selected.
|> 
|> 	Now, the question is, what is the BEST way to get X to tell me
|> WHAT "icon" was picked ??
|> 
|> 	I can:
|> 
|> 	1) Check mouse co-ords against the display list (ugly)
|> 	2) Associate a "region" under each object (is this right?)
|> 	Are there other ways ?
I may not be understanding your problem correctly, but if you want
to map screen co-ordinates to your object space there are many
issues to consider. One way to do this would be to have a 2-d 
array which contains at each point the id of the object occuping
the corresponding screen location. Then when you get a mouse click
you just index into this array and voila!, you have the object you
have selected, which you can then highlight or whatever. Maintaining
this array obviously is going to be expensive and there are many 
obvious optimizations one can get into.

Checking the mouse co-ords against a display list is not bad.
This can be made fast if you use bounding boxes correctly. 

There are more complicated data structures like region quad-trees 
that can be used to attack this problem but it is hard to tell if that is what you should get into given your problem description (see 
Hanan Samet's "The Design and Analysis of Spatial Data Structures"
if you are interested).