[comp.windows.x] How do I pick/hit graphical primitives in X ?

erik@abblund.se (Erik Sparre) (03/15/91)

When you develop a direct manipulation graphical user interface you
will sooner or later need the ability to detect whether the user pointed
at a certain graphical object (line, ect, circle).

I've seen hardware that supports this by letting you set up a very small clip
window around the cursor hot-spot, redraw all primitives (without
actually doing any drawing). As soon as a primitive draws something inside 
the clip window, a flag is raised and/or an interrupt is signaled.
A straightforward and pretty fast method since no display memory is updated
during the redraw.

Some toolkits/systems, like GKS, supports picking as a part of the API. 

Is there any good way to detect picking in X or any X-based library
without having to do the calculations yourself ?

Thanks
-- 
Erik Sparre                                  | Email erik@abblund.se
ABB Corporate Research                       | Phone +46 46 168527
Dept. KLL, Lab for Man-Machine Communication | Telex        33709
IDEON Research Park, S-223 70 LUND, SWEDEN   | Fax   +46 46 145620

cjmchale@cs.tcd.ie (Ciaran McHale) (03/17/91)

In <1991Mar15.100902.16094@abblund.se> erik@abblund.se (Erik Sparre) writes:

>When you develop a direct manipulation graphical user interface you
>will sooner or later need the ability to detect whether the user pointed
>at a certain graphical object (line, ect, circle).
>[...]
>Is there any good way to detect picking in X or any X-based library
>without having to do the calculations yourself ?

This is one of the limitations of raw Xlib. It *is* possible to write
the appropriate routines, but it's a major pain to do so. It's best to
have such commonly used functionality provided in a graphical toolkit to
prevent application developers having to reinvent the wheel each time.

Choices:
	o Do the calculations yourself.
	o Use Display Popstscript.
	o Use Interviews, a C++ windowing/graphics library.
	o Write your own OO graphics library in which each graphical
	  object has a method does_contain_point(short x, short y).

This last approach is possible but its a pain to do yourself.


Ciaran.
-- 
Ciaran McHale		"Verbosity says it all"			      ____
Department of Computer Science, Trinity College, Dublin 2, Ireland.   \  /
Telephone: +353-1-772941 ext 1538	FAX: +353-1-772204	       \/
Telex: 93782 TCD EI			email: cjmchale@cs.tcd.ie

asente@adobe.com (Paul Asente) (03/19/91)

In article <1991Mar16.160205.20935@cs.tcd.ie> cjmchale@cs.tcd.ie (Ciaran McHale) writes:
>In <1991Mar15.100902.16094@abblund.se> erik@abblund.se (Erik Sparre) writes:
>
>>When you develop a direct manipulation graphical user interface you
>>will sooner or later need the ability to detect whether the user pointed
>>at a certain graphical object (line, ect, circle).
>>[...]
>>Is there any good way to detect picking in X or any X-based library
>>without having to do the calculations yourself ?
>
>Choices:
>	o Use Display Popstscript.
>	...

Just to expand a bit on Ciaran's response, Display PostScript has a set of
operators that let you test whether a path intersects an aperture.  You can
test whether the stroked path intersects the aperture or whether the filled
path intersects the aperture.  You can make the aperture large or small,
square, round, of whatever shape you like.

	-paul asente
		asente@adobe.com	...decwrl!adobe!asente

    Ratz put a bucket of liquid in front of me.
   "I wanted a glass of docs, Ratz.  What the hell is this?" I barked.
   "Motif don't fit in a glass anymore," he barked back.
    I looked at the liquid.  It was totally opaque to me.