Back to index

lightning-sunbird  0.9+nobinonly
xregion.h
Go to the documentation of this file.
00001 /* $XConsortium: region.h,v 11.13 91/09/10 08:21:49 rws Exp $ */
00002 /************************************************************************
00003 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
00004 and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
00005 
00006                         All Rights Reserved
00007 
00008 Permission to use, copy, modify, and distribute this software and its 
00009 documentation for any purpose and without fee is hereby granted, 
00010 provided that the above copyright notice appear in all copies and that
00011 both that copyright notice and this permission notice appear in 
00012 supporting documentation, and that the names of Digital or MIT not be
00013 used in advertising or publicity pertaining to distribution of the
00014 software without specific, written prior permission.  
00015 
00016 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
00017 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00018 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
00019 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00020 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00021 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00022 SOFTWARE.
00023 
00024 ************************************************************************/
00025 
00026 #ifndef _XREGION_H
00027 #define _XREGION_H
00028 
00029 typedef struct {
00030     short x1, x2, y1, y2;
00031 } Box, BOX, BoxRec, *BoxPtr;
00032 
00033 typedef struct {
00034     short x, y, width, height;
00035 }RECTANGLE, RectangleRec, *RectanglePtr;
00036 
00037 #ifdef TRUE
00038 #undef TRUE
00039 #endif
00040 
00041 #define TRUE 1
00042 #ifndef FALSE
00043 #define FALSE 0
00044 #endif
00045 #ifndef MAXSHORT
00046 #define MAXSHORT 32767
00047 #endif
00048 #ifndef MINSHORT
00049 #define MINSHORT -MAXSHORT
00050 #endif
00051 #ifndef MAX
00052 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
00053 #endif
00054 #ifndef MIN
00055 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
00056 #endif
00057 
00058 
00059 /* 
00060  *   clip region
00061  */
00062 
00063 typedef struct _XRegion {
00064     long size;
00065     long numRects;
00066     BOX *rects;
00067     BOX extents;
00068 } REGION;
00069 
00070 /* Xutil.h contains the declaration: 
00071  * typedef struct _XRegion *Region; 
00072  */   
00073 
00074 /*  1 if two BOXs overlap.
00075  *  0 if two BOXs do not overlap.
00076  *  Remember, x2 and y2 are not in the region 
00077  */
00078 #define EXTENTCHECK(r1, r2) \
00079        ((r1)->x2 > (r2)->x1 && \
00080         (r1)->x1 < (r2)->x2 && \
00081         (r1)->y2 > (r2)->y1 && \
00082         (r1)->y1 < (r2)->y2)
00083 
00084 /*
00085  *  update region extents
00086  */
00087 #define EXTENTS(r,idRect){\
00088             if((r)->x1 < (idRect)->extents.x1)\
00089               (idRect)->extents.x1 = (r)->x1;\
00090             if((r)->y1 < (idRect)->extents.y1)\
00091               (idRect)->extents.y1 = (r)->y1;\
00092             if((r)->x2 > (idRect)->extents.x2)\
00093               (idRect)->extents.x2 = (r)->x2;\
00094             if((r)->y2 > (idRect)->extents.y2)\
00095               (idRect)->extents.y2 = (r)->y2;\
00096         }
00097 
00098 /*
00099  *   Check to see if there is enough memory in the present region.
00100  */
00101 #define MEMCHECK(reg, rect, firstrect){\
00102         if ((reg)->numRects >= ((reg)->size - 1)){\
00103           (firstrect) = (BOX *) Xrealloc \
00104           ((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\
00105           if ((firstrect) == 0)\
00106             return(0);\
00107           (reg)->size *= 2;\
00108           (rect) = &(firstrect)[(reg)->numRects];\
00109          }\
00110        }
00111 
00112 /*  this routine checks to see if the previous rectangle is the same
00113  *  or subsumes the new rectangle to add.
00114  */
00115 
00116 #define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
00117                (!(((Reg)->numRects > 0)&&\
00118                   ((R-1)->y1 == (Ry1)) &&\
00119                   ((R-1)->y2 == (Ry2)) &&\
00120                   ((R-1)->x1 <= (Rx1)) &&\
00121                   ((R-1)->x2 >= (Rx2))))
00122 
00123 /*  add a rectangle to the given Region */
00124 #define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
00125     if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
00126         CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
00127               (r)->x1 = (rx1);\
00128               (r)->y1 = (ry1);\
00129               (r)->x2 = (rx2);\
00130               (r)->y2 = (ry2);\
00131               EXTENTS((r), (reg));\
00132               (reg)->numRects++;\
00133               (r)++;\
00134             }\
00135         }
00136 
00137 
00138 
00139 /*  add a rectangle to the given Region */
00140 #define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
00141             if ((rx1 < rx2) && (ry1 < ry2) &&\
00142                 CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
00143               (r)->x1 = (rx1);\
00144               (r)->y1 = (ry1);\
00145               (r)->x2 = (rx2);\
00146               (r)->y2 = (ry2);\
00147               (reg)->numRects++;\
00148               (r)++;\
00149             }\
00150         }
00151 
00152 #define EMPTY_REGION(pReg) pReg->numRects = 0
00153 
00154 #define REGION_NOT_EMPTY(pReg) pReg->numRects
00155 
00156 #define INBOX(r, x, y) \
00157       ( ( ((r).x2 >  x)) && \
00158         ( ((r).x1 <= x)) && \
00159         ( ((r).y2 >  y)) && \
00160         ( ((r).y1 <= y)) )
00161 
00162 /*
00163  * number of points to buffer before sending them off
00164  * to scanlines() :  Must be an even number
00165  */
00166 #define NUMPTSTOBUFFER 200
00167 
00168 /*
00169  * used to allocate buffers for points and link
00170  * the buffers together
00171  */
00172 typedef struct _POINTBLOCK {
00173     XPoint pts[NUMPTSTOBUFFER];
00174     struct _POINTBLOCK *next;
00175 } POINTBLOCK;
00176 
00177 #endif