]> Pileus Git - ~andy/gtk/blob - gdk/gdkregion-generic.h
Updated Bulgarian translation by Alexander Shopov <ash@contact.bg>
[~andy/gtk] / gdk / gdkregion-generic.h
1 /* $TOG: region.h /main/9 1998/02/06 17:50:30 kaleb $ */
2 /************************************************************************
3
4 Copyright 1987, 1998  The Open Group
5
6 All Rights Reserved.
7
8 The above copyright notice and this permission notice shall be included in
9 all copies or substantial portions of the Software.
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
14 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
15 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
18 Except as contained in this notice, the name of The Open Group shall not be
19 used in advertising or otherwise to promote the sale, use or other dealings
20 in this Software without prior written authorization from The Open Group.
21
22
23 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
24
25                         All Rights Reserved
26
27 Permission to use, copy, modify, and distribute this software and its 
28 documentation for any purpose and without fee is hereby granted, 
29 provided that the above copyright notice appear in all copies and that
30 both that copyright notice and this permission notice appear in 
31 supporting documentation, and that the name of Digital not be
32 used in advertising or publicity pertaining to distribution of the
33 software without specific, written prior permission.  
34
35 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41 SOFTWARE.
42
43 ************************************************************************/
44
45 #ifndef __GDK_REGION_GENERIC_H__
46 #define __GDK_REGION_GENERIC_H__
47
48 typedef GdkSegment GdkRegionBox;
49
50 /* 
51  *   clip region
52  */
53
54 struct _GdkRegion
55 {
56   long size;
57   long numRects;
58   GdkRegionBox *rects;
59   GdkRegionBox extents;
60 };
61
62 /*  1 if two BOXs overlap.
63  *  0 if two BOXs do not overlap.
64  *  Remember, x2 and y2 are not in the region 
65  */
66 #define EXTENTCHECK(r1, r2) \
67         ((r1)->x2 > (r2)->x1 && \
68          (r1)->x1 < (r2)->x2 && \
69          (r1)->y2 > (r2)->y1 && \
70          (r1)->y1 < (r2)->y2)
71
72 /*
73  *  update region extents
74  */
75 #define EXTENTS(r,idRect){\
76             if((r)->x1 < (idRect)->extents.x1)\
77               (idRect)->extents.x1 = (r)->x1;\
78             if((r)->y1 < (idRect)->extents.y1)\
79               (idRect)->extents.y1 = (r)->y1;\
80             if((r)->x2 > (idRect)->extents.x2)\
81               (idRect)->extents.x2 = (r)->x2;\
82             if((r)->y2 > (idRect)->extents.y2)\
83               (idRect)->extents.y2 = (r)->y2;\
84         }
85
86 #define GROWREGION(reg, nRects){                                                 \
87           if ((reg)->rects == &(reg)->extents) {                                 \
88             (reg)->rects = g_new (GdkRegionBox, (nRects));                       \
89             (reg)->rects[0] = reg->extents;                                      \
90           }                                                                      \
91           else                                                                   \
92             (reg)->rects = g_renew (GdkRegionBox, (reg)->rects, (nRects));       \
93           (reg)->size = (nRects);                                                \
94        }                                 
95
96 /*
97  *   Check to see if there is enough memory in the present region.
98  */
99 #define MEMCHECK(reg, rect, firstrect){                                          \
100         if ((reg)->numRects >= ((reg)->size - 1)) {                              \
101           GROWREGION(reg,2*(reg)->size);                                         \
102           (rect) = &(firstrect)[(reg)->numRects];                                \
103          }                                                                       \
104        }
105
106 /*  this routine checks to see if the previous rectangle is the same
107  *  or subsumes the new rectangle to add.
108  */
109
110 #define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
111                (!(((Reg)->numRects > 0)&&\
112                   ((R-1)->y1 == (Ry1)) &&\
113                   ((R-1)->y2 == (Ry2)) &&\
114                   ((R-1)->x1 <= (Rx1)) &&\
115                   ((R-1)->x2 >= (Rx2))))
116
117 /*  add a rectangle to the given Region */
118 #define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
119     if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
120         CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
121               (r)->x1 = (rx1);\
122               (r)->y1 = (ry1);\
123               (r)->x2 = (rx2);\
124               (r)->y2 = (ry2);\
125               EXTENTS((r), (reg));\
126               (reg)->numRects++;\
127               (r)++;\
128             }\
129         }
130
131
132
133 /*  add a rectangle to the given Region */
134 #define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
135             if ((rx1 < rx2) && (ry1 < ry2) &&\
136                 CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
137               (r)->x1 = (rx1);\
138               (r)->y1 = (ry1);\
139               (r)->x2 = (rx2);\
140               (r)->y2 = (ry2);\
141               (reg)->numRects++;\
142               (r)++;\
143             }\
144         }
145
146 #define EMPTY_REGION(pReg) pReg->numRects = 0
147
148 #define REGION_NOT_EMPTY(pReg) pReg->numRects
149
150 #define INBOX(r, x, y) \
151       ( ( ((r).x2 >  x)) && \
152         ( ((r).x1 <= x)) && \
153         ( ((r).y2 >  y)) && \
154         ( ((r).y1 <= y)) )
155
156 /*
157  * number of points to buffer before sending them off
158  * to scanlines() :  Must be an even number
159  */
160 #define NUMPTSTOBUFFER 200
161
162 /*
163  * used to allocate buffers for points and link
164  * the buffers together
165  */
166 typedef struct _POINTBLOCK {
167   GdkPoint pts[NUMPTSTOBUFFER];
168   struct _POINTBLOCK *next;
169 } POINTBLOCK;
170
171 #endif /* __GDK_REGION_GENERIC_H__ */