/* ========================================================================== * ÆÄ ÀÏ : UIRect.h * ¸ñ Àû : * ÀÛ ¼º ÀÚ : À̼ø±Ô * ÀÛ ¼º ÀÏ : 2006.09.30 * ÁÖÀÇ»çÇ× : *===========================================================================*/ #pragma once #include "UIPos.h" #include "UISize.h" #pragma warning( disable: 4201 ) /// UI ³ëµåÀÇ ¿µ¿ª template class tUIRect { public: tUIRect(); tUIRect( T left, T top, T right, T bottom ); tUIRect( const tUIPos& upperLeft, const tUIPos& lowerRight ); tUIRect( const tUIRect& other ); tUIRect( const tUIPos& pos, const tUISize& Size ); /// ¼³Á¤ void Set( T left, T top, T right, T bottom ); void SetPos( const tUIPos& pos ); /// Ŭ¸®ÇÎ void ClipAgainst( const tUIRect& other ); /// À߸øµÈ ºÎºÐÀ» ¼öÁ¤ void Repair(); /// Á¡À» Æ÷ÇÔÇÏ´ÂÁö ¿©ºÎ¸¦ ¸®ÅÏ bool ContainPoint( const tUIPos& pos ) const; /// ´Ù¸¥ ¿µ¿ª°ú ±³Â÷ÇÏ´ÂÁö ¿©ºÎ¸¦ ¸®ÅÏ bool IntersectRect( const tUIRect& other ) const; /// Áß½ÉÀ» ¸®ÅÏ tUIPos GetCenter() const; /// ³Êºñ¸¦ ¸®ÅÏ T GetWidth() const; /// ³ôÀ̸¦ ¸®ÅÏ T GetHeight() const; /// Å©±â¸¦ ¸®ÅÏ tUISize GetSize() const; /// ÀûÇÕ¼º ¿©ºÎ¸¦ ¸®ÅÏ bool IsValid() const; const tUIRect& operator = ( const tUIRect& other ); tUIRect operator + ( const tUIPos& pos ) const; const tUIRect& operator += ( const tUIPos& pos ); bool operator == ( const tUIRect& other ) const; bool operator != ( const tUIRect& other ) const; public: union { struct { T mLeft; T mTop; T mRight; T mBottom; }; struct { tUIPos mUpperLeft; tUIPos mLowerRight; }; }; }; template inline tUIRect::tUIRect() : mLeft( 0 ) , mTop( 0 ) , mRight( 0 ) , mBottom( 0 ) { } template inline tUIRect::tUIRect( T left, T top, T right, T bottom ) { mLeft = left; mTop = top; mRight = right; mBottom = bottom; } template inline tUIRect::tUIRect( const tUIPos& upperLeft, const tUIPos& lowerRight ) : mUpperLeft( upperLeft ) , mLowerRight( lowerRight ) { } template inline tUIRect::tUIRect( const tUIRect& other ) : mUpperLeft( other.mUpperLeft ) , mLowerRight( other.mLowerRight ) { } template inline tUIRect::tUIRect( const tUIPos& pos, const tUISize& Size ) : mUpperLeft( pos ) , mLowerRight( pos.mX + Size.mWidth, pos.mY + Size.mHeight ) { } template inline void tUIRect::Set( T left, T top, T right, T bottom ) { mLeft = left; mTop = top; mRight = right; mBottom = bottom; } template inline void tUIRect::SetPos( const tUIPos& pos ) { tUISize Size; Size.mWidth = GetWidth(); Size.mHeight = GetHeight(); mLeft = pos.mX; mTop = pos.mY; mRight = mLeft + Size.mWidth; mBottom = mTop + Size.mHeight; } template inline void tUIRect::ClipAgainst( const tUIRect& other ) { if( other.mRight < mRight ) { mRight = other.mRight; } if( other.mBottom < mBottom ) { mBottom = other.mBottom; } if( other.mLeft > mLeft ) { mLeft = other.mLeft; } if( other.mTop > mTop ) { mTop = other.mTop; } if( mTop > mBottom ) { mTop = mBottom; } if( mLeft > mRight ) { mLeft = mRight; } } template inline void tUIRect::Repair() { if( mRight < mLeft ) { T t = mRight; mRight = mLeft; mLeft = t; } if( mBottom < mTop ) { T t = mBottom; mBottom = mTop; mTop = t; } } template inline bool tUIRect::ContainPoint( const tUIPos& pos ) const { return ( mLeft <= pos.mX && mTop <= pos.mY && mRight >= pos.mX && mBottom >= pos.mY ); } template inline bool tUIRect::IntersectRect( const tUIRect& other ) const { return ( mBottom > other.mTop && mTop < other.mBottom && mRight > other.mLeft && mLeft < other.mRight ); } template inline tUIPos tUIRect::GetCenter() const { return tUIPos( ( mLeft + mRight ) / 2, ( mTop + mBottom ) / 2 ); } template inline T tUIRect::GetWidth() const { return mRight - mLeft; } template inline T tUIRect::GetHeight() const { return mBottom - mTop; } template inline tUISize tUIRect::GetSize() const { return tUISize( GetWidth(), GetHeight() ); } template inline bool tUIRect::IsValid() const { T dx = mRight - mLeft; T dy = mBottom - mTop; return !( dx < 0 || dy < 0 || ( dx == 0 && dy == 0 ) ); } template inline const tUIRect& tUIRect::operator = ( const tUIRect& other ) { mUpperLeft = other.mUpperLeft; mLowerRight = other.mLowerRight; return *this; } template inline tUIRect tUIRect::operator + ( const tUIPos& pos ) const { tUIRect ret( *this ); ret.mUpperLeft += pos; ret.mLowerRight += pos; return ret; } template inline const tUIRect& tUIRect::operator += ( const tUIPos& pos ) { mUpperLeft += pos; mLowerRight += pos; return *this; } template inline bool tUIRect::operator == ( const tUIRect& other ) const { return ( mUpperLeft == other.mUpperLeft && mLowerRight == other.mLowerRight ); } template inline bool tUIRect::operator != ( const tUIRect& other ) const { return ( mUpperLeft != other.mUpperLeft || mLowerRight != other.mLowerRight ); }