00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SALT_RECT_H
00023 #define SALT_RECT_H
00024
00025 #ifdef HAVE_CONFIG_H
00026 #include <config.h>
00027 #endif
00028
00029 #include "defines.h"
00030
00031 namespace salt
00032 {
00033
00035 class Rect
00036 {
00037 public:
00039 f_inline Rect() { }
00041 f_inline Rect(const Rect &inOther) : mLeft(inOther.Left()), mTop(inOther.Top()), mRight(inOther.Right()), mBottom(inOther.Bottom()) { }
00042
00044 f_inline Rect(int inLeft, int inTop, int inRight, int inBottom) : mLeft(inLeft), mTop(inTop), mRight(inRight), mBottom(inBottom) { }
00045
00047 f_inline void Set(int inLeft, int inTop, int inRight, int inBottom) { mLeft=inLeft; mTop=inTop; mRight=inRight; mBottom=inBottom; }
00048
00049
00051 f_inline int Left() const { return mLeft; }
00052
00054 f_inline int Right() const { return mRight; }
00055
00057 f_inline int Top() const { return mTop; }
00058
00060 f_inline int Bottom() const { return mBottom; }
00061
00063 f_inline int Width() const { return mRight-mLeft; }
00064
00066 f_inline int Height() const { return mBottom-mTop; }
00067
00069
00070 f_inline void Normalize() { if (mRight < mLeft) gSwap(mLeft, mRight); if (mBottom < mTop) gSwap(mTop, mBottom); }
00071
00073 f_inline void Widen(int inDelta) { mLeft-=inDelta; mTop-=inDelta; mRight+=inDelta; mBottom+=inDelta; }
00074
00078 f_inline void Widen(int inDeltaWidth, int inDeltaHeight) { mRight+=inDeltaWidth; mBottom+=inDeltaHeight; }
00079
00084 f_inline void Widen(int inDeltaLeft, int inDeltaTop, int inDeltaRight, int inDeltaBottom) { mLeft-=inDeltaLeft; mTop-=inDeltaTop; mRight+=inDeltaRight; mBottom+=inDeltaBottom; }
00085
00087 f_inline void Shrink(int inDelta) { mLeft+=inDelta; mTop+=inDelta; mRight-=inDelta; mBottom-=inDelta; }
00088
00092 f_inline void Shrink(int inDeltaWidth, int inDeltaHeight) { mRight-=inDeltaWidth; mBottom-=inDeltaHeight; }
00093
00098 f_inline void Shrink(int inDeltaLeft, int inDeltaTop, int inDeltaRight, int inDeltaBottom) { mLeft+=inDeltaLeft; mTop+=inDeltaTop; mRight-=inDeltaRight; mBottom-=inDeltaBottom; }
00099
00101 f_inline void Offset(int inDeltaX, int inDeltaY) { mLeft+=inDeltaX; mTop+=inDeltaY; mRight+=inDeltaX; mBottom+=inDeltaY; }
00102
00104 f_inline bool Intersects(const Rect &b) const { return !(mLeft > b.mRight || mRight < b.mLeft || mTop > b.mBottom || mBottom < b.mTop); }
00105
00106
00107
00109 f_inline Rect& operator=(const Rect &inOther) { mLeft=inOther.Left(); mTop=inOther.Top(); mRight=inOther.Right(); mBottom=inOther.Bottom(); return *this; }
00110
00111
00112
00114 f_inline bool operator==(const Rect &inRHS) const { return (mLeft==inRHS.Left()) && (mTop==inRHS.Top()) && (mRight==inRHS.Right()) && (mBottom==inRHS.Bottom()); }
00115
00117 f_inline bool operator!=(const Rect &inRHS) const { return (mLeft!=inRHS.Left()) || (mTop!=inRHS.Top()) || (mRight!=inRHS.Right()) || (mBottom!=inRHS.Bottom()); }
00118
00119 private:
00121 int mLeft;
00122
00124 int mTop;
00125
00127 int mRight;
00128
00130 int mBottom;
00131 };
00132
00133 }
00134
00135 #endif //SALT_RECT_H