22 #ifndef BAGEL_MFC_ATLTYPES_H 23 #define BAGEL_MFC_ATLTYPES_H 25 #include "bagel/mfc/minwindef.h" 47 CSize(
int initCX,
int initCY);
56 bool operator==(
SIZE size)
const;
57 bool operator!=(
SIZE size)
const;
58 void operator+=(
SIZE size);
59 void operator-=(
SIZE size);
60 void SetSize(
int CX,
int CY);
65 CSize operator-()
const;
72 CRect operator+(
const RECT *lpRect)
const;
73 CRect operator-(
const RECT *lpRect)
const;
103 void Offset(
POINT point);
104 void Offset(
SIZE size);
105 void SetPoint(
int X,
int Y);
107 bool operator==(
POINT point)
const;
108 bool operator!=(
POINT point)
const;
109 void operator+=(
SIZE size);
110 void operator-=(
SIZE size);
111 void operator+=(
POINT point);
112 void operator-=(
POINT point);
124 CRect operator+(
const RECT *lpRect)
const;
125 CRect operator-(
const RECT *lpRect)
const;
160 CPoint CenterPoint()
const;
162 void SwapLeftRight();
163 static void WINAPI SwapLeftRight(
LPRECT lpRect);
170 bool IsRectEmpty()
const;
172 bool IsRectNull()
const;
174 bool PtInRect(
POINT point)
const;
190 void CopyRect(
LPCRECT lpSrcRect);
192 bool EqualRect(
LPCRECT lpRect)
const;
203 void InflateRect(
SIZE size);
207 void InflateRect(
LPCRECT lpRect);
219 void DeflateRect(
SIZE size);
220 void DeflateRect(
LPCRECT lpRect);
231 void OffsetRect(
SIZE size);
232 void OffsetRect(
POINT point);
233 void NormalizeRect();
241 void MoveToXY(
POINT point);
259 void operator=(
const RECT &srcRect);
260 bool operator==(
const RECT &rect)
const;
261 bool operator!=(
const RECT &rect)
const;
262 void operator+=(
POINT point);
263 void operator+=(
SIZE size);
264 void operator+=(
LPCRECT lpRect);
265 void operator-=(
POINT point);
266 void operator-=(
SIZE size);
267 void operator-=(
LPCRECT lpRect);
268 void operator&=(
const RECT &rect);
269 void operator|=(
const RECT &rect);
278 CRect operator&(
const RECT &rect2)
const;
279 CRect operator|(
const RECT &rect2)
const;
288 return *((
CPoint *)&right);
293 inline CSize::CSize() {
305 inline CSize::CSize(
SIZE initSize) {
306 *(
SIZE *)
this = initSize;
309 inline CSize::CSize(
POINT initPt) {
310 *(
POINT *)
this = initPt;
313 inline CSize::CSize(uint32 dwSize) {
314 cx = (short)LOWORD(dwSize);
315 cy = (short)HIWORD(dwSize);
318 inline bool CSize::operator==(
SIZE size)
const {
319 return (cx == size.cx && cy == size.cy);
322 inline bool CSize::operator!=(
SIZE size)
const {
323 return (cx != size.cx || cy != size.cy);
326 inline void CSize::operator+=(
SIZE size) {
331 inline void CSize::operator-=(
SIZE size) {
336 inline void CSize::SetSize(
343 inline CSize CSize::operator+(
SIZE size)
const {
344 return CSize(cx + size.cx, cy + size.cy);
347 inline CSize CSize::operator-(
SIZE size)
const {
348 return CSize(cx - size.cx, cy - size.cy);
351 inline CSize CSize::operator-()
const {
352 return CSize(-cx, -cy);
355 inline CPoint CSize::operator+(
POINT point)
const {
356 return CPoint(cx + point.x, cy + point.y);
359 inline CPoint CSize::operator-(
POINT point)
const {
360 return CPoint(cx - point.x, cy - point.y);
363 inline CRect CSize::operator+(
const RECT *lpRect)
const {
364 return CRect(lpRect) + *
this;
367 inline CRect CSize::operator-(
const RECT *lpRect)
const {
368 return CRect(lpRect) - *
this;
372 inline CPoint::CPoint() {
377 inline CPoint::CPoint(
384 inline CPoint::CPoint(
POINT initPt) {
385 *(
POINT *)
this = initPt;
388 inline CPoint::CPoint(
SIZE initSize) {
389 *(
SIZE *)
this = initSize;
392 inline CPoint::CPoint(LPARAM dwPoint) {
393 x = (short)LOWORD(dwPoint);
394 y = (short)HIWORD(dwPoint);
397 inline void CPoint::Offset(
404 inline void CPoint::Offset(
POINT point) {
409 inline void CPoint::Offset(
SIZE size) {
414 inline void CPoint::SetPoint(
421 inline bool CPoint::operator==(
POINT point)
const {
422 return (x == point.x && y == point.y);
425 inline bool CPoint::operator!=(
POINT point)
const {
426 return (x != point.x || y != point.y);
429 inline void CPoint::operator+=(
SIZE size) {
434 inline void CPoint::operator-=(
SIZE size) {
439 inline void CPoint::operator+=(
POINT point) {
444 inline void CPoint::operator-=(
POINT point) {
449 inline CPoint CPoint::operator+(
SIZE size)
const {
450 return CPoint(x + size.cx, y + size.cy);
453 inline CPoint CPoint::operator-(
SIZE size)
const {
454 return CPoint(x - size.cx, y - size.cy);
457 inline CPoint CPoint::operator-()
const {
461 inline CPoint CPoint::operator+(
POINT point)
const {
462 return CPoint(x + point.x, y + point.y);
465 inline CSize CPoint::operator-(
POINT point)
const {
466 return CSize(x - point.x, y - point.y);
469 inline CRect CPoint::operator+(
const RECT *lpRect)
const {
470 return CRect(lpRect) + *
this;
473 inline CRect CPoint::operator-(
const RECT *lpRect)
const {
474 return CRect(lpRect) - *
this;
478 inline CRect::CRect() {
496 inline CRect::CRect(
const RECT &srcRect) {
500 inline CRect::CRect(
LPCRECT lpSrcRect) {
504 inline CRect::CRect(
const POINT &point,
const SIZE &size) {
505 right = (left = point.x) + size.cx;
506 bottom = (top = point.y) + size.cy;
509 inline CRect::CRect(
const POINT &topLeft,
const POINT &bottomRight) {
512 right = bottomRight.x;
513 bottom = bottomRight.y;
516 inline int CRect::Width()
const {
520 inline int CRect::Height()
const {
524 inline CSize CRect::Size()
const {
525 return CSize(right - left, bottom - top);
528 inline CPoint CRect::CenterPoint()
const {
529 return CPoint((left + right) / 2, (top + bottom) / 2);
532 inline void CRect::SwapLeftRight() {
533 SwapLeftRight(
LPRECT(
this));
536 inline void WINAPI CRect::SwapLeftRight(
LPRECT lpRect) {
537 long temp = lpRect->left;
538 lpRect->left = lpRect->right;
539 lpRect->right = temp;
542 inline CRect::operator
LPRECT() {
546 inline CRect::operator
LPCRECT()
const {
550 inline bool CRect::IsRectEmpty()
const {
551 return (left >= right) && (top >= bottom);
554 inline bool CRect::IsRectNull()
const {
555 return (left == 0 && right == 0 && top == 0 && bottom == 0);
558 inline bool CRect::PtInRect(
POINT point)
const {
559 return (point.x >= left) && (point.x < right) &&
560 (point.y >= top) && (point.y < bottom);
563 inline void CRect::SetRect(
int x1,
int y1,
571 inline void CRect::SetRect(
576 right = bottomRight.x;
577 bottom = bottomRight.y;
580 inline void CRect::SetRectEmpty() {
581 left = top = right = bottom = 0;
584 inline void CRect::CopyRect(
LPCRECT lpSrcRect) {
585 left = lpSrcRect->left;
586 top = lpSrcRect->top;
587 right = lpSrcRect->right;
588 bottom = lpSrcRect->bottom;
591 inline bool CRect::EqualRect(
LPCRECT lpRect)
const {
592 return left == lpRect->left &&
593 top == lpRect->top &&
594 right == lpRect->right &&
595 bottom == lpRect->bottom;
598 inline void CRect::InflateRect(
606 inline void CRect::InflateRect(
SIZE size) {
613 inline void CRect::DeflateRect(
618 inline void CRect::DeflateRect(
SIZE size) {
619 InflateRect(-size.cx, -size.cy);
622 inline void CRect::OffsetRect(
630 inline void CRect::OffsetRect(
POINT point) {
637 inline void CRect::OffsetRect(
SIZE size) {
638 OffsetRect(size.cx, size.cy);
641 inline void CRect::MoveToY(
int y) {
642 bottom = Height() + y;
646 inline void CRect::MoveToX(
int x) {
651 inline void CRect::MoveToXY(
658 inline void CRect::MoveToXY(
POINT pt) {
663 inline bool CRect::IntersectRect(
665 return (lpRect1->left < lpRect2->right) &&
666 (lpRect2->left < lpRect1->right) &&
667 (lpRect1->top < lpRect2->bottom) &&
668 (lpRect2->top < lpRect1->bottom);
672 if (!lpRect1 || !lpRect2) {
679 bool empty1 = lpRect1->left >= lpRect1->right || lpRect1->top >= lpRect1->bottom;
680 bool empty2 = lpRect2->left >= lpRect2->right || lpRect2->top >= lpRect2->bottom;
682 if (empty1 && empty2) {
694 left =
MIN(lpRect1->left, lpRect2->left);
695 top =
MIN(lpRect1->top, lpRect2->top);
696 right =
MAX(lpRect1->right, lpRect2->right);
697 bottom =
MAX(lpRect1->bottom, lpRect2->bottom);
702 inline void CRect::operator=(
const RECT &srcRect) {
706 inline bool CRect::operator==(
const RECT &rect)
const {
707 return EqualRect(&rect);
710 inline bool CRect::operator!=(
const RECT &rect)
const {
711 return !EqualRect(&rect);
714 inline void CRect::operator+=(
POINT point) {
715 OffsetRect(point.x, point.y);
718 inline void CRect::operator+=(
SIZE size) {
719 OffsetRect(size.cx, size.cy);
722 inline void CRect::operator+=(
LPCRECT lpRect) {
726 inline void CRect::operator-=(
POINT point) {
727 OffsetRect(-point.x, -point.y);
730 inline void CRect::operator-=(
SIZE size) {
731 OffsetRect(-size.cx, -size.cy);
734 inline void CRect::operator-=(
LPCRECT lpRect) {
738 inline void CRect::operator&=(
const RECT &rect) {
739 IntersectRect(
this, &rect);
742 inline void CRect::operator|=(
const RECT &rect) {
743 UnionRect(
this, &rect);
746 inline CRect CRect::operator+(
POINT pt)
const {
748 rect.OffsetRect(pt.x, pt.y);
752 inline CRect CRect::operator-(
POINT pt)
const {
754 rect.OffsetRect(-pt.x, -pt.y);
758 inline CRect CRect::operator+(
SIZE size)
const {
760 rect.OffsetRect(size.cx, size.cy);
764 inline CRect CRect::operator-(
SIZE size)
const {
766 rect.OffsetRect(-size.cx, -size.cy);
772 rect.InflateRect(lpRect);
778 rect.DeflateRect(lpRect);
782 inline CRect CRect::operator&(
const RECT &rect2)
const {
784 rect.IntersectRect(
this, &rect2);
788 inline CRect CRect::operator|(
const RECT &rect2)
const {
790 rect.UnionRect(
this, &rect2);
794 inline bool CRect::SubtractRect(
798 if (!intersect.IntersectRect(lpRectSrc1, lpRectSrc2)) {
805 if (intersect == *lpRectSrc1) {
813 if (intersect.top > lpRectSrc1->top &&
814 intersect.left <= lpRectSrc1->left &&
815 intersect.right >= lpRectSrc1->right) {
816 SetRect(lpRectSrc1->left, lpRectSrc1->top,
817 lpRectSrc1->right, intersect.top);
822 if (intersect.bottom < lpRectSrc1->bottom &&
823 intersect.left <= lpRectSrc1->left &&
824 intersect.right >= lpRectSrc1->right) {
825 SetRect(lpRectSrc1->left, intersect.bottom,
826 lpRectSrc1->right, lpRectSrc1->bottom);
831 if (intersect.left > lpRectSrc1->left &&
832 intersect.top <= lpRectSrc1->top &&
833 intersect.bottom >= lpRectSrc1->bottom) {
834 SetRect(lpRectSrc1->left, lpRectSrc1->top,
835 intersect.left, lpRectSrc1->bottom);
840 if (intersect.right < lpRectSrc1->right &&
841 intersect.top <= lpRectSrc1->top &&
842 intersect.bottom >= lpRectSrc1->bottom) {
843 SetRect(intersect.right, lpRectSrc1->top,
844 lpRectSrc1->right, lpRectSrc1->bottom);
854 inline void CRect::NormalizeRect() {
868 inline void CRect::InflateRect(
LPCRECT lpRect) {
869 left -= lpRect->left;
871 right += lpRect->right;
872 bottom += lpRect->bottom;
875 inline void CRect::InflateRect(
886 inline void CRect::DeflateRect(
LPCRECT lpRect) {
887 left += lpRect->left;
889 right -= lpRect->right;
890 bottom -= lpRect->bottom;
893 inline void CRect::DeflateRect(
904 inline int SafeMulDiv(
int a,
int b,
int c) {
909 int64 temp = (int64)a * (int64)b;
913 return (
int)((temp + (c / 2)) / c);
915 return (
int)((temp - (c / 2)) / c);
918 inline CRect CRect::MulDiv(
920 int nDivisor)
const {
922 SafeMulDiv(left, nMultiplier, nDivisor),
923 SafeMulDiv(top, nMultiplier, nDivisor),
924 SafeMulDiv(right, nMultiplier, nDivisor),
925 SafeMulDiv(bottom, nMultiplier, nDivisor));
Definition: minwindef.h:165
Definition: atltypes.h:79
Definition: minwindef.h:160
Definition: atltypes.h:40
Definition: minwindef.h:178
T MIN(T a, T b)
Definition: util.h:61
T MAX(T a, T b)
Definition: util.h:64
Definition: atltypes.h:131