Indentation fix, cleanup.
[AROS.git] / rom / graphics / intregions.h
blob2393962c8634d18f14492c606ab194a5b3cc0783
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Header file for intregions.c
6 Lang: english
7 */
8 #ifndef INTREGIONS_H
9 #define INTREGIONS_H
11 #include <graphics/gfxbase.h>
12 #include <graphics/regions.h>
14 /* CHECK_EVIL_RECTS:
16 If 1, code will assume such rects to be like an empty region
18 If 0, code reacts on such rects in a probably undefined matter
19 and things like layers.library might freak out if an app for
20 example tries to install a clip rectangle (region) with maxx < minx
21 and/or maxy < miny. Causing apps to render outside of layer/window
22 and possibly crash.
26 #define CHECK_EVIL_RECTS 1
28 #if CHECK_EVIL_RECTS
30 #define IS_RECT_EVIL(rect) \
31 ( \
32 ((rect)->MaxX < (rect)->MinX) || \
33 ((rect)->MaxY < (rect)->MinY) \
36 #define ARE_COORDS_EVIL(minx,miny,maxx,maxy) \
37 ( \
38 ((maxx) < (minx)) || \
39 ((maxy) < (miny)) \
42 #else
44 #define IS_RECT_EVIL(rect) 0
45 #define ARE_COORDS_EVIL(minx,miny,maxx,maxy) 0
47 #endif
50 BOOL clearrectrect(struct Rectangle* clearrect, struct Rectangle* rect,
51 struct RegionRectangle** erg);
53 #define Bounds(x) (&(x)->bounds)
54 #define MinX(rr) (Bounds(rr)->MinX)
55 #define MaxX(rr) (Bounds(rr)->MaxX)
56 #define MinY(rr) (Bounds(rr)->MinY)
57 #define MaxY(rr) (Bounds(rr)->MaxY)
58 #define Width(rr) (MaxX(rr) - MinX(rr) + 1)
59 #define Height(rr) (MaxY(rr) - MinY(rr) + 1)
61 #define _DoRectsOverlap(Rect, x1, y1, x2, y2) \
62 ( \
63 y1 <= (Rect)->MaxY && \
64 y2 >= (Rect)->MinY && \
65 x1 <= (Rect)->MaxX && \
66 x2 >= (Rect)->MinX \
69 #define overlap(a,b) _DoRectsOverlap(&(a), (b).MinX, (b).MinY, (b).MaxX, (b).MaxY)
71 #define _AndRectRect(rect1, rect2, intersect) \
72 ({ \
73 BOOL res; \
75 if (overlap(*(rect1), *(rect2))) \
76 { \
77 (intersect)->MinX = MAX((rect1)->MinX, (rect2)->MinX); \
78 (intersect)->MinY = MAX((rect1)->MinY, (rect2)->MinY); \
79 (intersect)->MaxX = MIN((rect1)->MaxX, (rect2)->MaxX); \
80 (intersect)->MaxY = MIN((rect1)->MaxY, (rect2)->MaxY); \
82 res = TRUE; \
83 } \
84 else \
85 res = FALSE; \
87 res; \
90 #define _AreRectsEqual(Rect1, Rect2) \
91 ( \
92 (Rect1)->MinX == (Rect2)->MinX && \
93 (Rect1)->MinY == (Rect2)->MinY && \
94 (Rect1)->MaxX == (Rect2)->MaxX && \
95 (Rect1)->MaxY == (Rect2)->MaxY \
98 /* Checks whether the rectangle (x1, y1)-(x2, y2) is completely contained in Rect */
99 #define _IsRectInRect(Rect, x1, y1, x2, y2) \
101 y1 >= (Rect)->MinY && \
102 y2 <= (Rect)->MaxY && \
103 x1 >= (Rect)->MinX && \
104 x2 <= (Rect)->MaxX \
107 #define _IsPointInRect(Rect, x, y) _IsRectInRect(Rect, (x), (y), (x), (y))
109 #define _SwapRegions(region1, region2) \
110 do \
112 struct Region tmp; \
114 tmp = *region1; \
115 *region1 = *region2; \
116 *region2 = tmp; \
117 } while (0);
119 #define _TranslateRect(rect, dx, dy) \
120 do \
122 struct Rectangle *_rect = rect; \
123 WORD _dx = dx; \
124 WORD _dy = dy; \
125 (_rect)->MinX += _dx; \
126 (_rect)->MinY += _dy; \
127 (_rect)->MaxX += _dx; \
128 (_rect)->MaxY += _dy; \
129 } while(0)
131 #define _TranslateRegionRectangles(rr, dx, dy) \
132 if (dx || dy) \
134 struct RegionRectangle *_rr; \
136 for (_rr = rr; _rr; _rr = _rr->Next) \
137 _TranslateRect(&_rr->bounds, dx, dy); \
141 ** Important: ClearRegion calls InitRegion(). If you change something here
142 ** which should not be done in case of ClearRegion() then don't forget to
143 ** fix ClearRegion!
146 #define InitRegion(region) \
147 do \
149 MinX(region) = 0; \
150 MinY(region) = 0; \
151 MaxX(region) = 0; \
152 MaxY(region) = 0; \
153 (region)->RegionRectangle = NULL; \
154 } while (0)
156 /* Copy RegionRectangles from R1 to R2. R2 will be overwritten!!! */
157 static inline BOOL _CopyRegionRectangles(struct Region *R1, struct Region *R2, struct GfxBase *GfxBase)
159 if (_LinkRegionRectangleList(R1->RegionRectangle, &R2->RegionRectangle, GfxBase))
161 R2->RegionRectangle = Head(R2->RegionRectangle);
162 R2->bounds = R1->bounds;
163 return TRUE;
165 return FALSE;
168 /* ugly hack, I know... */
169 #ifndef GfxBase
171 typedef BOOL BandOperation
173 LONG OffX1,
174 LONG OffX2,
175 LONG MinY,
176 LONG MaxY,
177 struct RegionRectangle *Src1,
178 struct RegionRectangle *Src2,
179 struct RegionRectangle **DstPtr,
180 struct RegionRectangle **NextSrc1Ptr,
181 struct RegionRectangle **NextSrc2Ptr,
182 struct GfxBase *GfxBase
185 BOOL _DoOperationBandBand
187 BandOperation *Operation,
188 LONG OffX1,
189 LONG OffX2,
190 LONG OffY1,
191 LONG OffY2,
192 struct RegionRectangle *Src1,
193 struct RegionRectangle *Src2,
194 struct RegionRectangle **DstPtr,
195 struct Rectangle *DstBounds,
196 struct GfxBase *GfxBase
199 extern BandOperation _OrBandBand, _AndBandBand, _ClearBandBand;
201 #endif
203 #endif /* !INTREGIONS_H */