r4493@vps: verhaegs | 2007-04-19 14:44:00 -0400
[AROS.git] / rom / graphics / intregions.h
blob6955750017942e31b4ff10fb14d9423c515b6ad1
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>
15 BOOL clearrectrect(struct Rectangle* clearrect, struct Rectangle* rect,
16 struct RegionRectangle** erg);
18 #define Bounds(x) (&(x)->bounds)
19 #define MinX(rr) (Bounds(rr)->MinX)
20 #define MaxX(rr) (Bounds(rr)->MaxX)
21 #define MinY(rr) (Bounds(rr)->MinY)
22 #define MaxY(rr) (Bounds(rr)->MaxY)
23 #define Width(rr) (MaxX(rr) - MinX(rr) + 1)
24 #define Height(rr) (MaxY(rr) - MinY(rr) + 1)
26 #define _DoRectsOverlap(Rect, x1, y1, x2, y2) \
27 ( \
28 y1 <= (Rect)->MaxY && \
29 y2 >= (Rect)->MinY && \
30 x1 <= (Rect)->MaxX && \
31 x2 >= (Rect)->MinX \
34 #define overlap(a,b) _DoRectsOverlap(&(a), (b).MinX, (b).MinY, (b).MaxX, (b).MaxY)
36 #define _AndRectRect(rect1, rect2, intersect) \
37 ({ \
38 BOOL res; \
40 if (overlap(*(rect1), *(rect2))) \
41 { \
42 (intersect)->MinX = MAX((rect1)->MinX, (rect2)->MinX); \
43 (intersect)->MinY = MAX((rect1)->MinY, (rect2)->MinY); \
44 (intersect)->MaxX = MIN((rect1)->MaxX, (rect2)->MaxX); \
45 (intersect)->MaxY = MIN((rect1)->MaxY, (rect2)->MaxY); \
47 res = TRUE; \
48 } \
49 else \
50 res = FALSE; \
52 res; \
55 #define _AreRectsEqual(Rect1, Rect2) \
56 ( \
57 (Rect1)->MinX == (Rect2)->MinX && \
58 (Rect1)->MinY == (Rect2)->MinY && \
59 (Rect1)->MaxX == (Rect2)->MaxX && \
60 (Rect1)->MaxY == (Rect2)->MaxY \
63 /* Checks whether the rectangle (x1, y1)-(x2, y2) is completely contained in Rect */
64 #define _IsRectInRect(Rect, x1, y1, x2, y2) \
65 ( \
66 y1 >= (Rect)->MinY && \
67 y2 <= (Rect)->MaxY && \
68 x1 >= (Rect)->MinX && \
69 x2 <= (Rect)->MaxX \
72 #define _IsPointInRect(Rect, x, y) _IsRectInRect(Rect, (x), (y), (x), (y))
74 #define _SwapRegions(region1, region2) \
75 do \
76 { \
77 struct Region tmp; \
79 tmp = *region1; \
80 *region1 = *region2; \
81 *region2 = tmp; \
82 } while (0);
84 #define _TranslateRect(rect, dx, dy) \
85 do \
86 { \
87 struct Rectangle *_rect = rect; \
88 WORD _dx = dx; \
89 WORD _dy = dy; \
90 (_rect)->MinX += _dx; \
91 (_rect)->MinY += _dy; \
92 (_rect)->MaxX += _dx; \
93 (_rect)->MaxY += _dy; \
94 } while(0)
96 #define _TranslateRegionRectangles(rr, dx, dy) \
97 if (dx || dy) \
98 { \
99 struct RegionRectangle *_rr; \
101 for (_rr = rr; _rr; _rr = _rr->Next) \
102 _TranslateRect(&_rr->bounds, dx, dy); \
106 ** Important: ClearRegion calls InitRegion(). If you change something here
107 ** which should not be done in case of ClearRegion() then don't forget to
108 ** fix ClearRegion!
111 #define InitRegion(region) \
112 do \
114 MinX(region) = 0; \
115 MinY(region) = 0; \
116 MaxX(region) = 0; \
117 MaxY(region) = 0; \
118 (region)->RegionRectangle = NULL; \
119 } while (0)
122 /* ugly hack, I know... */
123 #ifndef GfxBase
125 typedef BOOL BandOperation
127 LONG OffX1,
128 LONG OffX2,
129 LONG MinY,
130 LONG MaxY,
131 struct RegionRectangle *Src1,
132 struct RegionRectangle *Src2,
133 struct RegionRectangle **DstPtr,
134 struct RegionRectangle **NextSrc1Ptr,
135 struct RegionRectangle **NextSrc2Ptr,
136 struct GfxBase *GfxBase
139 BOOL _DoOperationBandBand
141 BandOperation *Operation,
142 LONG OffX1,
143 LONG OffX2,
144 LONG OffY1,
145 LONG OffY2,
146 struct RegionRectangle *Src1,
147 struct RegionRectangle *Src2,
148 struct RegionRectangle **DstPtr,
149 struct Rectangle *DstBounds,
150 struct GfxBase *GfxBase
153 extern BandOperation _OrBandBand, _AndBandBand, _ClearBandBand;
155 #endif
157 #endif /* !INTREGIONS_H */