4 * Copyright 2016 Mark Jansen
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 class CPoint
: public tagPOINT
37 CPoint(int initX
, int initY
) throw()
43 CPoint(POINT initPt
) throw()
45 *((POINT
*)this) = initPt
;
48 CPoint(SIZE initSize
) throw()
50 *((SIZE
*)this) = initSize
;
53 CPoint(LPARAM dwPoint
) throw()
59 void Offset(int xOffset
, int yOffset
) throw()
65 void Offset(POINT point
) throw()
67 Offset(point
.x
, point
.y
);
70 void Offset(SIZE size
) throw()
72 Offset(size
.cx
, size
.cy
);
75 BOOL
operator==(POINT point
) const throw()
77 return (x
== point
.x
&& y
== point
.y
);
80 BOOL
operator!=(POINT point
) const throw()
82 return !(*this == point
);
85 void operator+=(SIZE size
) throw()
90 void operator+=(POINT point
) throw()
95 void operator-=(SIZE size
) throw()
97 Offset(-size
.cx
, -size
.cy
);
100 void operator-=(POINT point
) throw()
102 Offset(-point
.x
, -point
.y
);
105 CPoint
operator+(SIZE size
) const throw()
107 return CPoint(x
+ size
.cx
, y
+ size
.cy
);
110 CPoint
operator+(POINT point
) const throw()
112 return CPoint(x
+ point
.x
, y
+ point
.y
);
115 CRect
operator+(const RECT
* lpRect
) const throw();
117 CSize
operator-(POINT point
) const throw();
119 CPoint
operator-(SIZE size
) const throw()
121 return CPoint(x
- size
.cx
, y
- size
.cy
);
124 CRect
operator-(const RECT
* lpRect
) const throw();
126 CPoint
operator-() const throw()
128 return CPoint(-x
, -y
);
132 class CSize
: public tagSIZE
140 CSize(int initCX
, int initCY
) throw()
146 CSize(SIZE initSize
) throw()
148 *((SIZE
*)this) = initSize
;
151 CSize(POINT initPt
) throw()
153 *((POINT
*)this) = initPt
;
156 CSize(DWORD dwSize
) throw()
162 BOOL
operator==(SIZE size
) const throw()
164 return (size
.cx
== cx
&& size
.cy
== cy
);
167 BOOL
operator!=(SIZE size
) const throw()
169 return !(*this == size
);
172 void operator+=(SIZE size
) throw()
178 void operator-=(SIZE size
) throw()
184 CSize
operator+(SIZE size
) const throw()
186 return CSize(cx
+ size
.cx
, cy
+ size
.cy
);
189 CPoint
operator+(POINT point
) const throw()
191 return CPoint(cx
+ point
.x
, cy
+ point
.y
);
194 CRect
operator+(const RECT
* lpRect
) const throw();
196 CSize
operator-(SIZE size
) const throw()
198 return CSize(cx
- size
.cx
, cy
- size
.cy
);
201 CPoint
operator-(POINT point
) const throw()
203 return CPoint(cx
- point
.x
, cy
- point
.y
);
206 CRect
operator-(const RECT
* lpRect
) const throw();
208 CSize
operator-() const throw()
210 return CSize(-cx
, -cy
);
215 CSize
CPoint::operator-(POINT point
) const throw()
217 return CSize(x
- point
.x
, y
- point
.y
);
221 class CRect
: public tagRECT
226 left
= top
= right
= bottom
= 0;
229 CRect(int l
, int t
, int r
, int b
) throw()
237 CRect(const RECT
& srcRect
) throw()
241 right
= srcRect
.right
;
242 bottom
= srcRect
.bottom
;
245 CRect(LPCRECT lpSrcRect
) throw()
247 left
= lpSrcRect
->left
;
248 top
= lpSrcRect
->top
;
249 right
= lpSrcRect
->right
;
250 bottom
= lpSrcRect
->bottom
;
253 CRect(POINT point
, SIZE size
) throw()
257 right
= point
.x
+ size
.cx
;
258 bottom
= point
.y
+ size
.cy
;
261 CRect(POINT topLeft
, POINT bottomRight
) throw()
265 right
= bottomRight
.x
;
266 bottom
= bottomRight
.y
;
269 CPoint
& BottomRight() throw()
271 return ((CPoint
*)this)[1];
274 const CPoint
& BottomRight() const throw()
276 return ((const CPoint
*)this)[1];
279 CPoint
CenterPoint() const throw()
281 return CPoint(left
+ (Width() >> 1), top
+ (Height() >> 1));
284 void CopyRect(LPCRECT lpSrcRect
) throw()
286 ::CopyRect(this, lpSrcRect
);
289 void DeflateRect(int x
, int y
) throw()
291 ::InflateRect(this, -x
, -y
);
294 void DeflateRect(SIZE size
) throw()
296 ::InflateRect(this, -size
.cx
, -size
.cy
);
299 void DeflateRect(LPCRECT lpRect
) throw()
301 DeflateRect(lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
304 void DeflateRect(int l
, int t
, int r
, int b
) throw()
312 BOOL
EqualRect(LPCRECT lpRect
) const throw()
314 return ::EqualRect(this, lpRect
);
318 int Height() const throw()
323 void InflateRect(int x
, int y
) throw()
325 ::InflateRect(this, x
, y
);
328 void InflateRect(SIZE size
) throw()
330 ::InflateRect(this, size
.cx
, size
.cy
);
333 void InflateRect(LPCRECT lpRect
) throw()
335 InflateRect(lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
338 void InflateRect(int l
, int t
, int r
, int b
) throw()
346 BOOL
IntersectRect(LPCRECT lpRect1
, LPCRECT lpRect2
) throw()
348 return ::IntersectRect(this, lpRect1
, lpRect2
);
351 BOOL
IsRectEmpty() const throw()
353 return ::IsRectEmpty(this);
356 BOOL
IsRectNull() const throw()
358 return (left
== 0 && right
== 0 &&
359 top
== 0 && bottom
== 0);
362 //void MoveToX(int x) throw()
363 //void MoveToXY(int x, int y) throw()
364 //void MoveToXY(POINT point) throw()
365 //void MoveToY(int y) throw()
366 //void NormalizeRect() throw()
368 void OffsetRect(int x
, int y
) throw()
370 ::OffsetRect(this, x
, y
);
373 void OffsetRect(POINT point
) throw()
375 ::OffsetRect(this, point
.x
, point
.y
);
378 void OffsetRect(SIZE size
) throw()
380 ::OffsetRect(this, size
.cx
, size
.cy
);
383 //BOOL PtInRect(POINT point) const throw()
384 //void SetRect(int x1, int y1, int x2, int y2) throw()
385 //void SetRectEmpty() throw()
386 //CSize Size() const throw()
387 //BOOL SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2) throw()
389 CPoint
& TopLeft() throw()
391 return ((CPoint
*)this)[0];
394 const CPoint
& TopLeft() const throw()
396 return ((const CPoint
*)this)[0];
399 BOOL
UnionRect(LPCRECT lpRect1
, LPCRECT lpRect2
) throw()
401 return ::UnionRect(this, lpRect1
, lpRect2
);
404 int Width() const throw()
410 BOOL
operator==(const RECT
& rect
) const throw()
412 return (left
== rect
.left
&&
414 right
== rect
.right
&&
415 bottom
== rect
.bottom
);
418 BOOL
operator!=(const RECT
& rect
) const throw()
420 return !(*this == rect
);
423 void operator=(const RECT
& srcRect
) throw()
427 right
= srcRect
.right
;
428 bottom
= srcRect
.bottom
;
431 void operator+=(POINT point
) throw()
436 void operator+=(SIZE size
) throw()
441 void operator+=(LPCRECT lpRect
) throw()
446 void operator-=(POINT point
) throw()
448 OffsetRect(-point
.x
, -point
.y
);
451 void operator-=(SIZE size
) throw()
453 OffsetRect(-size
.cx
, -size
.cy
);
456 void operator-=(LPCRECT lpRect
) throw()
462 CRect
operator+(POINT point
) const throw()
469 CRect
operator+(LPCRECT lpRect
) const throw()
472 r
.InflateRect(lpRect
);
476 CRect
operator+(SIZE size
) const throw()
483 CRect
operator-(POINT point
) const throw()
486 r
.OffsetRect(-point
.x
, -point
.y
);
490 CRect
operator-(SIZE size
) const throw()
493 r
.OffsetRect(-size
.cx
, -size
.cy
);
497 CRect
operator-(LPCRECT lpRect
) const throw()
500 r
.DeflateRect(lpRect
);
504 void operator&=(const RECT
& rect
) throw()
506 IntersectRect(this, &rect
);
509 CRect
operator&(const RECT
& rect2
) const throw()
512 r
.IntersectRect(this, &rect2
);
516 void operator|=(const RECT
& rect
) throw()
518 UnionRect(this, &rect
);
521 CRect
operator|(const RECT
& rect2
) const throw()
524 r
.UnionRect(this, &rect2
);
528 operator LPRECT() throw()
533 operator LPCRECT() const throw()
539 CRect
CPoint::operator+(const RECT
* lpRect
) const throw()
546 CRect
CPoint::operator-(const RECT
* lpRect
) const throw()
553 CRect
CSize::operator+(const RECT
* lpRect
) const throw()
560 CRect
CSize::operator-(const RECT
* lpRect
) const throw()