diff options
author | Merov Linden <merov@lindenlab.com> | 2011-09-23 15:20:25 -0700 |
---|---|---|
committer | Merov Linden <merov@lindenlab.com> | 2011-09-23 15:20:25 -0700 |
commit | e42a9ec70c0e5fc98282c98358039445d0d68b84 (patch) | |
tree | 555cc9b4023e5eef6e2e019eb392a1267b378de3 /indra/llui | |
parent | 1bcf6882c5faa94385f045e1c591da96408bb032 (diff) | |
parent | 53a8e1299305a4acad83f52401679c86485fcf51 (diff) |
EXP-1207 : pull from viewer-experience-fui
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/llcommandmanager.cpp | 32 | ||||
-rw-r--r-- | indra/llui/llcommandmanager.h | 16 | ||||
-rw-r--r-- | indra/llui/lltoolbar.cpp | 233 | ||||
-rw-r--r-- | indra/llui/lltoolbar.h | 22 |
4 files changed, 192 insertions, 111 deletions
diff --git a/indra/llui/llcommandmanager.cpp b/indra/llui/llcommandmanager.cpp index 306b357d6a..6be616b980 100644 --- a/indra/llui/llcommandmanager.cpp +++ b/indra/llui/llcommandmanager.cpp @@ -72,9 +72,15 @@ LLCommandManager::LLCommandManager() LLCommandManager::~LLCommandManager() { + for (CommandVector::iterator cmdIt = mCommands.begin(); cmdIt != mCommands.end(); ++cmdIt) + { + LLCommand * command = *cmdIt; + + delete command; + } } -U32 LLCommandManager::count() const +U32 LLCommandManager::commandCount() const { return mCommands.size(); } @@ -88,20 +94,24 @@ LLCommand * LLCommandManager::getCommand(const std::string& commandName) { LLCommand * command_name_match = NULL; - for (CommandVector::iterator it = mCommands.begin(); it != mCommands.end(); ++it) + CommandIndexMap::const_iterator found = mCommandIndices.find(commandName); + + if (found != mCommandIndices.end()) { - LLCommand * command = *it; - - if (command->name() == commandName) - { - command_name_match = command; - break; - } + command_name_match = mCommands[found->second]; } return command_name_match; } +void LLCommandManager::addCommand(LLCommand * command) +{ + mCommandIndices[command->name()] = mCommands.size(); + mCommands.push_back(command); + + llinfos << "Successfully added command: " << command->name() << llendl; +} + //static bool LLCommandManager::load() { @@ -129,9 +139,7 @@ bool LLCommandManager::load() { LLCommand * command = new LLCommand(commandParams); - mgr.mCommands.push_back(command); - - llinfos << "Successfully loaded command: " << command->name() << llendl; + mgr.addCommand(command); } return true; diff --git a/indra/llui/llcommandmanager.h b/indra/llui/llcommandmanager.h index 4f3c9b2ada..24378ecd62 100644 --- a/indra/llui/llcommandmanager.h +++ b/indra/llui/llcommandmanager.h @@ -24,8 +24,8 @@ * $/LicenseInfo$ */ -#ifndef LL_COMMANDMANAGER_H -#define LL_COMMANDMANAGER_H +#ifndef LL_LLCOMMANDMANAGER_H +#define LL_LLCOMMANDMANAGER_H #include "llinitparam.h" #include "llsingleton.h" @@ -82,16 +82,22 @@ public: LLCommandManager(); ~LLCommandManager(); - U32 count() const; + U32 commandCount() const; LLCommand * getCommand(U32 commandIndex); LLCommand * getCommand(const std::string& commandName); static bool load(); +protected: + void addCommand(LLCommand * command); + private: + typedef std::map<std::string, U32> CommandIndexMap; typedef std::vector<LLCommand *> CommandVector; - CommandVector mCommands; + + CommandVector mCommands; + CommandIndexMap mCommandIndices; }; -#endif // LL_COMMANDMANAGER_H +#endif // LL_LLCOMMANDMANAGER_H diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index 167dbfcc47..e052c1c876 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -27,9 +27,12 @@ #include "linden_common.h" -#include "boost/foreach.hpp" +#include <boost/foreach.hpp> #include "lltoolbar.h" +#include "llcommandmanager.h" +#include "lltrans.h" + static LLDefaultChildRegistry::Register<LLToolBar> r1("toolbar"); namespace LLToolBarEnums @@ -55,8 +58,8 @@ LLToolBar::Params::Params() button_icon("button_icon"), button_icon_and_text("button_icon_and_text"), wrap("wrap", true), - min_width("min_width", 0), - max_width("max_width", S32_MAX), + min_button_width("min_button_width", 0), + max_button_width("max_button_width", S32_MAX), background_image("background_image") {} @@ -68,10 +71,12 @@ LLToolBar::LLToolBar(const LLToolBar::Params& p) mNeedsLayout(false), mCenterPanel(NULL), mCenteringStack(NULL), - mMinWidth(p.min_width), - mMaxWidth(p.max_width), + mMinButtonWidth(p.min_button_width), + mMaxButtonWidth(p.max_button_width), mBackgroundImage(p.background_image) { + mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_ONLY] = p.button_icon; + mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT] = p.button_icon_and_text; } void LLToolBar::initFromParams(const LLToolBar::Params& p) @@ -109,120 +114,192 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p) mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p)); - addRow(); - BOOST_FOREACH (LLToolBarButton::Params button_p, p.buttons) { + // buttons always follow left and top, for all orientations + button_p.follows.flags = FOLLOWS_LEFT|FOLLOWS_TOP; + button_p.fillFrom(mButtonParams[mButtonType]); + LLRect button_rect(button_p.rect); { // remove any offset from button if (orientation == LLLayoutStack::HORIZONTAL) { - button_rect.setOriginAndSize(0, 0, mMinWidth, getRect().getHeight()); + button_rect.setOriginAndSize(0, 0, mMinButtonWidth, button_rect.getHeight()); } else // VERTICAL { - button_rect.setOriginAndSize(0, 0, mMinWidth, button_rect.getHeight()); + button_rect.setOriginAndSize(0, 0, mMinButtonWidth, button_rect.getHeight()); } } - button_p.fillFrom((mButtonType == BTNTYPE_ICONS_ONLY) - ? p.button_icon // icon only - : p.button_icon_and_text); // icon + text + // use our calculated rect + button_p.rect = button_rect; + LLToolBarButton* buttonp = LLUICtrlFactory::create<LLToolBarButton>(button_p); + + mButtons.push_back(buttonp); + mCenterPanel->addChild(buttonp); - mButtons.push_back(LLUICtrlFactory::create<LLToolBarButton>(button_p)); mNeedsLayout = true; } - - updateLayout(); } -void LLToolBar::addButton(LLToolBarButton* buttonp) +bool LLToolBar::addCommand(LLCommand * command) { - LLLayoutPanel::Params panel_p; - panel_p.name = buttonp->getName() + "_panel"; - panel_p.user_resize = false; - panel_p.auto_resize= false; - panel_p.fit_content = true; + // + // Init basic toolbar button params + // - LLLayoutPanel* panel = LLUICtrlFactory::create<LLLayoutPanel>(panel_p); - - panel->addChild(buttonp); - mStacks.back()->addChild(panel); + LLToolBarButton::Params button_p; + button_p.fillFrom(mButtonParams[mButtonType]); + + button_p.name = command->name(); + button_p.label = LLTrans::getString(command->labelRef()); + button_p.tool_tip = LLTrans::getString(command->tooltipRef()); + + // + // Set up the button rectangle + // + + S32 btn_width = mMinButtonWidth; + S32 btn_height = mButtonParams[mButtonType].rect.height; + + if ((mSideType == LLToolBarEnums::SIDE_BOTTOM) || (mSideType == LLToolBarEnums::SIDE_TOP)) + { + btn_height = getRect().getHeight(); + } + + LLRect button_rect; + button_rect.setOriginAndSize(0, 0, btn_width, btn_height); + + button_p.rect = button_rect; + + // + // Add it to the list of buttons + // + + LLToolBarButton * toolbar_button = LLUICtrlFactory::create<LLToolBarButton>(button_p); + + toolbar_button->reshape(llclamp(toolbar_button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth), toolbar_button->getRect().getHeight()); + + mButtons.push_back(toolbar_button); + mCenterPanel->addChild(toolbar_button); + + mNeedsLayout = true; + + return true; } -void LLToolBar::updateLayout() +void LLToolBar::updateLayoutAsNeeded() { - mCenteringStack->updateLayout(); - if (!mNeedsLayout) return; - mNeedsLayout = false; - { // clean up existing rows + LLLayoutStack::ELayoutOrientation orientation = getOrientation(mSideType); + + // our terminology for orientation-agnostic layout is that + // length refers to a distance in the direction we stack the buttons + // and girth refers to a distance in the direction buttons wrap + S32 row_running_length = 0; + S32 max_length = (orientation == LLLayoutStack::HORIZONTAL) + ? getRect().getWidth() + : getRect().getHeight(); + S32 max_row_girth = 0; + S32 cur_start = 0; + S32 cur_row = 0; + + LLRect panel_rect = mCenterPanel->getLocalRect(); + + std::vector<LLToolBarButton*> buttons_in_row; + BOOST_FOREACH(LLToolBarButton* button, mButtons) { - if (button->getParent()) + S32 button_clamped_width = llclamp(button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth); + S32 button_length = (orientation == LLLayoutStack::HORIZONTAL) + ? button_clamped_width + : button->getRect().getHeight(); + S32 button_girth = (orientation == LLLayoutStack::HORIZONTAL) + ? button->getRect().getHeight() + : button_clamped_width; + + // handle wrapping + if (row_running_length + button_length > max_length + && cur_start != 0) // not first button in row + { // go ahead and wrap + if (orientation == LLLayoutStack::VERTICAL) { - button->getParent()->removeChild(button); + // row girth is clamped to allowable button widths + max_row_girth = llclamp(max_row_girth, mMinButtonWidth, mMaxButtonWidth); } + // make buttons in current row all same girth + BOOST_FOREACH(LLToolBarButton* button, buttons_in_row) + { + if (orientation == LLLayoutStack::HORIZONTAL) + { + button->reshape(llclamp(button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth), max_row_girth); } - - BOOST_FOREACH(LLLayoutStack* stack, mStacks) + else // VERTICAL { - delete stack; + button->reshape(max_row_girth, button->getRect().getHeight()); + } } - mStacks.clear(); + buttons_in_row.clear(); + + row_running_length = 0; + cur_start = 0; + cur_row += max_row_girth; + max_row_girth = 0; } - // start with one row of buttons - addRow(); - S32 total_width = 0, total_height = 0; - S32 max_total_width = 0, max_total_height = 0; - S32 max_width = getRect().getWidth(), max_height = getRect().getHeight(); - BOOST_FOREACH(LLToolBarButton* button, mButtons) + LLRect button_rect; + if (orientation == LLLayoutStack::HORIZONTAL) { - S32 button_width = button->getRect().getWidth(); - S32 button_height = button->getRect().getHeight(); - - if (getOrientation(mSideType) == LLLayoutStack::HORIZONTAL - && total_width + button_height > getRect().getWidth()) + button_rect.setLeftTopAndSize(cur_start, panel_rect.mTop - cur_row, button_clamped_width, button->getRect().getHeight()); + } + else // VERTICAL { - addRow(); - total_width = 0; + button_rect.setLeftTopAndSize(cur_row, panel_rect.mTop - cur_start, button_clamped_width, button->getRect().getHeight()); } - addButton(button); - - total_width += button_width; - total_height += button_height; - max_total_width = llmax(max_total_width, total_width); - max_total_height = llmax(max_total_height, total_height); - max_width = llmax(button->getRect().getWidth(), max_width); - max_height = llmax(button->getRect().getHeight(), max_height); + button->setShape(button_rect); + + buttons_in_row.push_back(button); + + row_running_length += button_length; + cur_start = row_running_length; + max_row_girth = llmax(button_girth, max_row_girth); } - if (getOrientation(mSideType) == LLLayoutStack::HORIZONTAL) + // final resizing in "girth" direction + S32 total_girth = cur_row + max_row_girth; // increment by size of final row + + // grow and optionally shift toolbar to accomodate buttons + if (orientation == LLLayoutStack::HORIZONTAL) { - BOOST_FOREACH(LLLayoutStack* stack, mStacks) - { - stack->reshape(max_total_width, stack->getParent()->getRect().getHeight()); - stack->updateLayout(); + if (mSideType == SIDE_TOP) + { // shift down to maintain top edge + translate(0, getRect().getHeight() - total_girth); } + + reshape(getRect().getWidth(), total_girth); } - else + else // VERTICAL { - BOOST_FOREACH(LLLayoutStack* stack, mStacks) - { - stack->reshape(stack->getParent()->getRect().getWidth(), max_total_height); - stack->updateLayout(); + if (mSideType == SIDE_RIGHT) + { // shift left to maintain right edge + translate(getRect().getWidth() - total_girth, 0); + } + reshape(total_girth, getRect().getHeight()); } - reshape(max_total_width, getRect().getHeight()); - } + // recenter toolbar buttons + mCenteringStack->updateLayout(); + + // don't clear flag until after we've resized ourselves, to avoid laying out every frame + mNeedsLayout = false; } void LLToolBar::draw() { - updateLayout(); + updateLayoutAsNeeded(); { // draw background LLRect bg_rect; @@ -232,22 +309,6 @@ void LLToolBar::draw() LLUICtrl::draw(); } -void LLToolBar::addRow() -{ - LLLayoutStack::ELayoutOrientation orientation = getOrientation(mSideType); - - LLLayoutStack::Params stack_p; - stack_p.rect = getLocalRect(); - stack_p.name = llformat("button_stack_%d", mStacks.size()); - stack_p.orientation = orientation; - stack_p.follows.flags = (orientation == LLLayoutStack::HORIZONTAL) - ? (FOLLOWS_TOP|FOLLOWS_BOTTOM) // horizontal - : (FOLLOWS_LEFT|FOLLOWS_RIGHT); // vertical - - mStacks.push_back(LLUICtrlFactory::create<LLLayoutStack>(stack_p)); - mCenterPanel->addChild(mStacks.back()); -} - void LLToolBar::reshape(S32 width, S32 height, BOOL called_from_parent) { LLUICtrl::reshape(width, height, called_from_parent); diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index 3a593e42d9..85cd6d5170 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -33,6 +33,9 @@ #include "llbutton.h" +class LLCommand; + + class LLToolBarButton : public LLButton { public: @@ -50,6 +53,8 @@ namespace LLToolBarEnums { BTNTYPE_ICONS_ONLY = 0, BTNTYPE_ICONS_WITH_TEXT, + + BTNTYPE_COUNT }; enum SideType @@ -93,8 +98,8 @@ public: button_icon_and_text; Optional<bool> wrap; - Optional<S32> min_width, - max_width; + Optional<S32> min_button_width, + max_button_width; // get rid of this Multiple<LLToolBarButton::Params> buttons; @@ -107,16 +112,16 @@ public: void draw(); void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); + bool addCommand(LLCommand * command); + protected: friend class LLUICtrlFactory; LLToolBar(const Params&); void initFromParams(const Params&); - void addButton(LLToolBarButton* buttonp); - void updateLayout(); private: - void addRow(); + void updateLayoutAsNeeded(); std::list<LLToolBarButton*> mButtons; LLToolBarEnums::ButtonType mButtonType; @@ -125,13 +130,14 @@ private: LLLayoutPanel* mCenterPanel; LLToolBarEnums::SideType mSideType; - std::vector<LLLayoutStack*> mStacks; bool mWrap; bool mNeedsLayout; - S32 mMinWidth, - mMaxWidth; + S32 mMinButtonWidth, + mMaxButtonWidth; LLUIImagePtr mBackgroundImage; + + LLToolBarButton::Params mButtonParams[LLToolBarEnums::BTNTYPE_COUNT]; }; |