diff options
author | Merov Linden <merov@lindenlab.com> | 2012-05-08 10:18:03 -0700 |
---|---|---|
committer | Merov Linden <merov@lindenlab.com> | 2012-05-08 10:18:03 -0700 |
commit | 60f602d5e12a50623b51b13e097992f79006823f (patch) | |
tree | 386e3cf5b25f3292e3ba7c8a9b0524c5bfbb9589 /indra/llmath/llcoord.h | |
parent | 29da931051202a10ea71db56e47acecae1603a5d (diff) | |
parent | ccb86a2a6675b21dda6267d4a850e5a09acbafa4 (diff) |
Pull from VirLinden/drano
Diffstat (limited to 'indra/llmath/llcoord.h')
-rw-r--r-- | indra/llmath/llcoord.h | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/indra/llmath/llcoord.h b/indra/llmath/llcoord.h index 706ad92787..1f617e649e 100644 --- a/indra/llmath/llcoord.h +++ b/indra/llmath/llcoord.h @@ -26,80 +26,80 @@ #ifndef LL_LLCOORD_H #define LL_LLCOORD_H +struct LLCoordCommon +{ + LLCoordCommon(S32 x, S32 y) : mX(x), mY(y) {} + LLCoordCommon() : mX(0), mY(0) {} + S32 mX; + S32 mY; +}; + // A two-dimensional pixel value -class LLCoord +template<typename COORD_FRAME> +class LLCoord : protected COORD_FRAME { public: - S32 mX; - S32 mY; + typedef LLCoord<COORD_FRAME> self_t; + typename COORD_FRAME::value_t mX; + typename COORD_FRAME::value_t mY; LLCoord(): mX(0), mY(0) {} LLCoord(S32 x, S32 y): mX(x), mY(y) {} - virtual ~LLCoord() - {} - virtual void set(S32 x, S32 y) { mX = x; mY = y; } -}; + LLCoord(const LLCoordCommon& other) + { + COORD_FRAME::convertFromCommon(other); + } + LLCoordCommon convert() const + { + return COORD_FRAME::convertToCommon(); + } -// GL coordinates start in the client region of a window, -// with left, bottom = 0, 0 -class LLCoordGL : public LLCoord -{ -public: - LLCoordGL() : LLCoord() - {} - LLCoordGL(S32 x, S32 y) : LLCoord(x, y) - {} - bool operator==(const LLCoordGL& other) const { return mX == other.mX && mY == other.mY; } - bool operator!=(const LLCoordGL& other) const { return !(*this == other); } -}; + void set(S32 x, S32 y) { mX = x; mY = y;} + bool operator==(const self_t& other) const { return mX == other.mX && mY == other.mY; } + bool operator!=(const self_t& other) const { return !(*this == other); } -//bool operator ==(const LLCoordGL& a, const LLCoordGL& b); +}; -// Window coords include things like window borders, -// menu regions, etc. -class LLCoordWindow : public LLCoord +struct LL_COORD_TYPE_GL { -public: - LLCoordWindow() : LLCoord() - {} - LLCoordWindow(S32 x, S32 y) : LLCoord(x, y) - {} - bool operator==(const LLCoordWindow& other) const { return mX == other.mX && mY == other.mY; } - bool operator!=(const LLCoordWindow& other) const { return !(*this == other); } -}; + typedef S32 value_t; + LLCoordCommon convertToCommon() const + { + const LLCoord<LL_COORD_TYPE_GL>& self = static_cast<const LLCoord<LL_COORD_TYPE_GL>&>(*this); + return LLCoordCommon(self.mX, self.mY); + } + + void convertFromCommon(const LLCoordCommon& from) + { + LLCoord<LL_COORD_TYPE_GL>& self = static_cast<LLCoord<LL_COORD_TYPE_GL>&>(*this); + self.mX = from.mX; + self.mY = from.mY; + } +}; -// Screen coords start at left, top = 0, 0 -class LLCoordScreen : public LLCoord +struct LL_COORD_TYPE_WINDOW { -public: - LLCoordScreen() : LLCoord() - {} - LLCoordScreen(S32 x, S32 y) : LLCoord(x, y) - {} - bool operator==(const LLCoordScreen& other) const { return mX == other.mX && mY == other.mY; } - bool operator!=(const LLCoordScreen& other) const { return !(*this == other); } + typedef S32 value_t; + + LLCoordCommon convertToCommon() const; + void convertFromCommon(const LLCoordCommon& from); }; -class LLCoordFont : public LLCoord +struct LL_COORD_TYPE_SCREEN { -public: - F32 mZ; - - LLCoordFont() : LLCoord(), mZ(0.f) - {} - LLCoordFont(S32 x, S32 y, F32 z = 0) : LLCoord(x,y), mZ(z) - {} - - void set(S32 x, S32 y) { LLCoord::set(x,y); mZ = 0.f; } - void set(S32 x, S32 y, F32 z) { mX = x; mY = y; mZ = z; } - bool operator==(const LLCoordFont& other) const { return mX == other.mX && mY == other.mY; } - bool operator!=(const LLCoordFont& other) const { return !(*this == other); } + typedef S32 value_t; + + LLCoordCommon convertToCommon() const; + void convertFromCommon(const LLCoordCommon& from); }; - + +typedef LLCoord<LL_COORD_TYPE_GL> LLCoordGL; +typedef LLCoord<LL_COORD_TYPE_WINDOW> LLCoordWindow; +typedef LLCoord<LL_COORD_TYPE_SCREEN> LLCoordScreen; #endif |