From 565483ee1f2ea7b8d525c6d89700452216481c5e Mon Sep 17 00:00:00 2001 From: Leslie Linden Date: Thu, 22 Sep 2011 15:43:08 -0700 Subject: EXP-1205 PROGRESS -- As a User, I want a toybox which will contain all buttons that I can d&d into the toolbars EXP-1233 PROGRESS -- Populate the toybox floater window with all FUI toolbar buttons EXP-1236 FIX -- The toybox floater should remember its position for the user * Basic addCommand function to the LLToolBar. Need proper implementation. * Added map for faster lookup of commands * Toybox now adds commands to its toolbar for basic button setup Reviewed by Richard. --- indra/llui/llcommandmanager.cpp | 32 +++++---- indra/llui/llcommandmanager.h | 16 +++-- indra/llui/lltoolbar.cpp | 77 ++++++++++++++++++---- indra/llui/lltoolbar.h | 9 +++ indra/newview/llfloatertoybox.cpp | 18 ++--- indra/newview/llfloatertoybox.h | 5 +- .../skins/default/xui/en/floater_toybox.xml | 5 ++ 7 files changed, 120 insertions(+), 42 deletions(-) (limited to 'indra') 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 CommandIndexMap; typedef std::vector 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 8ed828efd3..bbd7706a11 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -27,9 +27,12 @@ #include "linden_common.h" -#include "boost/foreach.hpp" +#include #include "lltoolbar.h" +#include "llcommandmanager.h" +#include "lltrans.h" + // uncomment this and remove the one in llui.cpp when there is an external reference to this translation unit // thanks, MSVC! //static LLDefaultChildRegistry::Register r1("toolbar"); @@ -74,6 +77,8 @@ LLToolBar::LLToolBar(const Params& p) 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) @@ -112,9 +117,7 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p) { // buttons always follow left and top, for all orientations button_p.follows.flags = FOLLOWS_LEFT|FOLLOWS_TOP; - button_p.fillFrom((mButtonType == BTNTYPE_ICONS_ONLY) - ? p.button_icon // icon only - : p.button_icon_and_text); // icon + text + button_p.fillFrom(mButtonParams[mButtonType]); LLRect button_rect(button_p.rect); { // remove any offset from button @@ -139,12 +142,58 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p) } } +bool LLToolBar::addCommand(LLCommand * command) +{ + // + // Init basic toolbar button params + // + + 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(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::updateLayoutAsNeeded() { if (!mNeedsLayout) return; 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 @@ -160,8 +209,8 @@ void LLToolBar::updateLayoutAsNeeded() std::vector buttons_in_row; - BOOST_FOREACH(LLToolBarButton* button, mButtons) - { + BOOST_FOREACH(LLToolBarButton* button, mButtons) + { S32 button_clamped_width = llclamp(button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth); S32 button_length = (orientation == LLLayoutStack::HORIZONTAL) ? button_clamped_width @@ -185,23 +234,23 @@ void LLToolBar::updateLayoutAsNeeded() if (orientation == LLLayoutStack::HORIZONTAL) { button->reshape(llclamp(button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth), max_row_girth); - } + } else // VERTICAL - { + { button->reshape(max_row_girth, button->getRect().getHeight()); } - } + } buttons_in_row.clear(); row_running_length = 0; cur_start = 0; cur_row += max_row_girth; max_row_girth = 0; - } + } LLRect button_rect; if (orientation == LLLayoutStack::HORIZONTAL) - { + { button_rect.setLeftTopAndSize(cur_start, panel_rect.mTop - cur_row, button_clamped_width, button->getRect().getHeight()); } else // VERTICAL @@ -209,7 +258,7 @@ void LLToolBar::updateLayoutAsNeeded() button_rect.setLeftTopAndSize(cur_row, panel_rect.mTop - cur_start, button_clamped_width, button->getRect().getHeight()); } button->setShape(button_rect); - + buttons_in_row.push_back(button); row_running_length += button_length; @@ -237,7 +286,7 @@ void LLToolBar::updateLayoutAsNeeded() translate(getRect().getWidth() - total_girth, 0); } reshape(total_girth, getRect().getHeight()); - } + } // recenter toolbar buttons mCenteringStack->updateLayout(); diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index 31729e32b4..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 @@ -107,6 +112,8 @@ 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&); @@ -129,6 +136,8 @@ private: mMaxButtonWidth; LLUIImagePtr mBackgroundImage; + + LLToolBarButton::Params mButtonParams[LLToolBarEnums::BTNTYPE_COUNT]; }; diff --git a/indra/newview/llfloatertoybox.cpp b/indra/newview/llfloatertoybox.cpp index b4fb2e45ab..eaaaeb3357 100644 --- a/indra/newview/llfloatertoybox.cpp +++ b/indra/newview/llfloatertoybox.cpp @@ -29,12 +29,15 @@ #include "llfloatertoybox.h" #include "llbutton.h" +#include "llcommandmanager.h" #include "llpanel.h" +#include "lltoolbar.h" LLFloaterToybox::LLFloaterToybox(const LLSD& key) : LLFloater(key) , mBtnRestoreDefaults(NULL) + , mToolBar(NULL) { mCommitCallbackRegistrar.add("Toybox.RestoreDefaults", boost::bind(&LLFloaterToybox::onBtnRestoreDefaults, this)); } @@ -48,23 +51,20 @@ BOOL LLFloaterToybox::postBuild() center(); mBtnRestoreDefaults = getChild("btn_restore_defaults"); + mToolBar = getChild("toybox_toolbar"); // // Create Buttons // -/* - LLToyboxButtons::load(); - for (size_t i = 0; i < LLToyboxButtons::buttonCount(); i++) - { - LLToyboxButton * button = LLToyboxButtons::get(i); + LLCommandManager& cmdMgr = LLCommandManager::instance(); - // Panel opacity depends on whether or not button position is established - LLPanel * buttonPanel = createPanelForButton(button); + for (U32 i = 0; i < cmdMgr.commandCount(); i++) + { + LLCommand * command = cmdMgr.getCommand(i); - mToolBar->add(buttonPanel); + mToolBar->addCommand(command); } -*/ return TRUE; } diff --git a/indra/newview/llfloatertoybox.h b/indra/newview/llfloatertoybox.h index bb9392a0e3..3574e060bf 100644 --- a/indra/newview/llfloatertoybox.h +++ b/indra/newview/llfloatertoybox.h @@ -31,10 +31,10 @@ class LLButton; +class LLToolBar; -class LLFloaterToybox -: public LLFloater +class LLFloaterToybox : public LLFloater { public: LLFloaterToybox(const LLSD& key); @@ -53,6 +53,7 @@ protected: public: LLButton * mBtnRestoreDefaults; + LLToolBar * mToolBar; }; #endif // LL_LLFLOATERTOYBOX_H diff --git a/indra/newview/skins/default/xui/en/floater_toybox.xml b/indra/newview/skins/default/xui/en/floater_toybox.xml index 1951497309..5f3a59d964 100644 --- a/indra/newview/skins/default/xui/en/floater_toybox.xml +++ b/indra/newview/skins/default/xui/en/floater_toybox.xml @@ -11,6 +11,7 @@ legacy_header_height="18" name="Toybox" open_centered="true" + save_rect="true" single_instance="true" title="Customize toolbars" width="658"> @@ -45,7 +46,11 @@