Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
XRect.h
1#ifndef RECTSIZEPOINT_DEFINED_H
2#define RECTSIZEPOINT_DEFINED_H
3#pragma once
4
5BEGIN_MOOTOOLS_NAMESPACE
6
7#if defined(__APPLE__) || defined(__LINUX__)
8typedef struct
9{
10 int left;
11 int top;
12 int right;
13 int bottom;
14} RECT;
15
16typedef RECT* LPRECT;
17typedef const RECT* LPCRECT;
18
19typedef struct
20{
21 int x;
22 int y;
23} POINT;
24
25typedef POINT* LPPOINT;
26typedef struct
27{
28 int x;
29 int y;
30} POINTS;
31
32
33
34typedef struct
35{
36 int cx;
37 int cy;
38} SIZE;
39
40typedef SIZE* LPSIZE;
41#endif
42
43// Declared in macos_rect, win_rect...
44bool xIsRectEmpty(const RECT *rect);
45bool xSetRectEmpty(RECT *rect);
46bool xSetRect(RECT *dstrect, int left, int top, int right, int bottom);
47bool xPtInRect(const RECT *rect, POINT pt);
48bool xCopyRect(RECT *dstrect, const RECT *srcrect);
49bool xEqualRect(const RECT *rect1, const RECT *rect2);
50bool xIntersectRect(RECT *dstRect, const RECT *rect1, const RECT *rect2);
51bool xSubtractRect(RECT *dstRect, const RECT *rect1, const RECT *rect2);
52bool xUnionRect(RECT *dstRect, const RECT *rect1, const RECT *rect2);
53bool xInflateRect(RECT *rect, int x, int y);
54bool xOffsetRect(RECT *rect, int x, int y);
55
56/////////////////////////////////////////
57// Definition of the CXSize class
58// This class can be used to replace the SIZE structure
59class CXRect;
60class CXPoint;
61class CXSize;
62
63class DLL_TOOLSFUNCTION CXSize : public SIZE
64{
65public:
66 CXSize() { cx = 0; cy = 0; }
67 CXSize(int CX, int CY) { cx = CX; cy = CY; }
68 CXSize(SIZE sz) { cx = sz.cx; cy = sz.cy; }
69 CXSize(POINT pt) { cx = pt.x; cy = pt.y; }
70 void SetSize(int CX, int CY) { cx = CX; cy = CY; }
71
72 // Operators
73 operator LPSIZE() { return this; }
74 bool operator == (SIZE sz) const { return (cx == sz.cx && cy == sz.cy); }
75 bool operator != (SIZE sz) const { return (cx != sz.cx || cy != sz.cy); }
76 void operator += (SIZE sz) { cx += sz.cx; cy += sz.cy; }
77 void operator -= (SIZE sz) { cx -= sz.cx; cy -= sz.cy; }
78
79 // Operators returning CXSize
80 CXSize operator - () const { return CXSize(-cx, -cy); }
81 CXSize operator + (SIZE sz) const { return CXSize(cx + sz.cx, cy + sz.cy); }
82 CXSize operator - (SIZE sz) const { return CXSize(cx - sz.cx, cy - sz.cy); }
83
84 // Operators returning CXPoint
85 CXPoint operator + (POINT point) const;
86 CXPoint operator - (POINT point) const;
87
88 // Operators returning CXRect
89 CXRect operator + (RECT rc) const;
90 CXRect operator - (RECT rc) const;
91};
92
93
94/////////////////////////////////////////
95// Definition of the CXPoint class
96// This class can be used to replace the POINT structure
97class DLL_TOOLSFUNCTION CXPoint : public POINT
98{
99public:
100 CXPoint() { x = 0; y = 0; }
101 CXPoint(int X, int Y) { x = X; y = Y; }
102 CXPoint(POINT pt) { x = pt.x; y = pt.y; }
103 CXPoint(POINTS pts) { x = pts.x; y = pts.y; }
104 CXPoint(SIZE sz) { x = sz.cx; y = sz.cy; }
105
106 void Offset(int dx, int dy) { x += dx; y += dy; }
107 void Offset(POINT pt) { x += pt.x; y += pt.y; }
108 void Offset(SIZE sz) { x += sz.cx; y += sz.cy; }
109 void SetPoint(int X, int Y) { x = X; y = Y; }
110
111 // Operators
112 operator LPPOINT() { return this; }
113 bool operator == (POINT pt) const { return ((x == pt.x) && (y == pt.y)); }
114 bool operator != (POINT pt) const { return ((x != pt.x) || (y != pt.y)); }
115 void operator += (SIZE sz) { x += sz.cx; y += sz.cy; }
116 void operator -= (SIZE sz) { x -= sz.cx; y -= sz.cy; }
117 void operator += (POINT pt) { x += pt.x; y += pt.y; }
118 void operator -= (POINT pt) { x -= pt.x; y -= pt.y; }
119
120 // Operators returning CXPoint
121 CXPoint operator - () const { return CXPoint(-x, -y); }
122 CXPoint operator + (SIZE sz) const { return CXPoint(x + sz.cx, y + sz.cy); }
123 CXPoint operator - (SIZE sz) const { return CXPoint(x - sz.cx, y - sz.cy); }
124 CXPoint operator + (POINT pt) const { return CXPoint(x + pt.x, y + pt.y); }
125 CXPoint operator - (POINT pt) const { return CXPoint(x - pt.x, y - pt.y); }
126
127 // Operators returning CXRect
128 CXRect operator + (RECT rc) const;
129 CXRect operator - (RECT rc) const;
130};
131
132
133/////////////////////////////////////////
134// Definition of the CXRect class
135// This class can be used to replace the RECT structure.
136class DLL_TOOLSFUNCTION CXRect : public RECT
137{
138public:
139 CXRect() { left = top = right = bottom = 0; }
140 CXRect(int l, int t, int r, int b) { left = l; top = t; right = r; bottom = b; }
141 CXRect(RECT rc) { left = rc.left; top = rc.top; right = rc.right; bottom = rc.bottom; }
142 CXRect(POINT pt, SIZE sz) { right = (left = pt.x) + sz.cx; bottom = (top = pt.y) + sz.cy; }
143 CXRect(POINT topLeft, POINT bottomRight) { left = topLeft.x; top = topLeft.y; right = bottomRight.x; bottom = bottomRight.y; }
144
145 bool CopyRect(RECT rc) { return xCopyRect(this, &rc); }
146 bool DeflateRect(int x, int y) { return xInflateRect(this, -x, -y); }
147 bool DeflateRect(SIZE size) { return xInflateRect(this, -size.cx, -size.cy); }
148 bool DeflateRect(RECT rc) { return xInflateRect(this, rc.left - rc.right, rc.top - rc.bottom); }
149 bool DeflateRect(int l, int t, int r, int b) { return xInflateRect(this, l - r, t - b); }
150 bool EqualRect(RECT rc) const { return xEqualRect(&rc, this); }
151 bool InflateRect(int dx, int dy) { return xInflateRect(this, dx, dy); }
152 bool InflateRect(SIZE sz) { return xInflateRect(this, sz.cx, sz.cy); }
153 bool InflateRect(RECT rc) { return xInflateRect(this, rc.right - rc.left, rc.bottom - rc.top); }
154 bool InflateRect(int l, int t, int r, int b) { return xInflateRect(this, r - l, b - t); }
155 bool IntersectRect(RECT rc1, RECT rc2) { return xIntersectRect(this, &rc1, &rc2); }
156 bool IsRectEmpty() const { return xIsRectEmpty(this); }
157 bool IsRectNull() const { return (left == 0 && right == 0 && top == 0 && bottom == 0); }
158 CXRect MulDiv(int nMult, int nDiv) const {
159 return CXRect((left * nMult) / nDiv, (top * nMult) / nDiv,
160 (right * nMult) / nDiv, (bottom * nMult) / nDiv);
161 }
162 void NormalizeRect() {
163 int nTemp; if (left > right) { nTemp = left; left = right; right = nTemp; }
164 if (top > bottom) { nTemp = top; top = bottom; bottom = nTemp; }
165 }
166 bool OffsetRect(int dx, int dy) { return xOffsetRect(this, dx, dy); }
167 bool OffsetRect(POINT pt) { return xOffsetRect(this, pt.x, pt.y); }
168 bool OffsetRect(SIZE size) { return xOffsetRect(this, size.cx, size.cy); }
169 bool PtInRect(POINT pt) const { return xPtInRect(this, pt); }
170 bool SetRect(int l, int t, int r, int b) { return xSetRect(this, l, t, r, b); }
171 bool SetRect(POINT TopLeft, POINT BtmRight) { return xSetRect(this, TopLeft.x, TopLeft.y, BtmRight.x, BtmRight.y); }
172 bool SetRectEmpty() { return xSetRectEmpty(this); }
173 bool SubtractRect(RECT rc1, RECT rc2) { return xSubtractRect(this, &rc1, &rc2); }
174 bool UnionRect(RECT rc1, RECT rc2) { return xUnionRect(this, &rc1, &rc2); }
175
176 // Reposition rectangle
177 void MoveToX(int x) { right = Width() + x; left = x; }
178 void MoveToY(int y) { bottom = Height() + y; top = y; }
179 void MoveToXY(int x, int y) { MoveToX(x); MoveToY(y); }
180 void MoveToXY(POINT pt) { MoveToX(pt.x); MoveToY(pt.y); }
181
182 // Attributes
183 int Height() const { return bottom - top; }
184 int Width() const { return right - left; }
185 CXSize Size() const { return CXSize(Width(), Height()); }
186 CXPoint CenterPoint() const { return CXPoint((left + right) / 2, (top + bottom) / 2); }
187 CXPoint TopLeft() const { return CXPoint(left, top); }
188 CXPoint BottomRight() const { return CXPoint(right, bottom); }
189
190 // operators
191 operator LPRECT() { return this; }
192 operator LPCRECT() const { return this; }
193 bool operator == (RECT rc) const { return xEqualRect(this, &rc); }
194 bool operator != (RECT rc) const { return !xEqualRect(this, &rc); }
195 void operator += (POINT pt) { xOffsetRect(this, pt.x, pt.y); }
196 void operator += (SIZE size) { xOffsetRect(this, size.cx, size.cy); }
197 void operator += (RECT rc) { xInflateRect(this, rc.right - rc.left, rc.bottom - rc.top); }
198 void operator -= (RECT rc) { xInflateRect(this, rc.left - rc.right, rc.top - rc.bottom); }
199 void operator -= (POINT pt) { xOffsetRect(this, -pt.x, -pt.y); }
200 void operator -= (SIZE sz) { xOffsetRect(this, -sz.cx, -sz.cy); }
201 void operator &= (RECT rc) { xIntersectRect(this, this, &rc); }
202 void operator |= (RECT rc) { xUnionRect(this, this, &rc); }
203
204 // Operators returning CXRect
205 CXRect operator + (POINT pt) const { CXRect rc(*this); xOffsetRect(&rc, pt.x, pt.y); return rc; }
206 CXRect operator - (POINT pt) const { CXRect rc(*this); xOffsetRect(&rc, -pt.x, -pt.y); return rc; }
207 CXRect operator + (SIZE sz) const { CXRect rc(*this); xOffsetRect(&rc, sz.cx, sz.cy); return rc; }
208 CXRect operator - (SIZE sz) const { CXRect rc(*this); xOffsetRect(&rc, -sz.cx, -sz.cy); return rc; }
209 CXRect operator + (RECT rc) const { CXRect rc1(*this); rc1.InflateRect(rc); return rc1; }
210 CXRect operator - (RECT rc) const { CXRect rc1(*this); rc1.DeflateRect(rc); return rc1; }
211 CXRect operator & (RECT rc) const { CXRect rc1; xIntersectRect(&rc1, this, &rc); return rc1; }
212 CXRect operator | (RECT rc) const { CXRect rc1; xUnionRect(&rc1, this, &rc); return rc1; }
213};
214
215// CXSize member function definitions
216inline CXPoint CXSize::operator + (POINT pt) const { return CXPoint(pt) + *this; }
217inline CXPoint CXSize::operator - (POINT pt) const { return CXPoint(pt) - *this; }
218inline CXRect CXSize::operator + (RECT rc) const { return CXRect(rc) + *this; }
219inline CXRect CXSize::operator - (RECT rc) const { return CXRect(rc) - *this; }
220
221// CXPoint member function definitions
222inline CXRect CXPoint::operator + (RECT rc) const { return CXRect(rc) + *this; }
223inline CXRect CXPoint::operator - (RECT rc) const { return CXRect(rc) - *this; }
224
225END_MOOTOOLS_NAMESPACE
226
227#endif // RECTSIZEPOINT_DEFINED_H
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition XRect.h:98
Definition XRect.h:137
Definition XRect.h:64