diff options
Diffstat (limited to 'indra/llmath')
-rw-r--r-- | indra/llmath/llcoord.h | 69 |
1 files changed, 58 insertions, 11 deletions
diff --git a/indra/llmath/llcoord.h b/indra/llmath/llcoord.h index c0623e6d1f..0b1d7e04f5 100644 --- a/indra/llmath/llcoord.h +++ b/indra/llmath/llcoord.h @@ -26,32 +26,79 @@ #ifndef LL_LLCOORD_H #define LL_LLCOORD_H +struct LL_COORD_TYPE_COMMON +{ + typedef S32 value_t; +}; + // A two-dimensional pixel value -template<typename COORD_FRAME, typename VALUE_TYPE> -class LLCoord +template<typename COORD_FRAME> +class LLCoord : protected COORD_FRAME { public: - typedef LLCoord<COORD_FRAME, VALUE_TYPE> self_t; - VALUE_TYPE mX; - VALUE_TYPE 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) {} + LLCoord(const LLCoord<LL_COORD_TYPE_COMMON>& other) + { + COORD_FRAME::convertFromCommon(other); + } + + LLCoord<LL_COORD_TYPE_COMMON> convert() const + { + return COORD_FRAME::convertToCommon(); + } + 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); } }; -struct LL_COORD_TYPE_GL {}; -struct LL_COORD_TYPE_WINDOW {}; -struct LL_COORD_TYPE_SCREEN {}; +typedef LLCoord<LL_COORD_TYPE_COMMON> LLCoordCommon; + +struct LL_COORD_TYPE_GL +{ + 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; + } +}; + +struct LL_COORD_TYPE_WINDOW +{ + typedef S32 value_t; + + LLCoordCommon convertToCommon() const; + void convertFromCommon(const LLCoordCommon& from); +}; + +struct LL_COORD_TYPE_SCREEN +{ + typedef S32 value_t; + + LLCoordCommon convertToCommon() const; + void convertFromCommon(const LLCoordCommon& from); +}; -typedef LLCoord<LL_COORD_TYPE_GL, S32> LLCoordGL; -typedef LLCoord<LL_COORD_TYPE_WINDOW, S32> LLCoordWindow; -typedef LLCoord<LL_COORD_TYPE_SCREEN, S32> LLCoordScreen; +typedef LLCoord<LL_COORD_TYPE_GL> LLCoordGL; +typedef LLCoord<LL_COORD_TYPE_WINDOW> LLCoordWindow; +typedef LLCoord<LL_COORD_TYPE_SCREEN> LLCoordScreen; #endif |