2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Header file for intregions.c
11 #include <graphics/gfxbase.h>
12 #include <graphics/regions.h>
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
26 #define CHECK_EVIL_RECTS 1
30 #define IS_RECT_EVIL(rect) \
32 ((rect)->MaxX < (rect)->MinX) || \
33 ((rect)->MaxY < (rect)->MinY) \
36 #define ARE_COORDS_EVIL(minx,miny,maxx,maxy) \
38 ((maxx) < (minx)) || \
44 #define IS_RECT_EVIL(rect) 0
45 #define ARE_COORDS_EVIL(minx,miny,maxx,maxy) 0
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) \
63 y1 <= (Rect)->MaxY && \
64 y2 >= (Rect)->MinY && \
65 x1 <= (Rect)->MaxX && \
69 #define overlap(a,b) _DoRectsOverlap(&(a), (b).MinX, (b).MinY, (b).MaxX, (b).MaxY)
71 #define _AndRectRect(rect1, rect2, intersect) \
75 if (overlap(*(rect1), *(rect2))) \
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); \
90 #define _AreRectsEqual(Rect1, Rect2) \
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 && \
107 #define _IsPointInRect(Rect, x, y) _IsRectInRect(Rect, (x), (y), (x), (y))
109 #define _SwapRegions(region1, region2) \
115 *region1 = *region2; \
119 #define _TranslateRect(rect, dx, dy) \
122 struct Rectangle *_rect = rect; \
125 (_rect)->MinX += _dx; \
126 (_rect)->MinY += _dy; \
127 (_rect)->MaxX += _dx; \
128 (_rect)->MaxY += _dy; \
131 #define _TranslateRegionRectangles(rr, 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
146 #define InitRegion(region) \
153 (region)->RegionRectangle = NULL; \
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
;
168 /* ugly hack, I know... */
171 typedef BOOL BandOperation
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
,
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
;
203 #endif /* !INTREGIONS_H */