diff options
author | Richard Nelson <richard@lindenlab.com> | 2011-10-03 18:52:55 -0700 |
---|---|---|
committer | Richard Nelson <richard@lindenlab.com> | 2011-10-03 18:52:55 -0700 |
commit | ca8bac23949c361eea2d33198a8211ed1d8f15c3 (patch) | |
tree | 47dadd0308513c7302c5c5193b66436457d7f7b1 /indra/llui | |
parent | daae211fe3e2d1da3623951b1166473c53ce5808 (diff) | |
parent | edacb7b3363dca6cd28a4ff7ea27154d6a30702f (diff) |
Automated merge with ssh://hg.lindenlab.com/richard/viewer-experience-fui
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/lltoolbar.cpp | 17 | ||||
-rw-r--r-- | indra/llui/lltoolbar.h | 13 | ||||
-rw-r--r-- | indra/llui/llui.h | 126 |
3 files changed, 139 insertions, 17 deletions
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index 199574629f..4b7e04b682 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -319,7 +319,7 @@ void LLToolBar::resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row { if (getOrientation(mSideType) == LLLayoutStack::HORIZONTAL) { - button->reshape(llclamp(button->getRect().getWidth(), button->mMinWidth, button->mMaxWidth), max_row_girth); + button->reshape(button->mWidthRange.clamp(button->getRect().getWidth()), max_row_girth); } else // VERTICAL { @@ -378,10 +378,10 @@ void LLToolBar::updateLayoutAsNeeded() BOOST_FOREACH(LLToolBarButton* button, mButtons) { - button->reshape(button->mMinWidth, button->mDesiredHeight); + button->reshape(button->mWidthRange.getMin(), button->mDesiredHeight); button->autoResize(); - S32 button_clamped_width = llclamp(button->getRect().getWidth(), button->mMinWidth, button->mMaxWidth); + S32 button_clamped_width = button->mWidthRange.clamp(button->getRect().getWidth()); S32 button_length = (orientation == LLLayoutStack::HORIZONTAL) ? button_clamped_width : button->getRect().getHeight(); @@ -396,7 +396,7 @@ void LLToolBar::updateLayoutAsNeeded() { if (orientation == LLLayoutStack::VERTICAL) { // row girth (width in this case) is clamped to allowable button widths - max_row_girth = llclamp(max_row_girth, button->mMinWidth, button->mMaxWidth); + max_row_girth = button->mWidthRange.clamp(max_row_girth); } // make buttons in current row all same girth @@ -566,8 +566,7 @@ LLToolBarButton::LLToolBarButton(const Params& p) : LLButton(p), mMouseDownX(0), mMouseDownY(0), - mMinWidth(p.min_button_width), - mMaxWidth(p.max_button_width), + mWidthRange(p.button_width), mDesiredHeight(p.desired_height), mId("") { @@ -581,7 +580,7 @@ BOOL LLToolBarButton::handleMouseDown(S32 x, S32 y, MASK mask) return LLButton::handleMouseDown(x, y, mask); } -BOOL LLToolBarButton::handleHover( S32 x, S32 y, MASK mask ) +BOOL LLToolBarButton::handleHover(S32 x, S32 y, MASK mask) { // llinfos << "Merov debug: handleHover, x = " << x << ", y = " << y << ", mouse = " << hasMouseCapture() << llendl; BOOL handled = FALSE; @@ -595,10 +594,10 @@ BOOL LLToolBarButton::handleHover( S32 x, S32 y, MASK mask ) handled = TRUE; } else - { + { handled = mHandleDragItemCallback(x,y,mUUID,LLAssetType::AT_WIDGET); + } } - } else { handled = LLButton::handleHover(x, y, mask); diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index 10e5f49c0f..407cbde7d2 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -45,13 +45,11 @@ class LLToolBarButton : public LLButton public: struct Params : public LLInitParam::Block<Params, LLButton::Params> { - Optional<S32> min_button_width, - max_button_width, - desired_height; + Optional<LLUI::Range<S32> > button_width; + Optional<S32> desired_height; Params() - : min_button_width("min_button_width", 0), - max_button_width("max_button_width", S32_MAX), + : button_width("button_width"), desired_height("desired_height", 20) {} @@ -69,8 +67,7 @@ private: LLCommandId mId; S32 mMouseDownX; S32 mMouseDownY; - S32 mMinWidth; - S32 mMaxWidth; + LLUI::Range<S32> mWidthRange; S32 mDesiredHeight; bool mIsDragged; startdrag_callback_t mStartDragItemCallback; @@ -152,7 +149,7 @@ public: void* cargo_data, EAcceptance* accept, std::string& tooltip_msg); - + bool addCommand(const LLCommandId& commandId); bool hasCommand(const LLCommandId& commandId) const; bool enableCommand(const LLCommandId& commandId, bool enabled); diff --git a/indra/llui/llui.h b/indra/llui/llui.h index 3afb7c65a9..9f6fccfef6 100644 --- a/indra/llui/llui.h +++ b/indra/llui/llui.h @@ -148,6 +148,132 @@ class LLUI LOG_CLASS(LLUI); public: // + // Classes + // + + template <typename T> + struct Range + { + typedef Range<T> self_t; + + struct Params : public LLInitParam::Block<Params> + { + Optional<T> minimum, + maximum; + + Params() + : minimum("min", 0), + maximum("max", S32_MAX) + { + + } + }; + + // correct for inverted params + Range(const Params& p = Params()) + : mMin(p.minimum), + mMax(p.maximum) + { + sanitizeRange(); + } + + Range(T minimum, T maximum) + : mMin(minimum), + mMax(maximum) + { + sanitizeRange(); + } + + S32 clamp(T input) + { + if (input < mMin) return mMin; + if (input > mMax) return mMax; + return input; + } + + void setRange(T minimum, T maximum) + { + mMin = minimum; + mMax = maximum; + sanitizeRange(); + } + + S32 getMin() { return mMin; } + S32 getMax() { return mMax; } + + bool operator==(const self_t& 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; + } + } + + + T mMin, + mMax; + }; + + template<typename T> + struct ClampedValue : public Range<T> + { + typedef Range<T> range_t; + + struct Params : public LLInitParam::Block<Params, typename range_t::Params> + { + Mandatory<S32> value; + + Params() + : value("", 0) + { + addSynonym(value, "value"); + } + }; + + ClampedValue(const Params& p) + : range_t(p) + {} + + ClampedValue(const range_t& range) + : range_t(range) + { + // set value here, after range has been sanitized + mValue = clamp(0); + } + + ClampedValue(T value, const range_t& range = range_t()) + : range_t(range) + { + mValue = clamp(value); + } + + T get() + { + return mValue; + } + + void set(T value) + { + mValue = clamp(value); + } + + + private: + T mValue; + }; + + typedef ClampedValue<S32> ClampedS32; + + // // Methods // typedef std::map<std::string, LLControlGroup*> settings_map_t; |