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);
290 const CPoint &TopLeft()
const {
291 return *((
const CPoint *)
this);
293 const CPoint &BottomRight()
const {
294 return *((
const CPoint *)&right);
299 inline CSize::CSize() {
311 inline CSize::CSize(
SIZE initSize) {
312 *(
SIZE *)
this = initSize;
315 inline CSize::CSize(
POINT initPt) {
316 *(
POINT *)
this = initPt;
319 inline CSize::CSize(uint32 dwSize) {
320 cx = (short)LOWORD(dwSize);
321 cy = (short)HIWORD(dwSize);
324 inline bool CSize::operator==(
SIZE size)
const {
325 return (cx == size.cx && cy == size.cy);
328 inline bool CSize::operator!=(
SIZE size)
const {
329 return (cx != size.cx || cy != size.cy);
332 inline void CSize::operator+=(
SIZE size) {
337 inline void CSize::operator-=(
SIZE size) {
342 inline void CSize::SetSize(
349 inline CSize CSize::operator+(
SIZE size)
const {
350 return CSize(cx + size.cx, cy + size.cy);
353 inline CSize CSize::operator-(
SIZE size)
const {
354 return CSize(cx - size.cx, cy - size.cy);
357 inline CSize CSize::operator-()
const {
358 return CSize(-cx, -cy);
361 inline CPoint CSize::operator+(
POINT point)
const {
362 return CPoint(cx + point.x, cy + point.y);
365 inline CPoint CSize::operator-(
POINT point)
const {
366 return CPoint(cx - point.x, cy - point.y);
369 inline CRect CSize::operator+(
const RECT *lpRect)
const {
370 return CRect(lpRect) + *
this;
373 inline CRect CSize::operator-(
const RECT *lpRect)
const {
374 return CRect(lpRect) - *
this;
378 inline CPoint::CPoint() {
383 inline CPoint::CPoint(
390 inline CPoint::CPoint(
POINT initPt) {
391 *(
POINT *)
this = initPt;
394 inline CPoint::CPoint(
SIZE initSize) {
395 *(
SIZE *)
this = initSize;
398 inline CPoint::CPoint(LPARAM dwPoint) {
399 x = (short)LOWORD(dwPoint);
400 y = (short)HIWORD(dwPoint);
403 inline void CPoint::Offset(
410 inline void CPoint::Offset(
POINT point) {
415 inline void CPoint::Offset(
SIZE size) {
420 inline void CPoint::SetPoint(
427 inline bool CPoint::operator==(
POINT point)
const {
428 return (x == point.x && y == point.y);
431 inline bool CPoint::operator!=(
POINT point)
const {
432 return (x != point.x || y != point.y);
435 inline void CPoint::operator+=(
SIZE size) {
440 inline void CPoint::operator-=(
SIZE size) {
445 inline void CPoint::operator+=(
POINT point) {
450 inline void CPoint::operator-=(
POINT point) {
455 inline CPoint CPoint::operator+(
SIZE size)
const {
456 return CPoint(x + size.cx, y + size.cy);
459 inline CPoint CPoint::operator-(
SIZE size)
const {
460 return CPoint(x - size.cx, y - size.cy);
463 inline CPoint CPoint::operator-()
const {
467 inline CPoint CPoint::operator+(
POINT point)
const {
468 return CPoint(x + point.x, y + point.y);
471 inline CSize CPoint::operator-(
POINT point)
const {
472 return CSize(x - point.x, y - point.y);
475 inline CRect CPoint::operator+(
const RECT *lpRect)
const {
476 return CRect(lpRect) + *
this;
479 inline CRect CPoint::operator-(
const RECT *lpRect)
const {
480 return CRect(lpRect) - *
this;
484 inline CRect::CRect() {
502 inline CRect::CRect(
const RECT &srcRect) {
506 inline CRect::CRect(
LPCRECT lpSrcRect) {
510 inline CRect::CRect(
const POINT &point,
const SIZE &size) {
511 right = (left = point.x) + size.cx;
512 bottom = (top = point.y) + size.cy;
515 inline CRect::CRect(
const POINT &topLeft,
const POINT &bottomRight) {
518 right = bottomRight.x;
519 bottom = bottomRight.y;
522 inline int CRect::Width()
const {
526 inline int CRect::Height()
const {
530 inline CSize CRect::Size()
const {
531 return CSize(right - left, bottom - top);
534 inline CPoint CRect::CenterPoint()
const {
535 return CPoint((left + right) / 2, (top + bottom) / 2);
538 inline void CRect::SwapLeftRight() {
539 SwapLeftRight(
LPRECT(
this));
542 inline void WINAPI CRect::SwapLeftRight(
LPRECT lpRect) {
543 long temp = lpRect->left;
544 lpRect->left = lpRect->right;
545 lpRect->right = temp;
548 inline CRect::operator
LPRECT() {
552 inline CRect::operator
LPCRECT()
const {
556 inline bool CRect::IsRectEmpty()
const {
557 return (left >= right) && (top >= bottom);
560 inline bool CRect::IsRectNull()
const {
561 return (left == 0 && right == 0 && top == 0 && bottom == 0);
564 inline bool CRect::PtInRect(
POINT point)
const {
565 return (point.x >= left) && (point.x < right) &&
566 (point.y >= top) && (point.y < bottom);
569 inline void CRect::SetRect(
int x1,
int y1,
577 inline void CRect::SetRect(
582 right = bottomRight.x;
583 bottom = bottomRight.y;
586 inline void CRect::SetRectEmpty() {
587 left = top = right = bottom = 0;
590 inline void CRect::CopyRect(
LPCRECT lpSrcRect) {
591 left = lpSrcRect->left;
592 top = lpSrcRect->top;
593 right = lpSrcRect->right;
594 bottom = lpSrcRect->bottom;
597 inline bool CRect::EqualRect(
LPCRECT lpRect)
const {
598 return left == lpRect->left &&
599 top == lpRect->top &&
600 right == lpRect->right &&
601 bottom == lpRect->bottom;
604 inline void CRect::InflateRect(
612 inline void CRect::InflateRect(
SIZE size) {
619 inline void CRect::DeflateRect(
624 inline void CRect::DeflateRect(
SIZE size) {
625 InflateRect(-size.cx, -size.cy);
628 inline void CRect::OffsetRect(
636 inline void CRect::OffsetRect(
POINT point) {
643 inline void CRect::OffsetRect(
SIZE size) {
644 OffsetRect(size.cx, size.cy);
647 inline void CRect::MoveToY(
int y) {
648 bottom = Height() + y;
652 inline void CRect::MoveToX(
int x) {
657 inline void CRect::MoveToXY(
664 inline void CRect::MoveToXY(
POINT pt) {
669 inline bool CRect::IntersectRect(
672 SetRect(r.
left, r.top, r.
right, r.bottom);
678 if (!lpRect1 || !lpRect2) {
685 bool empty1 = lpRect1->left >= lpRect1->right || lpRect1->top >= lpRect1->bottom;
686 bool empty2 = lpRect2->left >= lpRect2->right || lpRect2->top >= lpRect2->bottom;
688 if (empty1 && empty2) {
700 left =
MIN(lpRect1->left, lpRect2->left);
701 top =
MIN(lpRect1->top, lpRect2->top);
702 right =
MAX(lpRect1->right, lpRect2->right);
703 bottom =
MAX(lpRect1->bottom, lpRect2->bottom);
708 inline void CRect::operator=(
const RECT &srcRect) {
712 inline bool CRect::operator==(
const RECT &rect)
const {
713 return EqualRect(&rect);
716 inline bool CRect::operator!=(
const RECT &rect)
const {
717 return !EqualRect(&rect);
720 inline void CRect::operator+=(
POINT point) {
721 OffsetRect(point.x, point.y);
724 inline void CRect::operator+=(
SIZE size) {
725 OffsetRect(size.cx, size.cy);
728 inline void CRect::operator+=(
LPCRECT lpRect) {
732 inline void CRect::operator-=(
POINT point) {
733 OffsetRect(-point.x, -point.y);
736 inline void CRect::operator-=(
SIZE size) {
737 OffsetRect(-size.cx, -size.cy);
740 inline void CRect::operator-=(
LPCRECT lpRect) {
744 inline void CRect::operator&=(
const RECT &rect) {
745 IntersectRect(
this, &rect);
748 inline void CRect::operator|=(
const RECT &rect) {
749 UnionRect(
this, &rect);
752 inline CRect CRect::operator+(
POINT pt)
const {
754 rect.OffsetRect(pt.x, pt.y);
758 inline CRect CRect::operator-(
POINT pt)
const {
760 rect.OffsetRect(-pt.x, -pt.y);
764 inline CRect CRect::operator+(
SIZE size)
const {
766 rect.OffsetRect(size.cx, size.cy);
770 inline CRect CRect::operator-(
SIZE size)
const {
772 rect.OffsetRect(-size.cx, -size.cy);
778 rect.InflateRect(lpRect);
784 rect.DeflateRect(lpRect);
788 inline CRect CRect::operator&(
const RECT &rect2)
const {
790 rect.IntersectRect(
this, &rect2);
794 inline CRect CRect::operator|(
const RECT &rect2)
const {
796 rect.UnionRect(
this, &rect2);
800 inline bool CRect::SubtractRect(
804 if (!intersect.IntersectRect(lpRectSrc1, lpRectSrc2)) {
811 if (intersect == *lpRectSrc1) {
819 if (intersect.top > lpRectSrc1->top &&
820 intersect.left <= lpRectSrc1->left &&
821 intersect.right >= lpRectSrc1->right) {
822 SetRect(lpRectSrc1->left, lpRectSrc1->top,
823 lpRectSrc1->right, intersect.top);
828 if (intersect.bottom < lpRectSrc1->bottom &&
829 intersect.left <= lpRectSrc1->left &&
830 intersect.right >= lpRectSrc1->right) {
831 SetRect(lpRectSrc1->left, intersect.bottom,
832 lpRectSrc1->right, lpRectSrc1->bottom);
837 if (intersect.left > lpRectSrc1->left &&
838 intersect.top <= lpRectSrc1->top &&
839 intersect.bottom >= lpRectSrc1->bottom) {
840 SetRect(lpRectSrc1->left, lpRectSrc1->top,
841 intersect.left, lpRectSrc1->bottom);
846 if (intersect.right < lpRectSrc1->right &&
847 intersect.top <= lpRectSrc1->top &&
848 intersect.bottom >= lpRectSrc1->bottom) {
849 SetRect(intersect.right, lpRectSrc1->top,
850 lpRectSrc1->right, lpRectSrc1->bottom);
860 inline void CRect::NormalizeRect() {
874 inline void CRect::InflateRect(
LPCRECT lpRect) {
875 left -= lpRect->left;
877 right += lpRect->right;
878 bottom += lpRect->bottom;
881 inline void CRect::InflateRect(
892 inline void CRect::DeflateRect(
LPCRECT lpRect) {
893 left += lpRect->left;
895 right -= lpRect->right;
896 bottom -= lpRect->bottom;
899 inline void CRect::DeflateRect(
910 inline int SafeMulDiv(
int a,
int b,
int c) {
915 int64 temp = (int64)a * (int64)b;
919 return (
int)((temp + (c / 2)) / c);
921 return (
int)((temp - (c / 2)) / c);
924 inline CRect CRect::MulDiv(
926 int nDivisor)
const {
928 SafeMulDiv(left, nMultiplier, nDivisor),
929 SafeMulDiv(top, nMultiplier, nDivisor),
930 SafeMulDiv(right, nMultiplier, nDivisor),
931 SafeMulDiv(bottom, nMultiplier, nDivisor));
Definition: minwindef.h:166
T left
Definition: rect.h:170
ConcreteRect findIntersectingRect(const ConcreteRect &r) const
Definition: rect.h:302
Definition: atltypes.h:79
Definition: minwindef.h:161
T right
Definition: rect.h:171
Definition: atltypes.h:40
bool isEmpty() const
Definition: rect.h:373
Definition: minwindef.h:179
T MIN(T a, T b)
Definition: util.h:61
T MAX(T a, T b)
Definition: util.h:64
Definition: atltypes.h:131