From edacb7b3363dca6cd28a4ff7ea27154d6a30702f Mon Sep 17 00:00:00 2001 From: Richard Nelson Date: Mon, 3 Oct 2011 18:52:22 -0700 Subject: implemented Range and ClampedValue classes to standardize min/max settings fixed not serializing named values when values provided from code --- indra/llui/lltoolbar.cpp | 11 ++-- indra/llui/lltoolbar.h | 11 ++-- indra/llui/lltoolbarview.cpp | 18 +++---- indra/llui/lltoolbarview.h | 4 +- indra/llui/llui.h | 126 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 146 insertions(+), 24 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index c0058d534d..66c2d7ab0b 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -319,7 +319,7 @@ void LLToolBar::resizeButtonsInRow(std::vector& 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 @@ -543,8 +543,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("") {} diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index 5d64630fa6..48ca6c62b3 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -41,13 +41,11 @@ class LLToolBarButton : public LLButton public: struct Params : public LLInitParam::Block { - Optional min_button_width, - max_button_width, - desired_height; + Optional > button_width; + Optional 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) {} @@ -62,8 +60,7 @@ private: LLCommandId mId; S32 mMouseDownX; S32 mMouseDownY; - S32 mMinWidth; - S32 mMaxWidth; + LLUI::Range mWidthRange; S32 mDesiredHeight; }; diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp index 12247519ad..49d4bfdc3c 100644 --- a/indra/llui/lltoolbarview.cpp +++ b/indra/llui/lltoolbarview.cpp @@ -169,8 +169,8 @@ bool LLToolBarView::loadToolbars(bool force_default) { if (toolbar_set.left_toolbar.button_display_mode.isProvided()) { - U32 button_type = toolbar_set.left_toolbar.button_display_mode; - mToolbarLeft->setButtonType((LLToolBarEnums::ButtonType)(button_type)); + LLToolBarEnums::ButtonType button_type = toolbar_set.left_toolbar.button_display_mode; + mToolbarLeft->setButtonType(button_type); } BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.left_toolbar.commands) { @@ -181,8 +181,8 @@ bool LLToolBarView::loadToolbars(bool force_default) { if (toolbar_set.right_toolbar.button_display_mode.isProvided()) { - U32 button_type = toolbar_set.right_toolbar.button_display_mode; - mToolbarRight->setButtonType((LLToolBarEnums::ButtonType)(button_type)); + LLToolBarEnums::ButtonType button_type = toolbar_set.right_toolbar.button_display_mode; + mToolbarRight->setButtonType(button_type); } BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.right_toolbar.commands) { @@ -193,8 +193,8 @@ bool LLToolBarView::loadToolbars(bool force_default) { if (toolbar_set.bottom_toolbar.button_display_mode.isProvided()) { - U32 button_type = toolbar_set.bottom_toolbar.button_display_mode; - mToolbarBottom->setButtonType((LLToolBarEnums::ButtonType)(button_type)); + LLToolBarEnums::ButtonType button_type = toolbar_set.bottom_toolbar.button_display_mode; + mToolbarBottom->setButtonType(button_type); } BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.bottom_toolbar.commands) { @@ -223,17 +223,17 @@ void LLToolBarView::saveToolbars() const LLToolBarView::ToolbarSet toolbar_set; if (mToolbarLeft) { - toolbar_set.left_toolbar.button_display_mode = (int)(mToolbarLeft->getButtonType()); + toolbar_set.left_toolbar.button_display_mode = mToolbarLeft->getButtonType(); addToToolset(mToolbarLeft->getCommandsList(),toolbar_set.left_toolbar); } if (mToolbarRight) { - toolbar_set.right_toolbar.button_display_mode = (int)(mToolbarRight->getButtonType()); + toolbar_set.right_toolbar.button_display_mode = mToolbarRight->getButtonType(); addToToolset(mToolbarRight->getCommandsList(),toolbar_set.right_toolbar); } if (mToolbarBottom) { - toolbar_set.bottom_toolbar.button_display_mode = (int)(mToolbarBottom->getButtonType()); + toolbar_set.bottom_toolbar.button_display_mode = mToolbarBottom->getButtonType(); addToToolset(mToolbarBottom->getCommandsList(),toolbar_set.bottom_toolbar); } diff --git a/indra/llui/lltoolbarview.h b/indra/llui/lltoolbarview.h index 20525a22ac..c67b8d9d64 100644 --- a/indra/llui/lltoolbarview.h +++ b/indra/llui/lltoolbarview.h @@ -50,8 +50,8 @@ public: // the user folder for the user specific (saved) settings struct Toolbar : public LLInitParam::Block { - Mandatory button_display_mode; - Multiple commands; + Mandatory button_display_mode; + Multiple commands; Toolbar(); }; struct ToolbarSet : public LLInitParam::Block 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 @@ -147,6 +147,132 @@ class LLUI { LOG_CLASS(LLUI); public: + // + // Classes + // + + template + struct Range + { + typedef Range self_t; + + struct Params : public LLInitParam::Block + { + Optional 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 + struct ClampedValue : public Range + { + typedef Range range_t; + + struct Params : public LLInitParam::Block + { + Mandatory 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 ClampedS32; + // // Methods // -- cgit v1.2.3 From 3689995fcfca3a99038b2aadec638819a63a02c8 Mon Sep 17 00:00:00 2001 From: Richard Nelson Date: Mon, 3 Oct 2011 18:58:30 -0700 Subject: fixed build --- indra/llui/lltoolbar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index 4b7e04b682..efa077ffa1 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -107,7 +107,7 @@ LLToolBar::LLToolBar(const LLToolBar::Params& p) { mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT] = p.button_icon_and_text; mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_ONLY] = p.button_icon; - mUUID = LLUUID::LLUUID::generateNewID(p.name); + mUUID = LLUUID::generateNewID(p.name); } LLToolBar::~LLToolBar() @@ -570,7 +570,7 @@ LLToolBarButton::LLToolBarButton(const Params& p) mDesiredHeight(p.desired_height), mId("") { - mUUID = LLUUID::LLUUID::generateNewID(p.name); + mUUID = LLUUID::generateNewID(p.name); } BOOL LLToolBarButton::handleMouseDown(S32 x, S32 y, MASK mask) -- cgit v1.2.3 From 44e9fb446f3c92c3dfd9b5be8a3e02ec5a44ba00 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 4 Oct 2011 12:04:29 -0700 Subject: another potential gcc fix --- indra/llui/llui.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llui.h b/indra/llui/llui.h index 9f6fccfef6..8cec1a16f4 100644 --- a/indra/llui/llui.h +++ b/indra/llui/llui.h @@ -158,8 +158,8 @@ public: struct Params : public LLInitParam::Block { - Optional minimum, - maximum; + typename Optional minimum, + maximum; Params() : minimum("min", 0), -- cgit v1.2.3 From 50c0447808f7041d5af5017c847a462e9599bdb5 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 4 Oct 2011 13:26:54 -0700 Subject: disabled min and max windows macros another attempt at fixing gcc builds --- indra/llui/llui.h | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llui.h b/indra/llui/llui.h index 8cec1a16f4..af8f239657 100644 --- a/indra/llui/llui.h +++ b/indra/llui/llui.h @@ -41,6 +41,7 @@ #include #include "lllazyvalue.h" #include "llframetimer.h" +#include // LLUIFactory #include "llsd.h" @@ -150,27 +151,25 @@ public: // // Classes // + template + struct RangeParams : public LLInitParam::Block > + { + Optional minimum, + maximum; + + RangeParams() + : minimum("min", T()), + maximum("max", std::numeric_limits::max()) + {} + }; template struct Range { typedef Range self_t; - struct Params : public LLInitParam::Block - { - typename Optional minimum, - maximum; - - Params() - : minimum("min", 0), - maximum("max", S32_MAX) - { - - } - }; - // correct for inverted params - Range(const Params& p = Params()) + Range(const RangeParams& p = RangeParams()) : mMin(p.minimum), mMax(p.maximum) { @@ -228,12 +227,12 @@ public: { typedef Range range_t; - struct Params : public LLInitParam::Block + struct Params : public LLInitParam::Block > { - Mandatory value; + Mandatory value; Params() - : value("", 0) + : value("", T()) { addSynonym(value, "value"); } -- cgit v1.2.3 From db2e763ff0537785336a330d03bb9307478cb79a Mon Sep 17 00:00:00 2001 From: Leslie Linden Date: Tue, 4 Oct 2011 14:09:03 -0700 Subject: * Modified commands to add functions for is_enabled, is_running and is_starting, currently not hooked to any functionality. --- indra/llui/llcommandmanager.cpp | 24 +++++++++++++++++------ indra/llui/llcommandmanager.h | 43 +++++++++++++++++++++++++++++++++++------ indra/llui/lltoolbar.cpp | 4 ++-- 3 files changed, 57 insertions(+), 14 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llcommandmanager.cpp b/indra/llui/llcommandmanager.cpp index b1147134c2..922f243806 100644 --- a/indra/llui/llcommandmanager.cpp +++ b/indra/llui/llcommandmanager.cpp @@ -48,24 +48,36 @@ const LLCommandId LLCommandId::null("null command"); // LLCommand::Params::Params() - : function("function") - , available_in_toybox("available_in_toybox", false) + : available_in_toybox("available_in_toybox", false) , icon("icon") , label_ref("label_ref") , name("name") - , parameter("parameter") , tooltip_ref("tooltip_ref") + , execute_function("execute_function") + , execute_parameters("execute_parameters") + , is_enabled_function("is_enabled_function") + , is_enabled_parameters("is_enabled_parameters") + , is_running_function("is_running_function") + , is_running_parameters("is_running_parameters") + , is_starting_function("is_starting_function") + , is_starting_parameters("is_starting_parameters") { } LLCommand::LLCommand(const LLCommand::Params& p) - : mFunction(p.function) - , mAvailableInToybox(p.available_in_toybox) + : mAvailableInToybox(p.available_in_toybox) , mIcon(p.icon) , mIdentifier(p.name) , mLabelRef(p.label_ref) - , mParameter(p.parameter) , mTooltipRef(p.tooltip_ref) + , mExecuteFunction(p.execute_function) + , mExecuteParameters(p.execute_parameters) + , mIsEnabledFunction(p.is_enabled_function) + , mIsEnabledParameters(p.is_enabled_parameters) + , mIsRunningFunction(p.is_running_function) + , mIsRunningParameters(p.is_running_parameters) + , mIsStartingFunction(p.is_starting_function) + , mIsStartingParameters(p.is_starting_parameters) { } diff --git a/indra/llui/llcommandmanager.h b/indra/llui/llcommandmanager.h index 6481a05689..3ac5548a0d 100644 --- a/indra/llui/llcommandmanager.h +++ b/indra/llui/llcommandmanager.h @@ -83,41 +83,72 @@ private: typedef std::list command_id_list_t; + class LLCommand { public: struct Params : public LLInitParam::Block { Mandatory available_in_toybox; - Mandatory function; Mandatory icon; Mandatory label_ref; Mandatory name; - Optional parameter; Mandatory tooltip_ref; + Mandatory execute_function; + Optional execute_parameters; + + Optional is_enabled_function; + Optional is_enabled_parameters; + + Optional is_running_function; + Optional is_running_parameters; + + Optional is_starting_function; + Optional is_starting_parameters; + Params(); }; LLCommand(const LLCommand::Params& p); const bool availableInToybox() const { return mAvailableInToybox; } - const std::string& functionName() const { return mFunction; } const std::string& icon() const { return mIcon; } const LLCommandId& id() const { return mIdentifier; } const std::string& labelRef() const { return mLabelRef; } - const LLSD& parameter() const { return mParameter; } const std::string& tooltipRef() const { return mTooltipRef; } + const std::string& executeFunctionName() const { return mExecuteFunction; } + const LLSD& executeParameters() const { return mExecuteParameters; } + + const std::string& isEnabledFunctionName() const { return mIsEnabledFunction; } + const LLSD& isEnabledParameters() const { return mIsEnabledParameters; } + + const std::string& isRunningFunctionName() const { return mIsRunningFunction; } + const LLSD& isRunningParameters() const { return mIsRunningParameters; } + + const std::string& isStartingFunctionName() const { return mIsStartingFunction; } + const LLSD& isStartingParameters() const { return mIsStartingParameters; } + private: LLCommandId mIdentifier; bool mAvailableInToybox; - std::string mFunction; std::string mIcon; std::string mLabelRef; - LLSD mParameter; std::string mTooltipRef; + + std::string mExecuteFunction; + LLSD mExecuteParameters; + + std::string mIsEnabledFunction; + LLSD mIsEnabledParameters; + + std::string mIsRunningFunction; + LLSD mIsRunningParameters; + + std::string mIsStartingFunction; + LLSD mIsStartingParameters; }; diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index efa077ffa1..a544aa9ec7 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -525,8 +525,8 @@ LLToolBarButton* LLToolBar::createButton(const LLCommandId& id) if (!mReadOnly) { LLUICtrl::CommitCallbackParam cbParam; - cbParam.function_name = commandp->functionName(); - cbParam.parameter = commandp->parameter(); + cbParam.function_name = commandp->executeFunctionName(); + cbParam.parameter = commandp->executeParameters(); button->setCommitCallback(cbParam); button->setStartDragCallback(mStartDragItemCallback); button->setHandleDragCallback(mHandleDragItemCallback); -- cgit v1.2.3 From a8fcfc5e19811ce579799d415a9ad63a0f1f6dc7 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 4 Oct 2011 14:11:45 -0700 Subject: removed attempt at templating LLUI::Clamp values in order to get build working again --- indra/llui/lltoolbar.h | 4 +-- indra/llui/llui.h | 72 ++++++++++++++++++++++---------------------------- 2 files changed, 34 insertions(+), 42 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index 407cbde7d2..3c317e10a2 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -45,7 +45,7 @@ class LLToolBarButton : public LLButton public: struct Params : public LLInitParam::Block { - Optional > button_width; + Optional button_width; Optional desired_height; Params() @@ -67,7 +67,7 @@ private: LLCommandId mId; S32 mMouseDownX; S32 mMouseDownY; - LLUI::Range mWidthRange; + LLUI::RangeS32 mWidthRange; S32 mDesiredHeight; bool mIsDragged; startdrag_callback_t mStartDragItemCallback; diff --git a/indra/llui/llui.h b/indra/llui/llui.h index af8f239657..28e84fa444 100644 --- a/indra/llui/llui.h +++ b/indra/llui/llui.h @@ -151,46 +151,43 @@ public: // // Classes // - template - struct RangeParams : public LLInitParam::Block > - { - Optional minimum, - maximum; - RangeParams() - : minimum("min", T()), - maximum("max", std::numeric_limits::max()) - {} - }; - - template - struct Range + struct RangeS32 { - typedef Range self_t; + struct Params : public LLInitParam::Block + { + Optional minimum, + maximum; + + Params() + : minimum("min", 0), + maximum("max", S32_MAX) + {} + }; // correct for inverted params - Range(const RangeParams& p = RangeParams()) - : mMin(p.minimum), + RangeS32(const Params& p = Params()) + : mMin(p.minimum), mMax(p.maximum) { sanitizeRange(); } - Range(T minimum, T maximum) - : mMin(minimum), + RangeS32(S32 minimum, S32 maximum) + : mMin(minimum), mMax(maximum) { sanitizeRange(); } - S32 clamp(T input) + S32 clamp(S32 input) { if (input < mMin) return mMin; if (input > mMax) return mMax; return input; } - void setRange(T minimum, T maximum) + void setRange(S32 minimum, S32 maximum) { mMin = minimum; mMax = maximum; @@ -200,7 +197,7 @@ public: S32 getMin() { return mMin; } S32 getMax() { return mMax; } - bool operator==(const self_t& other) const + bool operator==(const RangeS32& other) const { return mMin == other.mMin && mMax == other.mMax; @@ -218,60 +215,55 @@ public: } - T mMin, + S32 mMin, mMax; }; - template - struct ClampedValue : public Range + struct ClampedS32 : public RangeS32 { - typedef Range range_t; - - struct Params : public LLInitParam::Block > + struct Params : public LLInitParam::Block { - Mandatory value; + Mandatory value; Params() - : value("", T()) + : value("", 0) { addSynonym(value, "value"); } }; - ClampedValue(const Params& p) - : range_t(p) + ClampedS32(const Params& p) + : RangeS32(p) {} - ClampedValue(const range_t& range) - : range_t(range) + ClampedS32(const RangeS32& range) + : RangeS32(range) { // set value here, after range has been sanitized mValue = clamp(0); } - ClampedValue(T value, const range_t& range = range_t()) - : range_t(range) + ClampedS32(S32 value, const RangeS32& range = RangeS32()) + : RangeS32(range) { mValue = clamp(value); } - T get() + S32 get() { return mValue; } - void set(T value) + void set(S32 value) { mValue = clamp(value); } private: - T mValue; + S32 mValue; }; - typedef ClampedValue ClampedS32; - // // Methods // -- cgit v1.2.3