37class CSize :
public SIZE
47 CSize(
int initCX,
int initCY)
55 *(SIZE*)
this = initSize;
60 *(POINT*)
this = initPt;
65 cx = (short)LOWORD(dwSize);
66 cy = (short)HIWORD(dwSize);
70 BOOL operator ==(SIZE size)
const
72 return (cx == size.cx && cy == size.cy);
75 BOOL operator !=(SIZE size)
const
77 return (cx != size.cx || cy != size.cy);
80 void operator +=(SIZE size)
86 void operator -=(SIZE size)
92 void SetSize(
int CX,
int CY)
99 CSize operator +(SIZE size)
const
101 return CSize(cx + size.cx, cy + size.cy);
104 CSize operator -(SIZE size)
const
106 return CSize(cx - size.cx, cy - size.cy);
109 CSize operator -()
const
111 return CSize(-cx, -cy);
115 CPoint operator +(POINT point)
const;
116 CPoint operator -(POINT point)
const;
119 CRect operator +(
const RECT* lpRect)
const;
120 CRect operator -(
const RECT* lpRect)
const;
127class CPoint :
public POINT
137 CPoint(
int initX,
int initY)
145 *(POINT*)
this = initPt;
148 CPoint(SIZE initSize)
150 *(SIZE*)
this = initSize;
153 CPoint(DWORD dwPoint)
155 x = (short)LOWORD(dwPoint);
156 y = (short)HIWORD(dwPoint);
160 void Offset(
int xOffset,
int yOffset)
166 void Offset(POINT point)
172 void Offset(SIZE size)
178 BOOL operator ==(POINT point)
const
180 return (x == point.x && y == point.y);
183 BOOL operator !=(POINT point)
const
185 return (x != point.x || y != point.y);
188 void operator +=(SIZE size)
194 void operator -=(SIZE size)
200 void operator +=(POINT point)
206 void operator -=(POINT point)
212 void SetPoint(
int X,
int Y)
219 CPoint operator +(SIZE size)
const
221 return CPoint(x + size.cx, y + size.cy);
224 CPoint operator -(SIZE size)
const
226 return CPoint(x - size.cx, y - size.cy);
229 CPoint operator -()
const
231 return CPoint(-x, -y);
234 CPoint operator +(POINT point)
const
236 return CPoint(x + point.x, y + point.y);
240 CSize operator -(POINT point)
const
242 return CSize(x - point.x, y - point.y);
246 CRect operator +(
const RECT* lpRect)
const;
247 CRect operator -(
const RECT* lpRect)
const;
254class CRect :
public RECT
266 CRect(
int l,
int t,
int r,
int b)
274 CRect(
const RECT& srcRect)
279 CRect(LPCRECT lpSrcRect)
284 CRect(POINT point, SIZE size)
286 right = (left = point.x) + size.cx;
287 bottom = (top = point.y) + size.cy;
290 CRect(POINT topLeft, POINT bottomRight)
294 right = bottomRight.x;
295 bottom = bottomRight.y;
311 return CSize(right - left, bottom - top);
316 return *((CPoint*)
this);
319 CPoint& BottomRight()
321 return *((CPoint*)
this + 1);
324 const CPoint& TopLeft()
const
326 return *((CPoint*)
this);
329 const CPoint& BottomRight()
const
331 return *((CPoint*)
this + 1);
334 CPoint CenterPoint()
const
336 return CPoint((left + right) / 2, (top + bottom) / 2);
345 operator LPCRECT()
const
351 BOOL IsRectEmpty()
const
353 return ::IsRectEmpty(
this);
356 BOOL IsRectNull()
const
358 return (left == 0 && right == 0 && top == 0 && bottom == 0);
361 BOOL PtInRect(POINT point)
const
363 return point.x>=left && point.x<right
364 && point.y>=top && point.y<bottom;
368 void SetRect(
int x1,
int y1,
int x2,
int y2)
371 top = y1, bottom = y2;
374 void SetRect(POINT topLeft, POINT bottomRight)
376 SetRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
385 void CopyRect(LPCRECT lpSrcRect)
387 left = lpSrcRect->left;
388 top = lpSrcRect->top;
389 right = lpSrcRect->right;
390 bottom = lpSrcRect->bottom;
393 BOOL EqualRect(LPCRECT lpRect)
const
395 return left == lpRect->left && right == lpRect->right
396 && top == lpRect->top && bottom == lpRect->bottom;
399 void InflateRect(
int x,
int y)
402 top -=y ,bottom += y;
405 void InflateRect(SIZE size)
407 InflateRect(size.cx, size.cy);
410 void InflateRect(LPCRECT lpRect)
412 left -= lpRect->left;
414 right += lpRect->right;
415 bottom += lpRect->bottom;
418 void InflateRect(
int l,
int t,
int r,
int b)
426 void DeflateRect(
int x,
int y)
431 void DeflateRect(SIZE size)
433 InflateRect(-size.cx, -size.cy);
436 void DeflateRect(LPCRECT lpRect)
438 left += lpRect->left;
440 right -= lpRect->right;
441 bottom -= lpRect->bottom;
444 void DeflateRect(
int l,
int t,
int r,
int b)
452 void OffsetRect(
int x,
int y)
459 void OffsetRect(SIZE size)
461 OffsetRect(size.cx, size.cy);
464 void OffsetRect(POINT point)
466 OffsetRect(point.x, point.y);
489 bottom = Height() + y;
499 void MoveToXY(
int x,
int y)
505 void MoveToXY(POINT pt)
513 BOOL IntersectRect(LPCRECT src1, LPCRECT src2)
515 if (!src1 || !src2)
return FALSE;
516 CRect rc1(src1),rc2(src2);
517 if (rc1.IsRectEmpty() || rc2.IsRectEmpty() ||
518 (src1->left >= src2->right) || (src2->left >= src1->right) ||
519 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
524 left = smax( src1->left, src2->left );
525 right = smin( src1->right, src2->right );
526 top = smax( src1->top, src2->top );
527 bottom = smin( src1->bottom, src2->bottom );
531 BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2)
533 CRect src1(lpRect1),src2(lpRect2);
534 if (src1.IsRectEmpty())
536 if (src2.IsRectEmpty())
545 if (src2.IsRectEmpty()) *
this = src1;
548 left = smin( src1.left, src2.left );
549 right = smax( src1.right, src2.right );
550 top = smin( src1.top, src2.top );
551 bottom = smax( src1.bottom, src2.bottom );
557 BOOL SubtractRect(
const RECT *src1,
const RECT *src2 )
560 if (::IsRectEmpty( src1 ))
565 if (tmp.IntersectRect(src1, src2 ))
567 if (tmp.EqualRect(src1 ))
573 if ((tmp.top == top) && (tmp.bottom == bottom))
575 if (tmp.left == left) left = tmp.right;
576 else if (tmp.right == right) right = tmp.left;
578 else if ((tmp.left == left) && (tmp.right == right))
580 if (tmp.top == top) top = tmp.bottom;
581 else if (tmp.bottom == bottom) bottom = tmp.top;
592 void operator =(
const RECT& srcRect)
597 BOOL operator ==(
const RECT& rect)
const
599 return EqualRect(&rect);
602 BOOL operator !=(
const RECT& rect)
const
604 return EqualRect(&rect)==0;
607 void operator +=(POINT point)
609 OffsetRect(point.x, point.y);
612 void operator +=(SIZE size)
614 OffsetRect(size.cx, size.cy);
617 void operator +=(LPCRECT lpRect)
622 void operator -=(POINT point)
624 OffsetRect(-point.x, -point.y);
627 void operator -=(SIZE size)
629 OffsetRect(-size.cx, -size.cy);
632 void operator -=(LPCRECT lpRect)
637 void operator &=(
const RECT& rect)
639 IntersectRect(
this, &rect);
642 void operator |=(
const RECT& rect)
644 UnionRect(
this, &rect);
648 CRect operator +(POINT pt)
const
651 rect.OffsetRect(pt.x, pt.y);
655 CRect operator -(POINT pt)
const
658 rect.OffsetRect(-pt.x, -pt.y);
662 CRect operator +(LPCRECT lpRect)
const
665 rect.InflateRect(lpRect);
669 CRect operator +(SIZE size)
const
672 rect.OffsetRect(size.cx, size.cy);
676 CRect operator -(SIZE size)
const
679 rect.OffsetRect(-size.cx, -size.cy);
683 CRect operator -(LPCRECT lpRect)
const
686 rect.DeflateRect(lpRect);
690 CRect operator &(
const RECT& rect2)
const
693 rect.IntersectRect(
this, &rect2);
697 CRect operator |(
const RECT& rect2)
const
700 rect.UnionRect(
this, &rect2);
704 CRect MulDiv(
int nMultiplier,
int nDivisor)
const
707 ::MulDiv(left, nMultiplier, nDivisor),
708 ::MulDiv(top, nMultiplier, nDivisor),
709 ::MulDiv(right, nMultiplier, nDivisor),
710 ::MulDiv(bottom, nMultiplier, nDivisor));
717inline CPoint CSize::operator +(POINT point)
const
719 return CPoint(cx + point.x, cy + point.y);
722inline CPoint CSize::operator -(POINT point)
const
724 return CPoint(cx - point.x, cy - point.y);
727inline CRect CSize::operator +(
const RECT* lpRect)
const
729 return CRect(lpRect) + *
this;
732inline CRect CSize::operator -(
const RECT* lpRect)
const
734 return CRect(lpRect) - *
this;
740inline CRect CPoint::operator +(
const RECT* lpRect)
const
742 return CRect(lpRect) + *
this;
745inline CRect CPoint::operator -(
const RECT* lpRect)
const
747 return CRect(lpRect) - *
this;
752inline CSize operator *(SIZE s, Num n)
754 return CSize((
int)(s.cx * n), (
int)(s.cy * n));
758inline void operator *=(SIZE & s, Num n)
764inline CSize operator /(SIZE s, Num n)
766 return CSize((
int)(s.cx / n), (
int)(s.cy / n));
770inline void operator /=(SIZE & s, Num n)