diff options
author | Merov Linden <merov@lindenlab.com> | 2011-10-09 15:52:45 -0700 |
---|---|---|
committer | Merov Linden <merov@lindenlab.com> | 2011-10-09 15:52:45 -0700 |
commit | ec5ea33c8113a63e956c195ccf051b2a03979be9 (patch) | |
tree | 035e4ac326165d48eb6dc5f454fa6bc65fcbc1b6 /indra/llui/lltoolbar.cpp | |
parent | 60c85dff83918876b23ab1ff1dfd336fc9dbc839 (diff) |
EXP-1300 : drop tool animation. First shot. Works but still a bit hacky and with some bugs (tools can be duplicated at times).
Diffstat (limited to 'indra/llui/lltoolbar.cpp')
-rw-r--r-- | indra/llui/lltoolbar.cpp | 83 |
1 files changed, 72 insertions, 11 deletions
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index 5f7afb07fc..6332b2674a 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -33,6 +33,7 @@ #include "llcommandmanager.h" #include "llmenugl.h" #include "lltrans.h" +#include "llinventory.h" // uncomment this and remove the one in llui.cpp when there is an external reference to this translation unit // thanks, MSVC! @@ -113,6 +114,8 @@ 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; + mDraggedCommand = LLCommandId::null; + mRank = 0; } LLToolBar::~LLToolBar() @@ -203,17 +206,24 @@ bool LLToolBar::addCommand(const LLCommandId& commandId, int rank) { LLCommand * command = LLCommandManager::instance().getCommand(commandId); if (!command) return false; - + llinfos << "Merov debug : addCommand, " << commandId.name() << ", " << commandId.uuid() << llendl; + // Create the button and do the things that don't need ordering LLToolBarButton* button = createButton(commandId); mButtonPanel->addChild(button); - mButtonMap.insert(std::make_pair(commandId, button)); + LLCommandId temp_command = commandId; + if (commandId.name() == "Drag Tool") + { + temp_command = LLCommandId("Drag Tool"); + } + mButtonMap.insert(std::make_pair(temp_command.uuid(), button)); + // Insert the command and button in the right place in their respective lists if ((rank >= mButtonCommands.size()) || (rank < 0)) { // In that case, back load - mButtonCommands.push_back(commandId); + mButtonCommands.push_back(temp_command); mButtons.push_back(button); } else @@ -228,7 +238,7 @@ bool LLToolBar::addCommand(const LLCommandId& commandId, int rank) rank--; } // ...then insert - mButtonCommands.insert(it_command,commandId); + mButtonCommands.insert(it_command,temp_command); mButtons.insert(it_button,button); } @@ -241,14 +251,20 @@ bool LLToolBar::removeCommand(const LLCommandId& commandId) { if (!hasCommand(commandId)) return false; + llinfos << "Merov debug : removeCommand, " << commandId.name() << ", " << commandId.uuid() << llendl; // First erase the map record - command_id_map::iterator it = mButtonMap.find(commandId); + LLCommandId temp_command = commandId; + if (commandId.name() == "Drag Tool") + { + temp_command = LLCommandId("Drag Tool"); + } + command_id_map::iterator it = mButtonMap.find(temp_command.uuid()); mButtonMap.erase(it); // Now iterate on the commands and buttons to identify the relevant records std::list<LLToolBarButton*>::iterator it_button = mButtons.begin(); command_id_list_t::iterator it_command = mButtonCommands.begin(); - while (*it_command != commandId) + while (*it_command != temp_command) { ++it_button; ++it_command; @@ -276,7 +292,12 @@ bool LLToolBar::hasCommand(const LLCommandId& commandId) const { if (commandId != LLCommandId::null) { - command_id_map::const_iterator it = mButtonMap.find(commandId); + LLCommandId temp_command = commandId; + if (commandId.name() == "Drag Tool") + { + temp_command = LLCommandId("Drag Tool"); + } + command_id_map::const_iterator it = mButtonMap.find(temp_command.uuid()); return (it != mButtonMap.end()); } @@ -289,7 +310,12 @@ bool LLToolBar::enableCommand(const LLCommandId& commandId, bool enabled) if (commandId != LLCommandId::null) { - command_id_map::iterator it = mButtonMap.find(commandId); + LLCommandId temp_command = commandId; + if (commandId.name() == "Drag Tool") + { + temp_command = LLCommandId("Drag Tool"); + } + command_id_map::iterator it = mButtonMap.find(temp_command.uuid()); if (it != mButtonMap.end()) { it->second->setEnabled(enabled); @@ -507,7 +533,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 + mPadBetween; @@ -592,6 +618,12 @@ void LLToolBar::draw() } } } + // HACK!!! + if (!mDragAndDropTarget) + { + removeCommand(mDraggedCommand); + mDraggedCommand = LLCommandId::null; + } updateLayoutAsNeeded(); // rect may have shifted during layout @@ -622,7 +654,12 @@ void LLToolBar::createButtons() LLToolBarButton* button = createButton(command_id); mButtons.push_back(button); mButtonPanel->addChild(button); - mButtonMap.insert(std::make_pair(command_id, button)); + LLCommandId temp_command = command_id; + if (command_id.name() == "Drag Tool") + { + temp_command = LLCommandId("Drag Tool"); + } + mButtonMap.insert(std::make_pair(temp_command.uuid(), button)); } mNeedsLayout = true; } @@ -713,7 +750,31 @@ BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, *accept = (handled ? ACCEPT_YES_SINGLE : ACCEPT_NO); // We'll use that flag to change the visual aspect of the toolbar target on draw() - mDragAndDropTarget = handled; + mDragAndDropTarget = false; + + // HACK!!! + if (!isReadOnly() && handled) + { + if (!drop) + { + LLInventoryItem* inv_item = (LLInventoryItem*)cargo_data; + LLAssetType::EType type = inv_item->getType(); + if (type == LLAssetType::AT_WIDGET) + { + mRank = getRankFromPosition(x, y); + mDraggedCommand = LLCommandId("Drag Tool",inv_item->getUUID()); + removeCommand(mDraggedCommand); + addCommand(mDraggedCommand,mRank); + mDragAndDropTarget = true; + } + } + else + { + removeCommand(mDraggedCommand); + mDraggedCommand = LLCommandId::null; + } + + } return handled; } |