diff options
author | Leslie Linden <leslie@lindenlab.com> | 2011-10-04 12:17:01 -0700 |
---|---|---|
committer | Leslie Linden <leslie@lindenlab.com> | 2011-10-04 12:17:01 -0700 |
commit | fc6c3fbe4271dcd9b64bdfd417514dc97ad7dd75 (patch) | |
tree | bd09a20a2b4dd9384a92114eaeebe0d5bfac8e1e /indra/llui | |
parent | f3aac4c8ab45d52c4f038ad1a16768d9d8e0b201 (diff) | |
parent | 44e9fb446f3c92c3dfd9b5be8a3e02ec5a44ba00 (diff) |
Merge with latest
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/CMakeLists.txt | 5 | ||||
-rw-r--r-- | indra/llui/llclipboard.cpp | 6 | ||||
-rw-r--r-- | indra/llui/llclipboard.h | 9 | ||||
-rw-r--r-- | indra/llui/lltoolbar.cpp | 75 | ||||
-rw-r--r-- | indra/llui/lltoolbar.h | 36 | ||||
-rw-r--r-- | indra/llui/lltoolbarview.cpp | 324 | ||||
-rw-r--r-- | indra/llui/lltoolbarview.h | 100 | ||||
-rw-r--r-- | indra/llui/llui.h | 126 |
8 files changed, 222 insertions, 459 deletions
diff --git a/indra/llui/CMakeLists.txt b/indra/llui/CMakeLists.txt index 4212812558..dded8ab661 100644 --- a/indra/llui/CMakeLists.txt +++ b/indra/llui/CMakeLists.txt @@ -5,6 +5,7 @@ project(llui) include(00-Common) include(LLCommon) include(LLImage) +include(LLInventory) include(LLMath) include(LLMessage) include(LLRender) @@ -16,6 +17,7 @@ include(LLXUIXML) include_directories( ${LLCOMMON_INCLUDE_DIRS} ${LLIMAGE_INCLUDE_DIRS} + ${LLINVENTORY_INCLUDE_DIRS} ${LLMATH_INCLUDE_DIRS} ${LLMESSAGE_INCLUDE_DIRS} ${LLRENDER_INCLUDE_DIRS} @@ -101,7 +103,6 @@ set(llui_SOURCE_FILES lltransutil.cpp lltoggleablemenu.cpp lltoolbar.cpp - lltoolbarview.cpp lltooltip.cpp llui.cpp lluicolortable.cpp @@ -205,7 +206,6 @@ set(llui_HEADER_FILES lltimectrl.h lltoggleablemenu.h lltoolbar.h - lltoolbarview.h lltooltip.h lltransutil.h lluicolortable.h @@ -251,6 +251,7 @@ target_link_libraries(llui ${LLRENDER_LIBRARIES} ${LLWINDOW_LIBRARIES} ${LLIMAGE_LIBRARIES} + ${LLINVENTORY_LIBRARIES} ${LLVFS_LIBRARIES} # ugh, just for LLDir ${LLXUIXML_LIBRARIES} ${LLXML_LIBRARIES} diff --git a/indra/llui/llclipboard.cpp b/indra/llui/llclipboard.cpp index 984c4ec5fb..6910b962a1 100644 --- a/indra/llui/llclipboard.cpp +++ b/indra/llui/llclipboard.cpp @@ -40,6 +40,7 @@ LLClipboard gClipboard; LLClipboard::LLClipboard() { + mSourceItem = NULL; } @@ -134,3 +135,8 @@ BOOL LLClipboard::canPastePrimaryString() const { return LLView::getWindow()->isPrimaryTextAvailable(); } + +void LLClipboard::setSourceObject(const LLUUID& source_id, LLAssetType::EType type) +{ + mSourceItem = new LLInventoryObject (source_id, LLUUID::null, type, ""); +} diff --git a/indra/llui/llclipboard.h b/indra/llui/llclipboard.h index 24cb46c3f4..9371b94284 100644 --- a/indra/llui/llclipboard.h +++ b/indra/llui/llclipboard.h @@ -30,6 +30,8 @@ #include "llstring.h" #include "lluuid.h" +#include "stdenums.h" +#include "llinventory.h" class LLClipboard @@ -52,9 +54,14 @@ public: BOOL canPastePrimaryString() const; const LLWString& getPastePrimaryWString(LLUUID* source_id = NULL); + // Support clipboard for object known only by their uuid and asset type + void setSourceObject(const LLUUID& source_id, LLAssetType::EType type); + const LLInventoryObject* getSourceObject() { return mSourceItem; } + private: - LLUUID mSourceID; + LLUUID mSourceID; LLWString mString; + LLInventoryObject* mSourceItem; }; diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index c0058d534d..efa077ffa1 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -33,7 +33,6 @@ #include "llcommandmanager.h" #include "llmenugl.h" #include "lltrans.h" -#include "lltoolbarview.h" // uncomment this and remove the one in llui.cpp when there is an external reference to this translation unit // thanks, MSVC! @@ -108,6 +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::generateNewID(p.name); } LLToolBar::~LLToolBar() @@ -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 @@ -528,6 +528,8 @@ LLToolBarButton* LLToolBar::createButton(const LLCommandId& id) cbParam.function_name = commandp->functionName(); cbParam.parameter = commandp->parameter(); button->setCommitCallback(cbParam); + button->setStartDragCallback(mStartDragItemCallback); + button->setHandleDragCallback(mHandleDragItemCallback); } button->setCommandId(id); @@ -535,20 +537,41 @@ LLToolBarButton* LLToolBar::createButton(const LLCommandId& id) } -// -// LLToolBarButton -// +BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, + EDragAndDropType cargo_type, + void* cargo_data, + EAcceptance* accept, + std::string& tooltip_msg) +{ + llinfos << "Merov debug : handleDragAndDrop. drop = " << drop << ", tooltip = " << tooltip_msg << llendl; + // If we have a drop callback, that means that we can handle the drop + BOOL handled = (mHandleDropCallback ? TRUE : FALSE); + + // if drop, time to call the drop callback to get the operation done + if (handled && drop) + { + handled = mHandleDropCallback(cargo_type,cargo_data,mUUID); + } + + // We accept multi drop by default + *accept = (handled ? ACCEPT_YES_MULTI : ACCEPT_NO); + + // We'll use that flag to change the visual aspect of the target on draw() + mDragAndDropTarget = handled; + + return handled; +} 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("") -{} - +{ + mUUID = LLUUID::generateNewID(p.name); +} BOOL LLToolBarButton::handleMouseDown(S32 x, S32 y, MASK mask) { @@ -559,22 +582,26 @@ BOOL LLToolBarButton::handleMouseDown(S32 x, S32 y, MASK mask) BOOL LLToolBarButton::handleHover(S32 x, S32 y, MASK mask) { - if (hasMouseCapture()) +// llinfos << "Merov debug: handleHover, x = " << x << ", y = " << y << ", mouse = " << hasMouseCapture() << llendl; + BOOL handled = FALSE; + + if (hasMouseCapture() && mStartDragItemCallback && mHandleDragItemCallback) { - S32 dist_squared = (x - mMouseDownX) * (x - mMouseDownX) + (y - mMouseDownY) * (y - mMouseDownY); - S32 threshold = LLUI::sSettingGroups["config"]->getS32("DragAndDropDistanceThreshold"); - S32 threshold_squared = threshold * threshold; - if (dist_squared > threshold_squared) + if (!mIsDragged) { - // start drag and drop - LLToolBarView* view = getParentByType<LLToolBarView>(); - LLToolBar* bar = getParentByType<LLToolBar>(); - if (view) + mStartDragItemCallback(x,y,mUUID); + mIsDragged = true; + handled = TRUE; + } + else { - //view->startDrag(bar->createButton(mId)); - //setVisible(FALSE); + handled = mHandleDragItemCallback(x,y,mUUID,LLAssetType::AT_WIDGET); } } + else + { + handled = LLButton::handleHover(x, y, mask); } - return LLButton::handleHover(x, y, mask); + return handled; } + diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index 5d64630fa6..407cbde7d2 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -33,7 +33,11 @@ #include "lllayoutstack.h" #include "lluictrl.h" #include "llcommandmanager.h" +#include "llassettype.h" +typedef boost::function<void (S32 x, S32 y, const LLUUID& uuid)> startdrag_callback_t; +typedef boost::function<BOOL (S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type)> handledrag_callback_t; +typedef boost::function<BOOL (EDragAndDropType type, void* data, const LLUUID& uuid)> handledrop_callback_t; class LLToolBarButton : public LLButton { @@ -41,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) {} @@ -58,13 +60,19 @@ public: BOOL handleMouseDown(S32 x, S32 y, MASK mask); BOOL handleHover(S32 x, S32 y, MASK mask); void setCommandId(const LLCommandId& id) { mId = id; } + + void setStartDragCallback(startdrag_callback_t cb) { mStartDragItemCallback = cb; } + void setHandleDragCallback(handledrag_callback_t cb) { mHandleDragItemCallback = cb; } private: LLCommandId mId; S32 mMouseDownX; S32 mMouseDownY; - S32 mMinWidth; - S32 mMaxWidth; + LLUI::Range<S32> mWidthRange; S32 mDesiredHeight; + bool mIsDragged; + startdrag_callback_t mStartDragItemCallback; + handledrag_callback_t mHandleDragItemCallback; + LLUUID mUUID; }; @@ -108,7 +116,6 @@ class LLToolBar : public LLUICtrl { public: - struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> { Mandatory<LLToolBarEnums::ButtonType> button_display_mode; @@ -137,10 +144,18 @@ public: void draw(); void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); BOOL handleRightMouseDown(S32 x, S32 y, MASK mask); + virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, + EDragAndDropType cargo_type, + 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); + void setStartDragCallback(startdrag_callback_t cb) { mStartDragItemCallback = cb; } + void setHandleDragCallback(handledrag_callback_t cb) { mHandleDragItemCallback = cb; } + void setHandleDropCallback(handledrop_callback_t cb) { mHandleDropCallback = cb; } LLToolBarButton* createButton(const LLCommandId& id); @@ -150,6 +165,10 @@ protected: ~LLToolBar(); void initFromParams(const Params&); + startdrag_callback_t mStartDragItemCallback; + handledrag_callback_t mHandleDragItemCallback; + handledrop_callback_t mHandleDropCallback; + bool mDragAndDropTarget; public: // Methods used in loading and saving toolbar settings @@ -166,6 +185,7 @@ private: BOOL isSettingChecked(const LLSD& userdata); void onSettingEnable(const LLSD& userdata); + LLUUID mUUID; const bool mReadOnly; std::list<LLToolBarButton*> mButtons; diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp deleted file mode 100644 index 12247519ad..0000000000 --- a/indra/llui/lltoolbarview.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/** - * @file lltoolbarview.cpp - * @author Merov Linden - * @brief User customizable toolbar class - * - * $LicenseInfo:firstyear=2011&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$ - */ - -#include "linden_common.h" - -#include "lltoolbarview.h" - -#include "lldir.h" -#include "llxmlnode.h" -#include "lltoolbar.h" -#include "llbutton.h" - -#include <boost/foreach.hpp> - -LLToolBarView* gToolBarView = NULL; - -static LLDefaultChildRegistry::Register<LLToolBarView> r("toolbar_view"); - -LLToolBarView::Toolbar::Toolbar() -: button_display_mode("button_display_mode"), - commands("command") -{} - -LLToolBarView::ToolbarSet::ToolbarSet() -: left_toolbar("left_toolbar"), - right_toolbar("right_toolbar"), - bottom_toolbar("bottom_toolbar") -{} - - -LLToolBarView::LLToolBarView(const LLToolBarView::Params& p) -: LLUICtrl(p), - mToolbarLeft(NULL), - mToolbarRight(NULL), - mToolbarBottom(NULL) -{ -} - -void LLToolBarView::initFromParams(const LLToolBarView::Params& p) -{ - // Initialize the base object - LLUICtrl::initFromParams(p); -} - -LLToolBarView::~LLToolBarView() -{ - saveToolbars(); -} - -BOOL LLToolBarView::postBuild() -{ - mToolbarLeft = getChild<LLToolBar>("toolbar_left"); - mToolbarRight = getChild<LLToolBar>("toolbar_right"); - mToolbarBottom = getChild<LLToolBar>("toolbar_bottom"); - - return TRUE; -} - -bool LLToolBarView::hasCommand(const LLCommandId& commandId) const -{ - bool has_command = false; - if (mToolbarLeft && !has_command) - { - has_command = mToolbarLeft->hasCommand(commandId); - } - if (mToolbarRight && !has_command) - { - has_command = mToolbarRight->hasCommand(commandId); - } - if (mToolbarBottom && !has_command) - { - has_command = mToolbarBottom->hasCommand(commandId); - } - return has_command; -} - -bool LLToolBarView::addCommand(const LLCommandId& command, LLToolBar* toolbar) -{ - LLCommandManager& mgr = LLCommandManager::instance(); - if (mgr.getCommand(command)) - { - toolbar->addCommand(command); - } - else - { - llwarns << "Toolbars creation : the command " << command.name() << " cannot be found in the command manager" << llendl; - return false; - } - return true; -} - -bool LLToolBarView::loadToolbars(bool force_default) -{ - LLToolBarView::ToolbarSet toolbar_set; - - // Load the toolbars.xml file - std::string toolbar_file = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "toolbars.xml"); - if (force_default) - { - toolbar_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "toolbars.xml"); - } - else if (!gDirUtilp->fileExists(toolbar_file)) - { - llwarns << "User toolbars def not found -> use default" << llendl; - toolbar_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "toolbars.xml"); - } - - LLXMLNodePtr root; - if(!LLXMLNode::parseFile(toolbar_file, root, NULL)) - { - llerrs << "Unable to load toolbars from file: " << toolbar_file << llendl; - return false; - } - if(!root->hasName("toolbars")) - { - llwarns << toolbar_file << " is not a valid toolbars definition file" << llendl; - return false; - } - - // Parse the toolbar settings - LLXUIParser parser; - parser.readXUI(root, toolbar_set, toolbar_file); - if (!toolbar_set.validateBlock()) - { - llerrs << "Unable to validate toolbars from file: " << toolbar_file << llendl; - return false; - } - - // Clear the toolbars now before adding the loaded commands and settings - if (mToolbarLeft) - { - mToolbarLeft->clearCommandsList(); - } - if (mToolbarRight) - { - mToolbarRight->clearCommandsList(); - } - if (mToolbarBottom) - { - mToolbarBottom->clearCommandsList(); - } - - // Add commands to each toolbar - if (toolbar_set.left_toolbar.isProvided() && mToolbarLeft) - { - 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)); - } - BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.left_toolbar.commands) - { - addCommand(LLCommandId(command),mToolbarLeft); - } - } - if (toolbar_set.right_toolbar.isProvided() && mToolbarRight) - { - 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)); - } - BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.right_toolbar.commands) - { - addCommand(LLCommandId(command),mToolbarRight); - } - } - if (toolbar_set.bottom_toolbar.isProvided() && mToolbarBottom) - { - 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)); - } - BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.bottom_toolbar.commands) - { - addCommand(LLCommandId(command),mToolbarBottom); - } - } - return true; -} - -//static -bool LLToolBarView::loadDefaultToolbars() -{ - bool retval = false; - - if (gToolBarView) - { - retval = gToolBarView->loadToolbars(true); - } - - return retval; -} - -void LLToolBarView::saveToolbars() const -{ - // Build the parameter tree from the toolbar data - LLToolBarView::ToolbarSet toolbar_set; - if (mToolbarLeft) - { - toolbar_set.left_toolbar.button_display_mode = (int)(mToolbarLeft->getButtonType()); - addToToolset(mToolbarLeft->getCommandsList(),toolbar_set.left_toolbar); - } - if (mToolbarRight) - { - toolbar_set.right_toolbar.button_display_mode = (int)(mToolbarRight->getButtonType()); - addToToolset(mToolbarRight->getCommandsList(),toolbar_set.right_toolbar); - } - if (mToolbarBottom) - { - toolbar_set.bottom_toolbar.button_display_mode = (int)(mToolbarBottom->getButtonType()); - addToToolset(mToolbarBottom->getCommandsList(),toolbar_set.bottom_toolbar); - } - - // Serialize the parameter tree - LLXMLNodePtr output_node = new LLXMLNode("toolbars", false); - LLXUIParser parser; - parser.writeXUI(output_node, toolbar_set); - - // Write the resulting XML to file - if(!output_node->isNull()) - { - const std::string& filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "toolbars.xml"); - LLFILE *fp = LLFile::fopen(filename, "w"); - if (fp != NULL) - { - LLXMLNode::writeHeaderToFile(fp); - output_node->writeToFile(fp); - fclose(fp); - } - } -} - -// Enumerate the commands in command_list and add them as Params to the toolbar -void LLToolBarView::addToToolset(command_id_list_t& command_list, Toolbar& toolbar) const -{ - for (command_id_list_t::const_iterator it = command_list.begin(); - it != command_list.end(); - ++it) - { - LLCommandId::Params command; - command.name = it->name(); - toolbar.commands.add(command); - } -} - -void LLToolBarView::draw() -{ - static bool debug_print = true; - static S32 old_width = 0; - static S32 old_height = 0; - - //LLPanel* sizer_left = getChild<LLPanel>("sizer_left"); - - LLRect bottom_rect, left_rect, right_rect; - - if (mToolbarBottom) - { - mToolbarBottom->getParent()->reshape(mToolbarBottom->getParent()->getRect().getWidth(), mToolbarBottom->getRect().getHeight()); - mToolbarBottom->localRectToOtherView(mToolbarBottom->getLocalRect(), &bottom_rect, this); - } - if (mToolbarLeft) - { - mToolbarLeft->getParent()->reshape(mToolbarLeft->getRect().getWidth(), mToolbarLeft->getParent()->getRect().getHeight()); - mToolbarLeft->localRectToOtherView(mToolbarLeft->getLocalRect(), &left_rect, this); - } - if (mToolbarRight) - { - mToolbarRight->getParent()->reshape(mToolbarRight->getRect().getWidth(), mToolbarRight->getParent()->getRect().getHeight()); - mToolbarRight->localRectToOtherView(mToolbarRight->getLocalRect(), &right_rect, this); - } - - if ((old_width != getRect().getWidth()) || (old_height != getRect().getHeight())) - debug_print = true; - if (debug_print) - { - LLRect ctrl_rect = getRect(); - llinfos << "Merov debug : draw control rect = " << ctrl_rect.mLeft << ", " << ctrl_rect.mTop << ", " << ctrl_rect.mRight << ", " << ctrl_rect.mBottom << llendl; - llinfos << "Merov debug : draw bottom rect = " << bottom_rect.mLeft << ", " << bottom_rect.mTop << ", " << bottom_rect.mRight << ", " << bottom_rect.mBottom << llendl; - llinfos << "Merov debug : draw left rect = " << left_rect.mLeft << ", " << left_rect.mTop << ", " << left_rect.mRight << ", " << left_rect.mBottom << llendl; - llinfos << "Merov debug : draw right rect = " << right_rect.mLeft << ", " << right_rect.mTop << ", " << right_rect.mRight << ", " << right_rect.mBottom << llendl; - old_width = ctrl_rect.getWidth(); - old_height = ctrl_rect.getHeight(); - debug_print = false; - } - // Debug draw - LLColor4 back_color = LLColor4::blue; - LLColor4 back_color_vert = LLColor4::red; - LLColor4 back_color_hori = LLColor4::yellow; - back_color[VALPHA] = 0.5f; - back_color_hori[VALPHA] = 0.5f; - back_color_vert[VALPHA] = 0.5f; - //gl_rect_2d(getLocalRect(), back_color, TRUE); - //gl_rect_2d(bottom_rect, back_color_hori, TRUE); - //gl_rect_2d(left_rect, back_color_vert, TRUE); - //gl_rect_2d(right_rect, back_color_vert, TRUE); - - LLUICtrl::draw(); -} diff --git a/indra/llui/lltoolbarview.h b/indra/llui/lltoolbarview.h deleted file mode 100644 index 20525a22ac..0000000000 --- a/indra/llui/lltoolbarview.h +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file lltoolbarview.h - * @author Merov Linden - * @brief User customizable toolbar class - * - * $LicenseInfo:firstyear=2011&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_LLTOOLBARVIEW_H -#define LL_LLTOOLBARVIEW_H - -#include "lluictrl.h" -#include "lltoolbar.h" -#include "llcommandmanager.h" - -class LLUICtrlFactory; - -// Parent of all LLToolBar - -class LLToolBarView : public LLUICtrl -{ -public: - // Xui structure of the toolbar panel - struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> {}; - - // Note: valid children for LLToolBarView are stored in this registry - typedef LLDefaultChildRegistry child_registry_t; - - // Xml structure of the toolbars.xml setting - // Those live in a toolbars.xml found in app_settings (for the default) and in - // the user folder for the user specific (saved) settings - struct Toolbar : public LLInitParam::Block<Toolbar> - { - Mandatory<U32> button_display_mode; - Multiple<LLCommandId::Params> commands; - Toolbar(); - }; - struct ToolbarSet : public LLInitParam::Block<ToolbarSet> - { - Optional<Toolbar> left_toolbar, - right_toolbar, - bottom_toolbar; - ToolbarSet(); - }; - - // Derived methods - virtual ~LLToolBarView(); - virtual BOOL postBuild(); - virtual void draw(); - // Toolbar view interface with the rest of the world - // Checks if the commandId is being used somewhere in one of the toolbars - bool hasCommand(const LLCommandId& commandId) const; - // Loads the toolbars from the existing user or default settings - bool loadToolbars(bool force_default = false); // return false if load fails - - static bool loadDefaultToolbars(); - -protected: - friend class LLUICtrlFactory; - LLToolBarView(const Params&); - - void initFromParams(const Params&); - -private: - void saveToolbars() const; - bool addCommand(const LLCommandId& commandId, LLToolBar* toolbar); - void addToToolset(command_id_list_t& command_list, Toolbar& toolbar) const; - - // Pointers to the toolbars handled by the toolbar view - LLToolBar* mToolbarLeft; - LLToolBar* mToolbarRight; - LLToolBar* mToolbarBottom; - bool mDragging; - LLToolBarButton* mDragButton; - S32 mMouseX; - S32 mMouseY; -}; - -extern LLToolBarView* gToolBarView; - -#endif // LL_LLTOOLBARVIEW_H diff --git a/indra/llui/llui.h b/indra/llui/llui.h index 3afb7c65a9..8cec1a16f4 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> + { + typename 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; |