[comp.windows.x] X region and its data structure

HEPING@kuhub.cc.ukans.edu (08/01/89)

Questions:
1. What is the data structure for X region? 
2. I can create a rectangle or polygon region. How can I creat an ellipse
   region? Do I have to find the edge points for the ellipsefirst and then
   use XPlolygonRegion?
3. Once a region is set, can I get the region pointer? I mean that I don't
   know the clipregion and I don't care, but I want to set a new clipmask
   region by intersecting the current clipmask region with a third region.
4. It is possible to create an arbitrary region by creating a bitmap first
   But when I set this region, the old clipmask region will be destroyed.
   Is there a way to keep the old region for later use? ( it is similar to 3)

Any comments will be welcome and appreciated.


Phil

rws@EXPO.LCS.MIT.EDU (08/01/89)

    What is the data structure for X region?

A list of YX-banded rectangles and a total extents.

    How can I creat an ellipse region?

Xlib doesn't really provide a way, sorry.  If you want to use it for clipping
in the server, you can create a bitmap in the server, draw the ellipse into
it, and then use the bitmap as a clip mask.

    I want to set a new clipmask region by intersecting the current clipmask
    region with a third region.

The X protocol doesn't support clip mask region operations on the server side,
sorry.  (We have given some thought to an extension that would permit this.)
You'll either have to do all of the region arithmetic on the client side (e.g.
using XIntersectRegion), or do it all on the server side (e.g. using bitmaps
and GC functions to combine them and then re-store the bitmap into the GC).

    It is possible to create an arbitrary region by creating a bitmap first

Yes.

    But when I set this region, the old clipmask region will be destroyed.

Correct.

    Is there a way to keep the old region for later use?

You can copy it to another GC, but you can't do region arithmetic with it.

jg@max.crl.dec.com (Jim Gettys) (08/03/89)

>1. What is the data structure for X region? 

It is deliberately opaque; i.e. you aren't allowed to find out; it is private
to the library.

>2. I can create a rectangle or polygon region. How can I creat an ellipse
>   region? Do I have to find the edge points for the ellipsefirst and then
>   use XPlolygonRegion?

Unfortunately yes; we didn't have time to implement such a routine before X11R1,
so left it out.

>3. Once a region is set, can I get the region pointer? I mean that I don't
>   know the clipregion and I don't care, but I want to set a new clipmask
>   region by intersecting the current clipmask region with a third region.

Nope.  But you can certainly remember your regions and do the intersection
in the client program with the Xlib routines.  You wouldn't want to query
the server anyway; as usual, never rely on the server for information you could
have remembered in the first place, as it saves round trips.


>4. It is possible to create an arbitrary region by creating a bitmap first
>   But when I set this region, the old clipmask region will be destroyed.
>   Is there a way to keep the old region for later use? ( it is similar to 3)

Again, if you've computed your region in the first place, you should have it
around for later use when you need it.

You could be complaining that there should be an Xlib routine which takes and XImage
structure containing a bitmap and turns it into a region for other Xlib use, and I
wouldn't necessarily disagree with you, and for cleanlyness's sake, there should
probably be such a routine for arcs.  If this is what you need, I suspect you could
get support for it to be added in a future release.  What is in Xlib now is sort
of the least we could get away with in region code, given the initial time pressure of
the first release.  It was nip and tuck getting the original specification implemented
at the time.
				- Jim Gettys