jpayne@69: /************************************************************************ jpayne@69: jpayne@69: Copyright 1987, 1998 The Open Group jpayne@69: jpayne@69: Permission to use, copy, modify, distribute, and sell this software and its jpayne@69: documentation for any purpose is hereby granted without fee, provided that jpayne@69: the above copyright notice appear in all copies and that both that jpayne@69: copyright notice and this permission notice appear in supporting jpayne@69: documentation. jpayne@69: jpayne@69: The above copyright notice and this permission notice shall be included in jpayne@69: all copies or substantial portions of the Software. jpayne@69: jpayne@69: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR jpayne@69: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, jpayne@69: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE jpayne@69: OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN jpayne@69: AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN jpayne@69: CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jpayne@69: jpayne@69: Except as contained in this notice, the name of The Open Group shall not be jpayne@69: used in advertising or otherwise to promote the sale, use or other dealings jpayne@69: in this Software without prior written authorization from The Open Group. jpayne@69: jpayne@69: jpayne@69: Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. jpayne@69: jpayne@69: All Rights Reserved jpayne@69: jpayne@69: Permission to use, copy, modify, and distribute this software and its jpayne@69: documentation for any purpose and without fee is hereby granted, jpayne@69: provided that the above copyright notice appear in all copies and that jpayne@69: both that copyright notice and this permission notice appear in jpayne@69: supporting documentation, and that the name of Digital not be jpayne@69: used in advertising or publicity pertaining to distribution of the jpayne@69: software without specific, written prior permission. jpayne@69: jpayne@69: DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING jpayne@69: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL jpayne@69: DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR jpayne@69: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, jpayne@69: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, jpayne@69: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS jpayne@69: SOFTWARE. jpayne@69: jpayne@69: ************************************************************************/ jpayne@69: jpayne@69: #ifndef _X11_XREGION_H_ jpayne@69: #define _X11_XREGION_H_ jpayne@69: jpayne@69: typedef struct { jpayne@69: short x1, x2, y1, y2; jpayne@69: } Box, BOX, BoxRec, *BoxPtr; jpayne@69: jpayne@69: typedef struct { jpayne@69: short x, y, width, height; jpayne@69: }RECTANGLE, RectangleRec, *RectanglePtr; jpayne@69: jpayne@69: #define TRUE 1 jpayne@69: #define FALSE 0 jpayne@69: #define MAXSHORT 32767 jpayne@69: #define MINSHORT -MAXSHORT jpayne@69: #ifndef MAX jpayne@69: #define MAX(a,b) (((a) > (b)) ? (a) : (b)) jpayne@69: #endif jpayne@69: #ifndef MIN jpayne@69: #define MIN(a,b) (((a) < (b)) ? (a) : (b)) jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * clip region jpayne@69: */ jpayne@69: jpayne@69: typedef struct _XRegion { jpayne@69: long size; jpayne@69: long numRects; jpayne@69: BOX *rects; jpayne@69: BOX extents; jpayne@69: } REGION; jpayne@69: jpayne@69: /* Xutil.h contains the declaration: jpayne@69: * typedef struct _XRegion *Region; jpayne@69: */ jpayne@69: jpayne@69: /* 1 if two BOXs overlap. jpayne@69: * 0 if two BOXs do not overlap. jpayne@69: * Remember, x2 and y2 are not in the region jpayne@69: */ jpayne@69: #define EXTENTCHECK(r1, r2) \ jpayne@69: ((r1)->x2 > (r2)->x1 && \ jpayne@69: (r1)->x1 < (r2)->x2 && \ jpayne@69: (r1)->y2 > (r2)->y1 && \ jpayne@69: (r1)->y1 < (r2)->y2) jpayne@69: jpayne@69: /* jpayne@69: * update region extents jpayne@69: */ jpayne@69: #define EXTENTS(r,idRect){\ jpayne@69: if((r)->x1 < (idRect)->extents.x1)\ jpayne@69: (idRect)->extents.x1 = (r)->x1;\ jpayne@69: if((r)->y1 < (idRect)->extents.y1)\ jpayne@69: (idRect)->extents.y1 = (r)->y1;\ jpayne@69: if((r)->x2 > (idRect)->extents.x2)\ jpayne@69: (idRect)->extents.x2 = (r)->x2;\ jpayne@69: if((r)->y2 > (idRect)->extents.y2)\ jpayne@69: (idRect)->extents.y2 = (r)->y2;\ jpayne@69: } jpayne@69: jpayne@69: /* jpayne@69: * Check to see if there is enough memory in the present region. jpayne@69: */ jpayne@69: #define MEMCHECK(reg, rect, firstrect){\ jpayne@69: if ((reg)->numRects >= ((reg)->size - 1)){\ jpayne@69: BoxPtr tmpRect = Xrealloc ((firstrect), \ jpayne@69: (2 * (sizeof(BOX)) * ((reg)->size))); \ jpayne@69: if (tmpRect == NULL) \ jpayne@69: return(0);\ jpayne@69: (firstrect) = tmpRect; \ jpayne@69: (reg)->size *= 2;\ jpayne@69: (rect) = &(firstrect)[(reg)->numRects];\ jpayne@69: }\ jpayne@69: } jpayne@69: jpayne@69: /* this routine checks to see if the previous rectangle is the same jpayne@69: * or subsumes the new rectangle to add. jpayne@69: */ jpayne@69: jpayne@69: #define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\ jpayne@69: (!(((Reg)->numRects > 0)&&\ jpayne@69: ((R-1)->y1 == (Ry1)) &&\ jpayne@69: ((R-1)->y2 == (Ry2)) &&\ jpayne@69: ((R-1)->x1 <= (Rx1)) &&\ jpayne@69: ((R-1)->x2 >= (Rx2)))) jpayne@69: jpayne@69: /* add a rectangle to the given Region */ jpayne@69: #define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\ jpayne@69: if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\ jpayne@69: CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\ jpayne@69: (r)->x1 = (rx1);\ jpayne@69: (r)->y1 = (ry1);\ jpayne@69: (r)->x2 = (rx2);\ jpayne@69: (r)->y2 = (ry2);\ jpayne@69: EXTENTS((r), (reg));\ jpayne@69: (reg)->numRects++;\ jpayne@69: (r)++;\ jpayne@69: }\ jpayne@69: } jpayne@69: jpayne@69: jpayne@69: jpayne@69: /* add a rectangle to the given Region */ jpayne@69: #define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\ jpayne@69: if ((rx1 < rx2) && (ry1 < ry2) &&\ jpayne@69: CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\ jpayne@69: (r)->x1 = (rx1);\ jpayne@69: (r)->y1 = (ry1);\ jpayne@69: (r)->x2 = (rx2);\ jpayne@69: (r)->y2 = (ry2);\ jpayne@69: (reg)->numRects++;\ jpayne@69: (r)++;\ jpayne@69: }\ jpayne@69: } jpayne@69: jpayne@69: #define EMPTY_REGION(pReg) pReg->numRects = 0 jpayne@69: jpayne@69: #define REGION_NOT_EMPTY(pReg) pReg->numRects jpayne@69: jpayne@69: #define INBOX(r, x, y) \ jpayne@69: ( ( ((r).x2 > x)) && \ jpayne@69: ( ((r).x1 <= x)) && \ jpayne@69: ( ((r).y2 > y)) && \ jpayne@69: ( ((r).y1 <= y)) ) jpayne@69: jpayne@69: /* jpayne@69: * number of points to buffer before sending them off jpayne@69: * to scanlines() : Must be an even number jpayne@69: */ jpayne@69: #define NUMPTSTOBUFFER 200 jpayne@69: jpayne@69: /* jpayne@69: * used to allocate buffers for points and link jpayne@69: * the buffers together jpayne@69: */ jpayne@69: typedef struct _POINTBLOCK { jpayne@69: XPoint pts[NUMPTSTOBUFFER]; jpayne@69: struct _POINTBLOCK *next; jpayne@69: } POINTBLOCK; jpayne@69: jpayne@69: #endif /* _X11_XREGION_H_ */