diff options
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/CMakeLists.txt | 2 | ||||
-rw-r--r-- | indra/llui/llcommandmanager.cpp | 138 | ||||
-rw-r--r-- | indra/llui/llcommandmanager.h | 97 | ||||
-rw-r--r-- | indra/llui/llfloaterreg.cpp | 11 | ||||
-rw-r--r-- | indra/llui/llfloaterreg.h | 1 | ||||
-rw-r--r-- | indra/llui/lltoolbar.cpp | 196 | ||||
-rw-r--r-- | indra/llui/lltoolbar.h | 27 | ||||
-rw-r--r-- | indra/llui/llui.cpp | 5 |
8 files changed, 414 insertions, 63 deletions
diff --git a/indra/llui/CMakeLists.txt b/indra/llui/CMakeLists.txt index d81801a0d2..4212812558 100644 --- a/indra/llui/CMakeLists.txt +++ b/indra/llui/CMakeLists.txt @@ -35,6 +35,7 @@ set(llui_SOURCE_FILES llcheckboxctrl.cpp llclipboard.cpp llcombobox.cpp + llcommandmanager.cpp llconsole.cpp llcontainerview.cpp llctrlselectioninterface.cpp @@ -133,6 +134,7 @@ set(llui_HEADER_FILES llcheckboxctrl.h llclipboard.h llcombobox.h + llcommandmanager.h llconsole.h llcontainerview.h llctrlselectioninterface.h diff --git a/indra/llui/llcommandmanager.cpp b/indra/llui/llcommandmanager.cpp new file mode 100644 index 0000000000..306b357d6a --- /dev/null +++ b/indra/llui/llcommandmanager.cpp @@ -0,0 +1,138 @@ +/** + * @file llcommandmanager.cpp + * @brief LLCommandManager class + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// A control that displays the name of the chosen item, which when +// clicked shows a scrolling box of options. + +#include "linden_common.h" + +#include "llcommandmanager.h" +#include "lldir.h" +#include "llerror.h" +#include "llxuiparser.h" + +#include <boost/foreach.hpp> + + +// +// LLCommand class +// + +LLCommand::Params::Params() + : function("function") + , icon("icon") + , label_ref("label_ref") + , name("name") + , param("param") + , tooltip_ref("tooltip_ref") +{ +} + +LLCommand::LLCommand(const LLCommand::Params& p) + : mFunction(p.function) + , mIcon(p.icon) + , mLabelRef(p.label_ref) + , mName(p.name) + , mParam(p.param) + , mTooltipRef(p.tooltip_ref) +{ +} + + +// +// LLCommandManager class +// + +LLCommandManager::LLCommandManager() +{ +} + +LLCommandManager::~LLCommandManager() +{ +} + +U32 LLCommandManager::count() const +{ + return mCommands.size(); +} + +LLCommand * LLCommandManager::getCommand(U32 commandIndex) +{ + return mCommands[commandIndex]; +} + +LLCommand * LLCommandManager::getCommand(const std::string& commandName) +{ + LLCommand * command_name_match = NULL; + + for (CommandVector::iterator it = mCommands.begin(); it != mCommands.end(); ++it) + { + LLCommand * command = *it; + + if (command->name() == commandName) + { + command_name_match = command; + break; + } + } + + return command_name_match; +} + +//static +bool LLCommandManager::load() +{ + LLCommandManager& mgr = LLCommandManager::instance(); + + std::string commands_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "commands.xml"); + + LLCommandManager::Params commandsParams; + + LLSimpleXUIParser parser; + + if (!parser.readXUI(commands_file, commandsParams)) + { + llerrs << "Unable to load xml file: " << commands_file << llendl; + return false; + } + + if (!commandsParams.validateBlock()) + { + llerrs << "Unable to validate commands param block from file: " << commands_file << llendl; + return false; + } + + BOOST_FOREACH(LLCommand::Params& commandParams, commandsParams.commands) + { + LLCommand * command = new LLCommand(commandParams); + + mgr.mCommands.push_back(command); + + llinfos << "Successfully loaded command: " << command->name() << llendl; + } + + return true; +} diff --git a/indra/llui/llcommandmanager.h b/indra/llui/llcommandmanager.h new file mode 100644 index 0000000000..4f3c9b2ada --- /dev/null +++ b/indra/llui/llcommandmanager.h @@ -0,0 +1,97 @@ +/** + * @file llcommandmanager.h + * @brief LLCommandManager class to hold commands + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_COMMANDMANAGER_H +#define LL_COMMANDMANAGER_H + +#include "llinitparam.h" +#include "llsingleton.h" + + +class LLCommand +{ +public: + struct Params : public LLInitParam::Block<Params> + { + Mandatory<std::string> function; + Mandatory<std::string> icon; + Mandatory<std::string> label_ref; + Mandatory<std::string> name; + Optional<std::string> param; + Mandatory<std::string> tooltip_ref; + + Params(); + }; + + LLCommand(const LLCommand::Params& p); + + const std::string& functionName() const { return mFunction; } + const std::string& icon() const { return mIcon; } + const std::string& labelRef() const { return mLabelRef; } + const std::string& name() const { return mName; } + const std::string& param() const { return mParam; } + const std::string& tooltipRef() const { return mTooltipRef; } + +private: + std::string mFunction; + std::string mIcon; + std::string mLabelRef; + std::string mName; + std::string mParam; + std::string mTooltipRef; +}; + + +class LLCommandManager +: public LLSingleton<LLCommandManager> +{ +public: + struct Params : public LLInitParam::Block<Params> + { + Multiple< LLCommand::Params, AtLeast<1> > commands; + + Params() + : commands("command") + { + } + }; + + LLCommandManager(); + ~LLCommandManager(); + + U32 count() const; + LLCommand * getCommand(U32 commandIndex); + LLCommand * getCommand(const std::string& commandName); + + static bool load(); + +private: + typedef std::vector<LLCommand *> CommandVector; + CommandVector mCommands; +}; + + +#endif // LL_COMMANDMANAGER_H diff --git a/indra/llui/llfloaterreg.cpp b/indra/llui/llfloaterreg.cpp index fc7dcfcc4e..bc740dde17 100644 --- a/indra/llui/llfloaterreg.cpp +++ b/indra/llui/llfloaterreg.cpp @@ -453,6 +453,17 @@ void LLFloaterReg::toggleFloaterInstance(const LLSD& sdname) } //static +void LLFloaterReg::toggleToolbarFloaterInstance(const LLSD& sdname) +{ + // Do some extra logic here for 3-state toolbar floater toggling madness :) + + LLSD key; + std::string name = sdname.asString(); + parse_name_key(name, key); + toggleInstance(name, key); +} + +//static bool LLFloaterReg::floaterInstanceVisible(const LLSD& sdname) { LLSD key; diff --git a/indra/llui/llfloaterreg.h b/indra/llui/llfloaterreg.h index a2027a77a0..6239d98a7d 100644 --- a/indra/llui/llfloaterreg.h +++ b/indra/llui/llfloaterreg.h @@ -127,6 +127,7 @@ public: static void showFloaterInstance(const LLSD& sdname); static void hideFloaterInstance(const LLSD& sdname); static void toggleFloaterInstance(const LLSD& sdname); + static void toggleToolbarFloaterInstance(const LLSD& sdname); static bool floaterInstanceVisible(const LLSD& sdname); static bool floaterInstanceMinimized(const LLSD& sdname); diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index 2c1e141ca7..1e8be93f17 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -30,9 +30,10 @@ #include "boost/foreach.hpp" #include "lltoolbar.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<LLToolBar> r1("toolbar"); - namespace LLToolBarEnums { LLLayoutStack::ELayoutOrientation getOrientation(SideType sideType) @@ -47,85 +48,88 @@ namespace LLToolBarEnums return orientation; } } - +using namespace LLToolBarEnums; LLToolBar::Params::Params() : button_display_mode("button_display_mode"), buttons("button"), - side("side") + side("side"), + 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), + background_image("background_image") {} LLToolBar::LLToolBar(const Params& p) : LLUICtrl(p), mButtonType(p.button_display_mode), mSideType(p.side), - mStack(NULL) + mWrap(p.wrap), + mNeedsLayout(false), + mCenterPanel(NULL), + mCenteringStack(NULL), + mMinWidth(p.min_width), + mMaxWidth(p.max_width), + mBackgroundImage(p.background_image) { } void LLToolBar::initFromParams(const LLToolBar::Params& p) { - LLLayoutStack::ELayoutOrientation orientation = LLToolBarEnums::getOrientation(p.side); + LLLayoutStack::ELayoutOrientation orientation = getOrientation(p.side); LLLayoutStack::Params centering_stack_p; + centering_stack_p.name = "centering_stack"; centering_stack_p.rect = getLocalRect(); centering_stack_p.follows.flags = FOLLOWS_ALL; centering_stack_p.orientation = orientation; - centering_stack_p.name = "centering_stack"; + mCenteringStack = LLUICtrlFactory::create<LLLayoutStack>(centering_stack_p); + addChild(mCenteringStack); + LLLayoutPanel::Params border_panel_p; border_panel_p.name = "border_panel"; border_panel_p.rect = getLocalRect(); border_panel_p.auto_resize = true; border_panel_p.user_resize = false; - - LLLayoutStack* centering_stack = LLUICtrlFactory::create<LLLayoutStack>(centering_stack_p); - addChild(centering_stack); + mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p)); + LLLayoutPanel::Params center_panel_p; center_panel_p.name = "center_panel"; center_panel_p.rect = getLocalRect(); center_panel_p.auto_resize = false; center_panel_p.user_resize = false; center_panel_p.fit_content = true; + mCenterPanel = LLUICtrlFactory::create<LLLayoutPanel>(center_panel_p); + mCenteringStack->addChild(mCenterPanel); + + mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p)); - centering_stack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p)); - LLLayoutPanel* center_panel = LLUICtrlFactory::create<LLLayoutPanel>(center_panel_p); - centering_stack->addChild(center_panel); - centering_stack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p)); - - LLLayoutStack::Params stack_p; - stack_p.rect = getLocalRect(); - stack_p.name = "button_stack"; - stack_p.orientation = orientation; - stack_p.follows.flags = (orientation == LLLayoutStack::HORIZONTAL) - ? (FOLLOWS_TOP|FOLLOWS_BOTTOM) // horizontal - : (FOLLOWS_LEFT|FOLLOWS_RIGHT); // vertical - - mStack = LLUICtrlFactory::create<LLLayoutStack>(stack_p); - center_panel->addChild(mStack); + addRow(); BOOST_FOREACH (LLToolBarButton::Params button_p, p.buttons) { - // remove any offset from button LLRect button_rect(button_p.rect); - - if (orientation == LLLayoutStack::HORIZONTAL) - { - button_rect.setOriginAndSize(0, 0, 0, getRect().getHeight()); + { // remove any offset from button + if (orientation == LLLayoutStack::HORIZONTAL) + { + button_rect.setOriginAndSize(0, 0, mMinWidth, getRect().getHeight()); + } + else // VERTICAL + { + button_rect.setOriginAndSize(0, 0, mMinWidth, button_rect.getHeight()); + } } - else // VERTICAL - { - button_rect.setOriginAndSize(0, 0, 0, button_rect.getHeight()); - } - button_p.follows.flags = FOLLOWS_NONE; - button_p.rect = button_rect; - button_p.chrome = true; - button_p.auto_resize = true; - LLToolBarButton* button = LLUICtrlFactory::create<LLToolBarButton>(button_p); + button_p.fillFrom((mButtonType == BTNTYPE_ICONS_ONLY) + ? p.button_icon // icon only + : p.button_icon_and_text); // icon + text - addButton(button); + mButtons.push_back(LLUICtrlFactory::create<LLToolBarButton>(button_p)); + mNeedsLayout = true; } updateLayout(); @@ -142,57 +146,127 @@ void LLToolBar::addButton(LLToolBarButton* buttonp) LLLayoutPanel* panel = LLUICtrlFactory::create<LLLayoutPanel>(panel_p); panel->addChild(buttonp); - mStack->addChild(panel); - mButtons.push_back(buttonp); + mStacks.back()->addChild(panel); } void LLToolBar::updateLayout() { - S32 total_width = 0; - S32 total_height = 0; - S32 max_width = getRect().getWidth(); - S32 max_height = getRect().getHeight(); + mCenteringStack->updateLayout(); + + if (!mNeedsLayout) return; + mNeedsLayout = false; + + { // clean up existing rows + BOOST_FOREACH(LLToolBarButton* button, mButtons) + { + if (button->getParent()) + { + button->getParent()->removeChild(button); + } + } + + BOOST_FOREACH(LLLayoutStack* stack, mStacks) + { + delete stack; + } + mStacks.clear(); + } + // 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) { - total_width += button->getRect().getWidth(); - total_height += button->getRect().getHeight(); + S32 button_width = button->getRect().getWidth(); + S32 button_height = button->getRect().getHeight(); + + if (getOrientation(mSideType) == LLLayoutStack::HORIZONTAL + && total_width + button_height > getRect().getWidth()) + { + addRow(); + total_width = 0; + } + 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); } - if (LLToolBarEnums::getOrientation(mSideType) == LLLayoutStack::HORIZONTAL) + if (getOrientation(mSideType) == LLLayoutStack::HORIZONTAL) { - mStack->reshape(total_width, mStack->getParent()->getRect().getHeight()); + BOOST_FOREACH(LLLayoutStack* stack, mStacks) + { + stack->reshape(max_total_width, stack->getParent()->getRect().getHeight()); + stack->updateLayout(); + } } else { - mStack->reshape(mStack->getParent()->getRect().getWidth(), total_height); - reshape(max_width, getRect().getHeight()); + BOOST_FOREACH(LLLayoutStack* stack, mStacks) + { + stack->reshape(stack->getParent()->getRect().getWidth(), max_total_height); + stack->updateLayout(); + } + + reshape(max_total_width, getRect().getHeight()); } } void LLToolBar::draw() { - //gl_rect_2d(getLocalRect(), LLColor4::blue, TRUE); + updateLayout(); + + { // draw background + LLRect bg_rect; + localRectToOtherView(mCenterPanel->getRect(),&bg_rect, this); + mBackgroundImage->draw(bg_rect); + } 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); + mNeedsLayout = true; +} + namespace LLInitParam { - void TypeValues<LLToolBarEnums::ButtonType>::declareValues() + void TypeValues<ButtonType>::declareValues() { - declare("icons_only", LLToolBarEnums::BTNTYPE_ICONS_ONLY); - declare("icons_with_text", LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT); + declare("icons_only", BTNTYPE_ICONS_ONLY); + declare("icons_with_text", BTNTYPE_ICONS_WITH_TEXT); } - void TypeValues<LLToolBarEnums::SideType>::declareValues() + void TypeValues<SideType>::declareValues() { - declare("none", LLToolBarEnums::SIDE_NONE); - declare("bottom", LLToolBarEnums::SIDE_BOTTOM); - declare("left", LLToolBarEnums::SIDE_LEFT); - declare("right", LLToolBarEnums::SIDE_RIGHT); - declare("top", LLToolBarEnums::SIDE_TOP); + declare("none", SIDE_NONE); + declare("bottom", SIDE_BOTTOM); + declare("left", SIDE_LEFT); + declare("right", SIDE_RIGHT); + declare("top", SIDE_TOP); } } diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index 60a848a6e3..3a593e42d9 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -87,14 +87,25 @@ public: struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> { Mandatory<LLToolBarEnums::ButtonType> button_display_mode; - Multiple<LLToolBarButton::Params> buttons; Mandatory<LLToolBarEnums::SideType> side; + Optional<LLToolBarButton::Params> button_icon, + button_icon_and_text; + + Optional<bool> wrap; + Optional<S32> min_width, + max_width; + // get rid of this + Multiple<LLToolBarButton::Params> buttons; + + Optional<LLUIImage*> background_image; + Params(); }; // virtuals void draw(); + void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); protected: friend class LLUICtrlFactory; @@ -105,10 +116,22 @@ protected: void updateLayout(); private: + void addRow(); + std::list<LLToolBarButton*> mButtons; LLToolBarEnums::ButtonType mButtonType; + LLLayoutStack* mCenteringStack; + LLLayoutStack* mWrapStack; + LLLayoutPanel* mCenterPanel; LLToolBarEnums::SideType mSideType; - LLLayoutStack* mStack; + + std::vector<LLLayoutStack*> mStacks; + bool mWrap; + bool mNeedsLayout; + S32 mMinWidth, + mMaxWidth; + + LLUIImagePtr mBackgroundImage; }; diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index 593354ee9b..1bc575438c 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -41,6 +41,7 @@ #include "llgl.h" // Project includes +#include "llcommandmanager.h" #include "llcontrol.h" #include "llui.h" #include "lluicolortable.h" @@ -1617,6 +1618,7 @@ void LLUI::initClass(const settings_map_t& settings, // Callbacks for associating controls with floater visibilty: reg.add("Floater.Toggle", boost::bind(&LLFloaterReg::toggleFloaterInstance, _2)); + reg.add("Floater.ToolbarToggle", boost::bind(&LLFloaterReg::toggleToolbarFloaterInstance, _2)); reg.add("Floater.Show", boost::bind(&LLFloaterReg::showFloaterInstance, _2)); reg.add("Floater.Hide", boost::bind(&LLFloaterReg::hideFloaterInstance, _2)); reg.add("Floater.InitToVisibilityControl", boost::bind(&LLFloaterReg::initUICtrlToFloaterVisibilityControl, _1, _2)); @@ -1635,6 +1637,9 @@ void LLUI::initClass(const settings_map_t& settings, // Used by menus along with Floater.Toggle to display visibility as a checkmark LLUICtrl::EnableCallbackRegistry::defaultRegistrar().add("Floater.Visible", boost::bind(&LLFloaterReg::floaterInstanceVisible, _2)); + + // Parse the master list of commands + LLCommandManager::load(); } void LLUI::cleanupClass() |