[comp.windows.x] Using XPolygonRegion for getting pointer locations

kriso@northstar5 (Kris Olander) (07/18/90)

I'm creating a map.  I'm using XFillPolygon to display the countries, and
then I use XPolygonRegion to distinguish a the location of each country.

I'm under the assumption that I don't have to specify an offset using
XOffsetRegion if I want the drawable origin (the window that contains all
the countries) to be the regions origin.

After I've created all the countries and attached a 'Region' to each
country, I have been trapping Button1 'down' events as a means of selecting
a country.  I then go through the list of countries passing each
country's Region pointer into XPointInRegion to see which region the pointer
is trying to access.

The problem: none of my country's Regions ever match.  The Nut Shell books
give a whapping two pages describing Regions.

Can anyone clue me in?  Is this approach bogus?  I'd rather not dive into
the clipping algorithms for many sided polygons if X11 will do it for me.

Here's some of the code:
	} /* end Switch */
	for (i=0; i<geo->ncoords; i++) {
	    xy_array[i].x = (geo->coords[i]->x - bX ) / mX;
	    xy_array[i].y = (geo->coords[i]->y -bY ) / mY;
	}

	geo->locator = XPolygonRegion(xy_array, geo->ncoords,EvenOddRule);
	fprintf (stdout, "locator : %x \n", geo->locator);
------- and --------
DisplayRegion(window, button_event)
Window window;
XButtonEvent *button_event;
{
    GeoRegion *geo_check;
    int i, x, y;
    
    x = button_event->x; y = button_event->y;
 
    fprintf (stdout, "x, y: %d, %d\n", x, y);
    for (geo_check = First_region; 
	 geo_check != NULL;
	 geo_check = geo_check->next_region) {
	if(XPointInRegion(geo_check->locator,x, y))
	    break;
	fprintf (stdout, "region,locator: %s,%x\n",
		 geo_check->name, geo_check->locator);
    }
    if(geo_check)
	fprintf (stdout, "Region: %s\n", geo_check->name);
    else
	fprintf (stdout, "FAILED FINDING LOCATION OF POINTER\n");

}
----------------------- Sorry this is so long :( -------------------

				-Kris Olander

# Kris Olander ---- ---- arpa: Kris.Olander@Dartmouth.Edu    #
# ---------------------------------------------------------- #
# System Eng. Project NORTHSTAR                              #
# Thayer School of Eng., Dartmouth College                   #

harkcom@potato.pa.Yokogawa.CO.JP (Alton Harkcom) (07/20/90)

   I can't see anything wrong with your code(I'm an amatuer though) so it might
be in the data itself...

   I have almost finished an X version of (dare I say it from fear of lawsuit)
Risk. The problems I had at first were...

   my data was in CoordModePrevious format, so I had to translate it into
      CoordModeOrigin format to create the region.

   and an error in my translation algorithm caused the regions not to be scaled
      so I ended up with a tiny region but a large filled polygon (you can't see
      the little suckers so it's hard to debug something like this...)

   It would be nice if there was a routine that could read what youv'e written
into a region and display it as a polygon...

--
--harkcom@potato.pa.yokogawa.co.jp

mouse@LARRY.MCRCIM.MCGILL.EDU (der Mouse) (07/20/90)

> I have almost finished [...].  The problems I had at first were...

>    and an error in my translation algorithm caused the regions not to
>    be scaled so I ended up with a tiny region but a large filled
>    polygon (you can't see the little suckers so it's hard to debug
>    something like this...)

> It would be nice if there was a routine that could read what youv'e
> written into a region and display it as a polygon...

Simple enough: XSetRegion() the region as the clipping region of a GC
and then XFillRectangle() the whole window using that GC.

Hmmm, you probably want just the outline.  That's more difficult.  You
could probably hack it by displaying four times with GXxor, changing
the clip offsets each time.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu