diff --git a/LEGO1/mfc.h b/LEGO1/mfc.h new file mode 100644 index 00000000..eed8f66e --- /dev/null +++ b/LEGO1/mfc.h @@ -0,0 +1,380 @@ +#ifndef MFC_H +#define MFC_H + +#include + +// clang-format off + +///////////////////////////////////////////////////////////////////////////// +// Classes declared in this file + +class CSize; +class CPoint; +class CRect; + +///////////////////////////////////////////////////////////////////////////// +// CSize - An extent, similar to Windows SIZE structure. + +class CSize : public tagSIZE +{ +public: + +// Constructors + CSize(); + CSize(int initCX, int initCY); + CSize(SIZE initSize); + CSize(POINT initPt); + CSize(DWORD dwSize); + +// Operations + BOOL operator==(SIZE size) const; + BOOL operator!=(SIZE size) const; + void operator+=(SIZE size); + void operator-=(SIZE size); + +// Operators returning CSize values + CSize operator+(SIZE size) const; + CSize operator-(SIZE size) const; + CSize operator-() const; + +// Operators returning CPoint values + CPoint operator+(POINT point) const; + CPoint operator-(POINT point) const; + +// Operators returning CRect values + CRect operator+(const RECT* lpRect) const; + CRect operator-(const RECT* lpRect) const; +}; + +///////////////////////////////////////////////////////////////////////////// +// CPoint - A 2-D point, similar to Windows POINT structure. + +class CPoint : public tagPOINT +{ +public: + +// Constructors + CPoint(); + CPoint(int initX, int initY); + CPoint(POINT initPt); + CPoint(SIZE initSize); + CPoint(DWORD dwPoint); + +// Operations + void Offset(int xOffset, int yOffset); + void Offset(POINT point); + void Offset(SIZE size); + BOOL operator==(POINT point) const; + BOOL operator!=(POINT point) const; + void operator+=(SIZE size); + void operator-=(SIZE size); + void operator+=(POINT point); + void operator-=(POINT point); + +// Operators returning CPoint values + CPoint operator+(SIZE size) const; + CPoint operator-(SIZE size) const; + CPoint operator-() const; + CPoint operator+(POINT point) const; + +// Operators returning CSize values + CSize operator-(POINT point) const; + +// Operators returning CRect values + CRect operator+(const RECT* lpRect) const; + CRect operator-(const RECT* lpRect) const; +}; + +///////////////////////////////////////////////////////////////////////////// +// CRect - A 2-D rectangle, similar to Windows RECT structure. + +typedef const RECT* LPCRECT; // pointer to read/only RECT + +class CRect : public tagRECT +{ +public: + +// Constructors + CRect(); + CRect(int l, int t, int r, int b); + CRect(const RECT& srcRect); + CRect(LPCRECT lpSrcRect); + CRect(POINT point, SIZE size); + CRect(POINT topLeft, POINT bottomRight); + +// Attributes (in addition to RECT members) + int Width() const; + int Height() const; + CSize Size() const; + CPoint& TopLeft(); + CPoint& BottomRight(); + const CPoint& TopLeft() const; + const CPoint& BottomRight() const; + CPoint CenterPoint() const; + + // convert between CRect and LPRECT/LPCRECT (no need for &) + operator LPRECT(); + operator LPCRECT() const; + + BOOL IsRectEmpty() const; + BOOL IsRectNull() const; + BOOL PtInRect(POINT point) const; + +// Operations + void SetRect(int x1, int y1, int x2, int y2); + void SetRect(POINT topLeft, POINT bottomRight); + void SetRectEmpty(); + void CopyRect(LPCRECT lpSrcRect); + BOOL EqualRect(LPCRECT lpRect) const; + + void InflateRect(int x, int y); + void InflateRect(SIZE size); + void InflateRect(LPCRECT lpRect); + void InflateRect(int l, int t, int r, int b); + void DeflateRect(int x, int y); + void DeflateRect(SIZE size); + void DeflateRect(LPCRECT lpRect); + void DeflateRect(int l, int t, int r, int b); + + void OffsetRect(int x, int y); + void OffsetRect(SIZE size); + void OffsetRect(POINT point); + void NormalizeRect(); + + // operations that fill '*this' with result + BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2); + BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2); + BOOL SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2); + +// Additional Operations + void operator=(const RECT& srcRect); + BOOL operator==(const RECT& rect) const; + BOOL operator!=(const RECT& rect) const; + void operator+=(POINT point); + void operator+=(SIZE size); + void operator+=(LPCRECT lpRect); + void operator-=(POINT point); + void operator-=(SIZE size); + void operator-=(LPCRECT lpRect); + void operator&=(const RECT& rect); + void operator|=(const RECT& rect); + +// Operators returning CRect values + CRect operator+(POINT point) const; + CRect operator-(POINT point) const; + CRect operator+(LPCRECT lpRect) const; + CRect operator+(SIZE size) const; + CRect operator-(SIZE size) const; + CRect operator-(LPCRECT lpRect) const; + CRect operator&(const RECT& rect2) const; + CRect operator|(const RECT& rect2) const; + CRect MulDiv(int nMultiplier, int nDivisor) const; +}; + +// Always use the inline functions +#if TRUE +#define _AFX_ENABLE_INLINES +#endif + +#ifdef _AFX_ENABLE_INLINES +#define _AFXWIN_INLINE inline + +// CSize +_AFXWIN_INLINE CSize::CSize() + { /* random filled */ } +_AFXWIN_INLINE CSize::CSize(int initCX, int initCY) + { cx = initCX; cy = initCY; } +_AFXWIN_INLINE CSize::CSize(SIZE initSize) + { *(SIZE*)this = initSize; } +_AFXWIN_INLINE CSize::CSize(POINT initPt) + { *(POINT*)this = initPt; } +_AFXWIN_INLINE CSize::CSize(DWORD dwSize) + { + cx = (short)LOWORD(dwSize); + cy = (short)HIWORD(dwSize); + } +_AFXWIN_INLINE BOOL CSize::operator==(SIZE size) const + { return (cx == size.cx && cy == size.cy); } +_AFXWIN_INLINE BOOL CSize::operator!=(SIZE size) const + { return (cx != size.cx || cy != size.cy); } +_AFXWIN_INLINE void CSize::operator+=(SIZE size) + { cx += size.cx; cy += size.cy; } +_AFXWIN_INLINE void CSize::operator-=(SIZE size) + { cx -= size.cx; cy -= size.cy; } +_AFXWIN_INLINE CSize CSize::operator+(SIZE size) const + { return CSize(cx + size.cx, cy + size.cy); } +_AFXWIN_INLINE CSize CSize::operator-(SIZE size) const + { return CSize(cx - size.cx, cy - size.cy); } +_AFXWIN_INLINE CSize CSize::operator-() const + { return CSize(-cx, -cy); } +_AFXWIN_INLINE CPoint CSize::operator+(POINT point) const + { return CPoint(cx + point.x, cy + point.y); } +_AFXWIN_INLINE CPoint CSize::operator-(POINT point) const + { return CPoint(cx - point.x, cy - point.y); } +_AFXWIN_INLINE CRect CSize::operator+(const RECT* lpRect) const + { return CRect(lpRect) + *this; } +_AFXWIN_INLINE CRect CSize::operator-(const RECT* lpRect) const + { return CRect(lpRect) - *this; } + +// CPoint +_AFXWIN_INLINE CPoint::CPoint() + { /* random filled */ } +_AFXWIN_INLINE CPoint::CPoint(int initX, int initY) + { x = initX; y = initY; } +_AFXWIN_INLINE CPoint::CPoint(POINT initPt) + { *(POINT*)this = initPt; } +_AFXWIN_INLINE CPoint::CPoint(SIZE initSize) + { *(SIZE*)this = initSize; } +_AFXWIN_INLINE CPoint::CPoint(DWORD dwPoint) + { + x = (short)LOWORD(dwPoint); + y = (short)HIWORD(dwPoint); + } +_AFXWIN_INLINE void CPoint::Offset(int xOffset, int yOffset) + { x += xOffset; y += yOffset; } +_AFXWIN_INLINE void CPoint::Offset(POINT point) + { x += point.x; y += point.y; } +_AFXWIN_INLINE void CPoint::Offset(SIZE size) + { x += size.cx; y += size.cy; } +_AFXWIN_INLINE BOOL CPoint::operator==(POINT point) const + { return (x == point.x && y == point.y); } +_AFXWIN_INLINE BOOL CPoint::operator!=(POINT point) const + { return (x != point.x || y != point.y); } +_AFXWIN_INLINE void CPoint::operator+=(SIZE size) + { x += size.cx; y += size.cy; } +_AFXWIN_INLINE void CPoint::operator-=(SIZE size) + { x -= size.cx; y -= size.cy; } +_AFXWIN_INLINE void CPoint::operator+=(POINT point) + { x += point.x; y += point.y; } +_AFXWIN_INLINE void CPoint::operator-=(POINT point) + { x -= point.x; y -= point.y; } +_AFXWIN_INLINE CPoint CPoint::operator+(SIZE size) const + { return CPoint(x + size.cx, y + size.cy); } +_AFXWIN_INLINE CPoint CPoint::operator-(SIZE size) const + { return CPoint(x - size.cx, y - size.cy); } +_AFXWIN_INLINE CPoint CPoint::operator-() const + { return CPoint(-x, -y); } +_AFXWIN_INLINE CPoint CPoint::operator+(POINT point) const + { return CPoint(x + point.x, y + point.y); } +_AFXWIN_INLINE CSize CPoint::operator-(POINT point) const + { return CSize(x - point.x, y - point.y); } +_AFXWIN_INLINE CRect CPoint::operator+(const RECT* lpRect) const + { return CRect(lpRect) + *this; } +_AFXWIN_INLINE CRect CPoint::operator-(const RECT* lpRect) const + { return CRect(lpRect) - *this; } + +// CRect +_AFXWIN_INLINE CRect::CRect() + { /* random filled */ } +_AFXWIN_INLINE CRect::CRect(int l, int t, int r, int b) + { left = l; top = t; right = r; bottom = b; } +_AFXWIN_INLINE CRect::CRect(const RECT& srcRect) + { ::CopyRect(this, &srcRect); } +_AFXWIN_INLINE CRect::CRect(LPCRECT lpSrcRect) + { ::CopyRect(this, lpSrcRect); } +_AFXWIN_INLINE CRect::CRect(POINT point, SIZE size) + { right = (left = point.x) + size.cx; bottom = (top = point.y) + size.cy; } +_AFXWIN_INLINE CRect::CRect(POINT topLeft, POINT bottomRight) + { left = topLeft.x; top = topLeft.y; + right = bottomRight.x; bottom = bottomRight.y; } +_AFXWIN_INLINE int CRect::Width() const + { return right - left; } +_AFXWIN_INLINE int CRect::Height() const + { return bottom - top; } +_AFXWIN_INLINE CSize CRect::Size() const + { return CSize(right - left, bottom - top); } +_AFXWIN_INLINE CPoint& CRect::TopLeft() + { return *((CPoint*)this); } +_AFXWIN_INLINE CPoint& CRect::BottomRight() + { return *((CPoint*)this+1); } +_AFXWIN_INLINE const CPoint& CRect::TopLeft() const + { return *((CPoint*)this); } +_AFXWIN_INLINE const CPoint& CRect::BottomRight() const + { return *((CPoint*)this+1); } +_AFXWIN_INLINE CPoint CRect::CenterPoint() const + { return CPoint((left+right)/2, (top+bottom)/2); } +_AFXWIN_INLINE CRect::operator LPRECT() + { return this; } +_AFXWIN_INLINE CRect::operator LPCRECT() const + { return this; } +_AFXWIN_INLINE BOOL CRect::IsRectEmpty() const + { return ::IsRectEmpty(this); } +_AFXWIN_INLINE BOOL CRect::IsRectNull() const + { return (left == 0 && right == 0 && top == 0 && bottom == 0); } +_AFXWIN_INLINE BOOL CRect::PtInRect(POINT point) const + { return ::PtInRect(this, point); } +_AFXWIN_INLINE void CRect::SetRect(int x1, int y1, int x2, int y2) + { ::SetRect(this, x1, y1, x2, y2); } +_AFXWIN_INLINE void CRect::SetRect(POINT topLeft, POINT bottomRight) + { ::SetRect(this, topLeft.x, topLeft.y, bottomRight.x, bottomRight.y); } +_AFXWIN_INLINE void CRect::SetRectEmpty() + { ::SetRectEmpty(this); } +_AFXWIN_INLINE void CRect::CopyRect(LPCRECT lpSrcRect) + { ::CopyRect(this, lpSrcRect); } +_AFXWIN_INLINE BOOL CRect::EqualRect(LPCRECT lpRect) const + { return ::EqualRect(this, lpRect); } +_AFXWIN_INLINE void CRect::InflateRect(int x, int y) + { ::InflateRect(this, x, y); } +_AFXWIN_INLINE void CRect::InflateRect(SIZE size) + { ::InflateRect(this, size.cx, size.cy); } +_AFXWIN_INLINE void CRect::DeflateRect(int x, int y) + { ::InflateRect(this, -x, -y); } +_AFXWIN_INLINE void CRect::DeflateRect(SIZE size) + { ::InflateRect(this, -size.cx, -size.cy); } +_AFXWIN_INLINE void CRect::OffsetRect(int x, int y) + { ::OffsetRect(this, x, y); } +_AFXWIN_INLINE void CRect::OffsetRect(POINT point) + { ::OffsetRect(this, point.x, point.y); } +_AFXWIN_INLINE void CRect::OffsetRect(SIZE size) + { ::OffsetRect(this, size.cx, size.cy); } +_AFXWIN_INLINE BOOL CRect::IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2) + { return ::IntersectRect(this, lpRect1, lpRect2);} +_AFXWIN_INLINE BOOL CRect::UnionRect(LPCRECT lpRect1, LPCRECT lpRect2) + { return ::UnionRect(this, lpRect1, lpRect2); } +_AFXWIN_INLINE void CRect::operator=(const RECT& srcRect) + { ::CopyRect(this, &srcRect); } +_AFXWIN_INLINE BOOL CRect::operator==(const RECT& rect) const + { return ::EqualRect(this, &rect); } +_AFXWIN_INLINE BOOL CRect::operator!=(const RECT& rect) const + { return !::EqualRect(this, &rect); } +_AFXWIN_INLINE void CRect::operator+=(POINT point) + { ::OffsetRect(this, point.x, point.y); } +_AFXWIN_INLINE void CRect::operator+=(SIZE size) + { ::OffsetRect(this, size.cx, size.cy); } +_AFXWIN_INLINE void CRect::operator+=(LPCRECT lpRect) + { InflateRect(lpRect); } +_AFXWIN_INLINE void CRect::operator-=(POINT point) + { ::OffsetRect(this, -point.x, -point.y); } +_AFXWIN_INLINE void CRect::operator-=(SIZE size) + { ::OffsetRect(this, -size.cx, -size.cy); } +_AFXWIN_INLINE void CRect::operator-=(LPCRECT lpRect) + { DeflateRect(lpRect); } +_AFXWIN_INLINE void CRect::operator&=(const RECT& rect) + { ::IntersectRect(this, this, &rect); } +_AFXWIN_INLINE void CRect::operator|=(const RECT& rect) + { ::UnionRect(this, this, &rect); } +_AFXWIN_INLINE CRect CRect::operator+(POINT pt) const + { CRect rect(*this); ::OffsetRect(&rect, pt.x, pt.y); return rect; } +_AFXWIN_INLINE CRect CRect::operator-(POINT pt) const + { CRect rect(*this); ::OffsetRect(&rect, -pt.x, -pt.y); return rect; } +_AFXWIN_INLINE CRect CRect::operator+(SIZE size) const + { CRect rect(*this); ::OffsetRect(&rect, size.cx, size.cy); return rect; } +_AFXWIN_INLINE CRect CRect::operator-(SIZE size) const + { CRect rect(*this); ::OffsetRect(&rect, -size.cx, -size.cy); return rect; } +_AFXWIN_INLINE CRect CRect::operator+(LPCRECT lpRect) const + { CRect rect(this); rect.InflateRect(lpRect); return rect; } +_AFXWIN_INLINE CRect CRect::operator-(LPCRECT lpRect) const + { CRect rect(this); rect.DeflateRect(lpRect); return rect; } +_AFXWIN_INLINE CRect CRect::operator&(const RECT& rect2) const + { CRect rect; ::IntersectRect(&rect, this, &rect2); + return rect; } +_AFXWIN_INLINE CRect CRect::operator|(const RECT& rect2) const + { CRect rect; ::UnionRect(&rect, this, &rect2); + return rect; } +_AFXWIN_INLINE BOOL CRect::SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2) + { return ::SubtractRect(this, lpRectSrc1, lpRectSrc2); } + +#endif + +// clang-format on +#endif diff --git a/LEGO1/omni/include/mxrect32.h b/LEGO1/omni/include/mxrect32.h index 1461cbb9..25af61db 100644 --- a/LEGO1/omni/include/mxrect32.h +++ b/LEGO1/omni/include/mxrect32.h @@ -1,21 +1,22 @@ #ifndef MXRECT32_H #define MXRECT32_H +#include "mfc.h" #include "mxpoint32.h" #include "mxsize32.h" // SIZE 0x10 -class MxRect32 { +class MxRect32 : public CRect { public: MxRect32() {} - MxRect32(MxS32 p_left, MxS32 p_top, MxS32 p_right, MxS32 p_bottom) { CopyFrom(p_left, p_top, p_right, p_bottom); } + MxRect32(MxS32 p_left, MxS32 p_top, MxS32 p_right, MxS32 p_bottom) : CRect(p_left, p_top, p_right, p_bottom) {} MxRect32(const MxPoint32& p_point, const MxSize32& p_size) { CopyFrom(p_point, p_size); } MxRect32(const MxRect32& p_a, const MxRect32& p_b) { - m_left = Max(p_a.m_left, p_b.m_left); - m_top = Max(p_a.m_top, p_b.m_top); - m_right = Min(p_a.m_right, p_b.m_right); - m_bottom = Min(p_a.m_bottom, p_b.m_bottom); + left = Max(p_a.left, p_b.left); + top = Max(p_a.top, p_b.top); + right = Min(p_a.right, p_b.right); + bottom = Min(p_a.bottom, p_b.bottom); } MxRect32(const MxRect32& p_rect) { CopyFrom(p_rect); } @@ -28,100 +29,95 @@ class MxRect32 { void Intersect(const MxRect32& p_rect) { - m_left = Max(p_rect.m_left, m_left); - m_top = Max(p_rect.m_top, m_top); - m_right = Min(p_rect.m_right, m_right); - m_bottom = Min(p_rect.m_bottom, m_bottom); + left = Max(p_rect.left, left); + top = Max(p_rect.top, top); + right = Min(p_rect.right, right); + bottom = Min(p_rect.bottom, bottom); } void SetPoint(const MxPoint32& p_point) { - this->m_left = p_point.GetX(); - this->m_top = p_point.GetY(); + this->left = p_point.GetX(); + this->top = p_point.GetY(); } void AddPoint(const MxPoint32& p_point) { - this->m_left += p_point.GetX(); - this->m_top += p_point.GetY(); - this->m_right += p_point.GetX(); - this->m_bottom += p_point.GetY(); + this->left += p_point.GetX(); + this->top += p_point.GetY(); + this->right += p_point.GetX(); + this->bottom += p_point.GetY(); } void SubtractPoint(const MxPoint32& p_point) { - this->m_left -= p_point.GetX(); - this->m_top -= p_point.GetY(); - this->m_right -= p_point.GetX(); - this->m_bottom -= p_point.GetY(); + this->left -= p_point.GetX(); + this->top -= p_point.GetY(); + this->right -= p_point.GetX(); + this->bottom -= p_point.GetY(); } void UpdateBounds(const MxRect32& p_rect) { - m_left = Min(m_left, p_rect.m_left); - m_top = Min(m_top, p_rect.m_top); - m_right = Max(m_right, p_rect.m_right); - m_bottom = Max(m_bottom, p_rect.m_bottom); + left = Min(left, p_rect.left); + top = Min(top, p_rect.top); + right = Max(right, p_rect.right); + bottom = Max(bottom, p_rect.bottom); } - MxBool IsValid() const { return m_left < m_right && m_top < m_bottom; } + MxBool IsValid() const { return left < right && top < bottom; } MxBool IntersectsWith(const MxRect32& p_rect) const { - return m_left < p_rect.m_right && p_rect.m_left < m_right && m_top < p_rect.m_bottom && p_rect.m_top < m_bottom; + return left < p_rect.right && p_rect.left < right && top < p_rect.bottom && p_rect.top < bottom; } - MxS32 GetWidth() const { return (m_right - m_left) + 1; } - MxS32 GetHeight() const { return (m_bottom - m_top) + 1; } + MxS32 GetWidth() const { return (right - left) + 1; } + MxS32 GetHeight() const { return (bottom - top) + 1; } - MxPoint32 GetPoint() const { return MxPoint32(this->m_left, this->m_top); } - MxSize32 GetSize() const { return MxSize32(this->m_right, this->m_bottom); } + MxPoint32 GetPoint() const { return MxPoint32(this->left, this->top); } + MxSize32 GetSize() const { return MxSize32(this->right, this->bottom); } - MxS32 GetLeft() const { return m_left; } - MxS32 GetTop() const { return m_top; } - MxS32 GetRight() const { return m_right; } - MxS32 GetBottom() const { return m_bottom; } + MxS32 GetLeft() const { return left; } + MxS32 GetTop() const { return top; } + MxS32 GetRight() const { return right; } + MxS32 GetBottom() const { return bottom; } - void SetLeft(MxS32 p_left) { m_left = p_left; } - void SetTop(MxS32 p_top) { m_top = p_top; } - void SetRight(MxS32 p_right) { m_right = p_right; } - void SetBottom(MxS32 p_bottom) { m_bottom = p_bottom; } + void SetLeft(MxS32 p_left) { left = p_left; } + void SetTop(MxS32 p_top) { top = p_top; } + void SetRight(MxS32 p_right) { right = p_right; } + void SetBottom(MxS32 p_bottom) { bottom = p_bottom; } private: void CopyFrom(MxS32 p_left, MxS32 p_top, MxS32 p_right, MxS32 p_bottom) { - this->m_left = p_left; - this->m_top = p_top; - this->m_right = p_right; - this->m_bottom = p_bottom; + this->left = p_left; + this->top = p_top; + this->right = p_right; + this->bottom = p_bottom; } void CopyFrom(const MxRect32& p_rect) { - this->m_left = p_rect.m_left; - this->m_top = p_rect.m_top; - this->m_right = p_rect.m_right; - this->m_bottom = p_rect.m_bottom; + this->left = p_rect.left; + this->top = p_rect.top; + this->right = p_rect.right; + this->bottom = p_rect.bottom; } // The address might also be the constructor that calls CopyFrom // FUNCTION: LEGO1 0x100b6fc0 MxRect32* CopyFrom(const MxPoint32& p_point, const MxSize32& p_size) { - this->m_left = p_point.GetX(); - this->m_top = p_point.GetY(); - this->m_right = p_size.GetWidth() + p_point.GetX() - 1; - this->m_bottom = p_size.GetHeight() + p_point.GetY() - 1; + this->left = p_point.GetX(); + this->top = p_point.GetY(); + this->right = p_size.GetWidth() + p_point.GetX() - 1; + this->bottom = p_size.GetHeight() + p_point.GetY() - 1; return this; } static MxS32 Min(MxS32 p_a, MxS32 p_b) { return p_a <= p_b ? p_a : p_b; } static MxS32 Max(MxS32 p_a, MxS32 p_b) { return p_a <= p_b ? p_b : p_a; } - - MxS32 m_left; // 0x00 - MxS32 m_top; // 0x04 - MxS32 m_right; // 0x08 - MxS32 m_bottom; // 0x0c }; #endif // MXRECT32_H