diff options
Diffstat (limited to 'indra/llui/llui.h')
-rw-r--r-- | indra/llui/llui.h | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/indra/llui/llui.h b/indra/llui/llui.h index 3afb7c65a9..28e84fa444 100644 --- a/indra/llui/llui.h +++ b/indra/llui/llui.h @@ -41,6 +41,7 @@ #include <boost/signals2.hpp> #include "lllazyvalue.h" #include "llframetimer.h" +#include <limits> // LLUIFactory #include "llsd.h" @@ -148,6 +149,122 @@ class LLUI LOG_CLASS(LLUI); public: // + // Classes + // + + struct RangeS32 + { + struct Params : public LLInitParam::Block<Params> + { + Optional<S32> minimum, + maximum; + + Params() + : minimum("min", 0), + maximum("max", S32_MAX) + {} + }; + + // correct for inverted params + RangeS32(const Params& p = Params()) + : mMin(p.minimum), + mMax(p.maximum) + { + sanitizeRange(); + } + + RangeS32(S32 minimum, S32 maximum) + : mMin(minimum), + mMax(maximum) + { + sanitizeRange(); + } + + S32 clamp(S32 input) + { + if (input < mMin) return mMin; + if (input > mMax) return mMax; + return input; + } + + void setRange(S32 minimum, S32 maximum) + { + mMin = minimum; + mMax = maximum; + sanitizeRange(); + } + + S32 getMin() { return mMin; } + S32 getMax() { return mMax; } + + bool operator==(const RangeS32& other) const + { + return mMin == other.mMin + && mMax == other.mMax; + } + private: + void sanitizeRange() + { + if (mMin > mMax) + { + llwarns << "Bad interval range (" << mMin << ", " << mMax << ")" << llendl; + // since max is usually the most dangerous one to ignore (buffer overflow, etc), prefer it + // in the case of a malformed range + mMin = mMax; + } + } + + + S32 mMin, + mMax; + }; + + struct ClampedS32 : public RangeS32 + { + struct Params : public LLInitParam::Block<Params, RangeS32::Params> + { + Mandatory<S32> value; + + Params() + : value("", 0) + { + addSynonym(value, "value"); + } + }; + + ClampedS32(const Params& p) + : RangeS32(p) + {} + + ClampedS32(const RangeS32& range) + : RangeS32(range) + { + // set value here, after range has been sanitized + mValue = clamp(0); + } + + ClampedS32(S32 value, const RangeS32& range = RangeS32()) + : RangeS32(range) + { + mValue = clamp(value); + } + + S32 get() + { + return mValue; + } + + void set(S32 value) + { + mValue = clamp(value); + } + + + private: + S32 mValue; + }; + + // // Methods // typedef std::map<std::string, LLControlGroup*> settings_map_t; |