class PixSize; class PixPoint; class PixRect; struct xPix {LONG n; xPix():n(0){} explicit xPix(LONG x):n(x){} }; struct yPix {LONG n; yPix():n(0){} explicit yPix(LONG x):n(x){} }; class PixSize : public SIZE { public: operator xPix(){return xPix(cx);} operator yPix(){return yPix(cy);} // Constructors PixSize& operator+=(const PixSize& x){cx+=x.cx; cy+=x.cy; return *this; } PixSize() { cx = 0; cy = 0; } PixSize(int initCX, int initCY) { cx = initCX; cy = initCY; } PixSize(SIZE initSize) { *(SIZE*)this = initSize; } PixSize(POINT initPt) { *(POINT*)this = initPt; } PixSize(DWORD dwSize) { cx = (short)LOWORD(dwSize); cy = (short)HIWORD(dwSize); } // Operations PixSize& operator=(const RECT& r) {cx =r.right-r.left;return *this;} PixSize& operator=(LONG sz) {cx =sz;cy=sz ;return *this;} BOOL operator ==(SIZE size) const { return (cx == size.cx && cy == size.cy); } BOOL operator !=(SIZE size) const { return (cx != size.cx || cy != size.cy); } void operator +=(SIZE size) { cx += size.cx; cy += size.cy; } void operator -=(SIZE size) { cx -= size.cx; cy -= size.cy; } void SetSize(int CX, int CY) { cx = CX; cy = CY; } // Operators returning PixSize values PixSize operator +(SIZE size) const { return PixSize(cx + size.cx, cy + size.cy); } PixSize operator -(SIZE size) const { return PixSize(cx - size.cx, cy - size.cy); } PixSize operator -() const { return PixSize(-cx, -cy); } // Operators returning PixPoint values PixPoint operator +(POINT point) const; PixPoint operator -(POINT point) const; // Operators returning PixRect values PixRect operator +(const RECT* lpRect) const; PixRect operator -(const RECT* lpRect) const; }; /////////////////////////////////////////////////////////////////////////////// // PixPoint - Wrapper for Windows POINT structure. class PixPoint : public POINT { public: // Constructors PixPoint(const PixSize& a){x =a.cx;y=a.cy;} PixPoint() { x = 0; y = 0; } PixPoint(int initX, int initY) { x = initX; y = initY; } PixPoint(POINT initPt) { *(POINT*)this = initPt; } PixPoint(SIZE initSize) { *(SIZE*)this = initSize; } PixPoint(DWORD dwPoint) { x = (short)LOWORD(dwPoint); y = (short)HIWORD(dwPoint); } // Operations PixPoint& operator=(const RECT& b) {x =b.left;y=b.top;return *this;} void Offset(int xOffset, int yOffset) { x += xOffset; y += yOffset; } void Offset(POINT point) { x += point.x; y += point.y; } void Offset(SIZE size) { x += size.cx; y += size.cy; } BOOL operator ==(POINT point) const { return (x == point.x && y == point.y); } BOOL operator !=(POINT point) const { return (x != point.x || y != point.y); } void operator +=(SIZE size) { x += size.cx; y += size.cy; } void operator -=(SIZE size) { x -= size.cx; y -= size.cy; } void operator +=(POINT point) { x += point.x; y += point.y; } void operator -=(POINT point) { x -= point.x; y -= point.y; } void SetPoint(int X, int Y) { x = X; y = Y; } // Operators returning PixPoint values PixPoint operator +(SIZE size) const { return PixPoint(x + size.cx, y + size.cy); } PixPoint operator -(SIZE size) const { return PixPoint(x - size.cx, y - size.cy); } PixPoint operator -() const { return PixPoint(-x, -y); } PixPoint operator +(POINT point) const { return PixPoint(x + point.x, y + point.y); } // Operators returning PixSize values PixSize operator -(POINT point) const { return PixSize(x - point.x, y - point.y); } // Operators returning PixRect values PixRect operator +(const RECT* lpRect) const; PixRect operator -(const RECT* lpRect) const; }; /////////////////////////////////////////////////////////////////////////////// // PixRect - Wrapper for Windows RECT structure. class PixRect : public RECT { public: PixRect& adjust()const{const_cast(this)->right =max(left,right); const_cast(this)->bottom=max(top ,bottom); return *const_cast(this); } // Constructors PixSize size(){adjust(); if(right < left) right=left; if(bottom < top) bottom=top; PixSize s; s.cx=right-left; s.cy=bottom-top; return s; } PixRect(const PixSize& s){*this =s;} PixRect(const PixPoint& x){*this =x;} PixRect& sizeMax(const PixRect& plt ,const PixRect& prb) {adjust(); const_cast(plt).adjust(); const_cast(prb).adjust(); PixSize nsz=PixRect(plt.left,plt.top,prb.right,prb.bottom).size(); PixSize sz =size(); PixSize mx(max(nsz.cx,sz.cx) ,max(nsz.cy,sz.cy) ); *this =mx; return *this; } PixRect() { left = 0; top = 0; right = 0; bottom = 0; } PixRect(int l, int t, int r, int b) { left = l; top = t; right = r; bottom = b; } PixRect(const RECT& srERect) { ::CopyRect(this, &srERect); } PixRect(LPCRECT lpSrERect) { ::CopyRect(this, lpSrERect); } PixRect(POINT point, SIZE size) { right = (left = point.x) + size.cx; bottom = (top = point.y) + size.cy; } PixRect(POINT topLeft, POINT bottomRight) { left = topLeft.x; top = topLeft.y; right = bottomRight.x; bottom = bottomRight.y; } // Attributes (in addition to RECT members) int Width() const { adjust(); return right - left; } int Height() const { adjust(); return bottom - top; } PixSize Size() const { adjust(); return PixSize(right - left, bottom - top); } PixPoint& TopLeft() { return *((PixPoint*)this); } PixPoint& point() { return *((PixPoint*)this); } PixPoint& BottomRight() { adjust(); return *((PixPoint*)this + 1); } const PixPoint& TopLeft() const { return *((PixPoint*)this); } const PixPoint& BottomRight() const { adjust(); return *((PixPoint*)this + 1); } PixPoint CenterPoint() const { adjust(); return PixPoint((left + right) / 2, (top + bottom) / 2); } // convert between PixRect and LPRECT/LPCRECT (no need for &) operator LPRECT() { adjust(); return this; } operator LPCRECT() const { adjust(); return this; } BOOL IsRectEmpty() const { adjust(); return ::IsRectEmpty(this); } BOOL IsRectNull() const { return (left == 0 && right == 0 && top == 0 && bottom == 0); } BOOL PtInRect(POINT point) const { adjust(); return ::PtInRect(this, point); } // Operations void SetRect(int x1, int y1, int x2, int y2) { ::SetRect(this, x1, y1, x2, y2); } void SetRect(POINT topLeft, POINT bottomRight) { ::SetRect(this, topLeft.x, topLeft.y, bottomRight.x, bottomRight.y); } void SetRectEmpty() { ::SetRectEmpty(this); } void CopyRect(LPCRECT lpSrERect) { adjust(); ::CopyRect(this, lpSrERect); } BOOL EqualRect(LPCRECT lpRect) const { adjust(); return ::EqualRect(this, lpRect); } void InflateRect(int x, int y) { adjust(); ::InflateRect(this, x, y); } void InflateRect(SIZE size) { adjust(); ::InflateRect(this, size.cx, size.cy); } void InflateRect(LPCRECT lpRect) { adjust(); left -= lpRect->left; top -= lpRect->top; right += lpRect->right; bottom += lpRect->bottom; } void InflateRect(int l, int t, int r, int b) { adjust(); left -= l; top -= t; right += r; bottom += b; } void DeflateRect(int x, int y) { adjust(); ::InflateRect(this, -x, -y); } void DeflateRect(SIZE size) { adjust(); ::InflateRect(this, -size.cx, -size.cy); } void DeflateRect(LPCRECT lpRect) { adjust(); left += lpRect->left; top += lpRect->top; right -= lpRect->right; bottom -= lpRect->bottom; } void DeflateRect(int l, int t, int r, int b) { adjust(); left += l; top += t; right -= r; bottom -= b; } void OffsetRect(int x, int y) { adjust(); ::OffsetRect(this, x, y); } void OffsetRect(SIZE size) { adjust(); ::OffsetRect(this, size.cx, size.cy); } void OffsetRect(POINT point) { adjust(); ::OffsetRect(this, point.x, point.y); } void NormalizeRect() { adjust(); int nTemp; if (left > right) { nTemp = left; left = right; right = nTemp; } if (top > bottom) { nTemp = top; top = bottom; bottom = nTemp; } } // absolute position of rectangle void MoveToY(int y) { adjust(); bottom = Height() + y; top = y; } void MoveToX(int x) { adjust(); right = Width() + x; left = x; } void MoveToXY(int x, int y) { adjust(); MoveToX(x); MoveToY(y); } void MoveToXY(POINT pt) { adjust(); MoveToX(pt.x); MoveToY(pt.y); } // operations that fill '*this' with result BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2) { adjust(); return ::IntersectRect(this, lpRect1, lpRect2); } BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2) { adjust(); return ::UnionRect(this, lpRect1, lpRect2); } BOOL SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2) { adjust(); return ::SubtractRect(this, lpRectSrc1, lpRectSrc2); } // Additional Operations PixRect& operator=(const POINT& p){left =p.x;top=p.y;return *this;} PixRect& operator=(const SIZE& s){right =left+s.cx; bottom=top+s.cy;return *this;} void operator =(const RECT& srERect) { ::CopyRect(this, &srERect); } BOOL operator ==(const RECT& rect) const { adjust(); return ::EqualRect(this, &rect); } BOOL operator !=(const RECT& rect) const { adjust(); return !::EqualRect(this, &rect); } void operator +=(POINT point) { adjust(); ::OffsetRect(this, point.x, point.y); } void operator +=(SIZE size) { adjust(); ::OffsetRect(this, size.cx, size.cy); } void operator +=(LPCRECT lpRect) { adjust(); InflateRect(lpRect); } void operator -=(POINT point) { adjust(); ::OffsetRect(this, -point.x, -point.y); } void operator -=(SIZE size) { adjust(); ::OffsetRect(this, -size.cx, -size.cy); } void operator -=(LPCRECT lpRect) { adjust(); DeflateRect(lpRect); } void operator &=(const RECT& rect) { adjust(); ::IntersectRect(this, this, &rect); } void operator |=(const RECT& rect) { adjust(); ::UnionRect(this, this, &rect); } // Operators returning PixRect values PixRect operator +(POINT pt) const { adjust(); PixRect rect(*this); ::OffsetRect(&rect, pt.x, pt.y); return rect; } PixRect operator -(POINT pt) const { adjust(); PixRect rect(*this); ::OffsetRect(&rect, -pt.x, -pt.y); return rect; } PixRect operator +(LPCRECT lpRect) const { adjust(); PixRect rect(this); rect.InflateRect(lpRect); return rect; } PixRect operator +(SIZE size) const { adjust(); PixRect rect(*this); ::OffsetRect(&rect, size.cx, size.cy); return rect; } PixRect operator -(SIZE size) const { adjust(); PixRect rect(*this); ::OffsetRect(&rect, -size.cx, -size.cy); return rect; } PixRect operator -(LPCRECT lpRect) const { adjust(); PixRect rect(this); rect.DeflateRect(lpRect); return rect; } PixRect operator &(const RECT& rect2) const { adjust(); PixRect rect; ::IntersectRect(&rect, this, &rect2); return rect; } PixRect operator |(const RECT& rect2) const { adjust(); PixRect rect; ::UnionRect(&rect, this, &rect2); return rect; } PixRect MulDiv(int nMultiplier, int nDivisor) const { adjust(); return PixRect( ::MulDiv(left, nMultiplier, nDivisor), ::MulDiv(top, nMultiplier, nDivisor), ::MulDiv(right, nMultiplier, nDivisor), ::MulDiv(bottom, nMultiplier, nDivisor)); } }; // PixSize implementation inline PixPoint PixSize::operator +(POINT point) const { return PixPoint(cx + point.x, cy + point.y); } inline PixPoint PixSize::operator -(POINT point) const { return PixPoint(cx - point.x, cy - point.y); } inline PixRect PixSize::operator +(const RECT* lpRect) const { return PixRect(lpRect) + *this; } inline PixRect PixSize::operator -(const RECT* lpRect) const { return PixRect(lpRect) - *this; } // PixPoint implementation inline PixRect PixPoint::operator +(const RECT* lpRect) const { return PixRect(lpRect) + *this; } inline PixRect PixPoint::operator -(const RECT* lpRect) const { return PixRect(lpRect) - *this; } #if !defined(_WTL_NO_SIZE_SCALAR) && (!defined(_WTL_NO_WTYPES) || defined(__ATLTYPES_H__)) #ifndef __ATLMISC_H__ template inline PixSize operator *(SIZE s, Num n) { return PixSize((int)(s.cx * n), (int)(s.cy * n)); }; template inline void operator *=(SIZE & s, Num n) { s = s * n; }; template inline PixSize operator /(SIZE s, Num n) { return PixSize((int)(s.cx / n), (int)(s.cy / n)); }; template inline void operator /=(SIZE & s, Num n) { s = s / n; }; #endif #endif PixSize size(const PixRect& plt ,const PixRect& prb) {return PixSize()=PixRect(plt.left,plt.top,prb.right,prb.bottom);}