summaryrefslogtreecommitdiff
path: root/indra/newview/lltoolbarview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/lltoolbarview.cpp')
-rw-r--r--indra/newview/lltoolbarview.cpp130
1 files changed, 91 insertions, 39 deletions
diff --git a/indra/newview/lltoolbarview.cpp b/indra/newview/lltoolbarview.cpp
index 95ed603bbf..7977faeab7 100644
--- a/indra/newview/lltoolbarview.cpp
+++ b/indra/newview/lltoolbarview.cpp
@@ -41,7 +41,11 @@
LLToolBarView* gToolBarView = NULL;
static LLDefaultChildRegistry::Register<LLToolBarView> r("toolbar_view");
-bool LLToolBarView::sDragStarted = false;
+
+bool isToolDragged()
+{
+ return (LLToolDragAndDrop::getInstance()->getSource() == LLToolDragAndDrop::SOURCE_VIEWER);
+}
LLToolBarView::Toolbar::Toolbar()
: button_display_mode("button_display_mode"),
@@ -80,17 +84,17 @@ BOOL LLToolBarView::postBuild()
mToolbarRight = getChild<LLToolBar>("toolbar_right");
mToolbarBottom = getChild<LLToolBar>("toolbar_bottom");
- mToolbarLeft->setStartDragCallback(boost::bind(LLToolBarView::startDragItem,_1,_2,_3));
- mToolbarLeft->setHandleDragCallback(boost::bind(LLToolBarView::handleDragItem,_1,_2,_3,_4));
- mToolbarLeft->setHandleDropCallback(boost::bind(LLToolBarView::handleDrop,_1,_2,_3,_4));
+ mToolbarLeft->setStartDragCallback(boost::bind(LLToolBarView::startDragTool,_1,_2,_3));
+ mToolbarLeft->setHandleDragCallback(boost::bind(LLToolBarView::handleDragTool,_1,_2,_3,_4));
+ mToolbarLeft->setHandleDropCallback(boost::bind(LLToolBarView::handleDropTool,_1,_2,_3,_4));
- mToolbarRight->setStartDragCallback(boost::bind(LLToolBarView::startDragItem,_1,_2,_3));
- mToolbarRight->setHandleDragCallback(boost::bind(LLToolBarView::handleDragItem,_1,_2,_3,_4));
- mToolbarRight->setHandleDropCallback(boost::bind(LLToolBarView::handleDrop,_1,_2,_3,_4));
+ mToolbarRight->setStartDragCallback(boost::bind(LLToolBarView::startDragTool,_1,_2,_3));
+ mToolbarRight->setHandleDragCallback(boost::bind(LLToolBarView::handleDragTool,_1,_2,_3,_4));
+ mToolbarRight->setHandleDropCallback(boost::bind(LLToolBarView::handleDropTool,_1,_2,_3,_4));
- mToolbarBottom->setStartDragCallback(boost::bind(LLToolBarView::startDragItem,_1,_2,_3));
- mToolbarBottom->setHandleDragCallback(boost::bind(LLToolBarView::handleDragItem,_1,_2,_3,_4));
- mToolbarBottom->setHandleDropCallback(boost::bind(LLToolBarView::handleDrop,_1,_2,_3,_4));
+ mToolbarBottom->setStartDragCallback(boost::bind(LLToolBarView::startDragTool,_1,_2,_3));
+ mToolbarBottom->setHandleDragCallback(boost::bind(LLToolBarView::handleDragTool,_1,_2,_3,_4));
+ mToolbarBottom->setHandleDropCallback(boost::bind(LLToolBarView::handleDropTool,_1,_2,_3,_4));
return TRUE;
}
@@ -147,7 +151,7 @@ bool LLToolBarView::loadToolbars(bool force_default)
LLXMLNodePtr root;
if(!LLXMLNode::parseFile(toolbar_file, root, NULL))
{
- llerrs << "Unable to load toolbars from file: " << toolbar_file << llendl;
+ llwarns << "Unable to load toolbars from file: " << toolbar_file << llendl;
return false;
}
if(!root->hasName("toolbars"))
@@ -306,41 +310,45 @@ void LLToolBarView::draw()
mToolbarRight->localRectToOtherView(mToolbarRight->getLocalRect(), &right_rect, this);
}
- // 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);
+ // Draw drop zones if drop of a tool is active
+ if (isToolDragged())
+ {
+ LLColor4 drop_color = LLUIColorTable::instance().getColor( "ToolbarDropZoneColor" );
+ gl_rect_2d(bottom_rect, drop_color, TRUE);
+ gl_rect_2d(left_rect, drop_color, TRUE);
+ gl_rect_2d(right_rect, drop_color, TRUE);
+ }
LLUICtrl::draw();
}
// ----------------------------------------
-// Drag and Drop hacks (under construction)
+// Drag and Drop Handling
// ----------------------------------------
-void LLToolBarView::startDragItem( S32 x, S32 y, const LLUUID& uuid)
+void LLToolBarView::startDragTool( S32 x, S32 y, const LLUUID& uuid)
{
- //llinfos << "Merov debug: startDragItem() : x = " << x << ", y = " << y << llendl;
+ llinfos << "Merov debug: startDragTool() : x = " << x << ", y = " << y << ", uuid = " << uuid << llendl;
+ // Flag the tool dragging but don't start it yet
+ gToolBarView->mDragStarted = false;
+ gToolBarView->mDragCommand = LLCommandId::null;
+ gToolBarView->mDragRank = LLToolBar::RANK_NONE;
+ gToolBarView->mDragToolbar = NULL;
LLToolDragAndDrop::getInstance()->setDragStart( x, y );
- sDragStarted = false;
}
-BOOL LLToolBarView::handleDragItem( S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type)
+BOOL LLToolBarView::handleDragTool( S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type)
{
-// llinfos << "Merov debug: handleDragItem() : x = " << x << ", y = " << y << ", uuid = " << uuid << llendl;
if (LLToolDragAndDrop::getInstance()->isOverThreshold( x, y ))
{
- if (!sDragStarted)
+ if (!gToolBarView->mDragStarted)
{
+ llinfos << "Merov debug: handleDragTool() : x = " << x << ", y = " << y << ", uuid = " << uuid << llendl;
+ // Start the tool dragging:
+
+ // First, create the global drag and drop object
std::vector<EDragAndDropType> types;
uuid_vec_t cargo_ids;
types.push_back(DAD_WIDGET);
@@ -348,9 +356,35 @@ BOOL LLToolBarView::handleDragItem( S32 x, S32 y, const LLUUID& uuid, LLAssetTyp
gClipboard.setSourceObject(uuid,LLAssetType::AT_WIDGET);
LLToolDragAndDrop::ESource src = LLToolDragAndDrop::SOURCE_VIEWER;
LLUUID srcID;
- //llinfos << "Merov debug: handleDragItem() : beginMultiDrag()" << llendl;
LLToolDragAndDrop::getInstance()->beginMultiDrag(types, cargo_ids, src, srcID);
- sDragStarted = true;
+ llinfos << "Merov debug: beginMultiDrag() launched" << llendl;
+
+ // Second, check if the command is present in one of the 3 toolbars
+ // If it is, store the command, the toolbar and the rank in the toolbar and
+ // set a callback on end drag so that we reinsert the command if no drop happened
+ /*
+ gToolBarView->mDragCommand = LLCommandId(uuid);
+ if ((gToolBarView->mDragRank = gToolBarView->mToolbarLeft->removeCommand(gToolBarView->mDragCommand)) != LLToolBar::RANK_NONE)
+ {
+ gToolBarView->mDragToolbar = gToolBarView->mToolbarLeft;
+ }
+ else if ((gToolBarView->mDragRank = gToolBarView->mToolbarRight->removeCommand(gToolBarView->mDragCommand)) != LLToolBar::RANK_NONE)
+ {
+ gToolBarView->mDragToolbar = gToolBarView->mToolbarRight;
+ }
+ else if ((gToolBarView->mDragRank = gToolBarView->mToolbarBottom->removeCommand(gToolBarView->mDragCommand)) != LLToolBar::RANK_NONE)
+ {
+ gToolBarView->mDragToolbar = gToolBarView->mToolbarBottom;
+ }
+ if (gToolBarView->mDragRank != LLToolBar::RANK_NONE)
+ {
+ llinfos << "Merov debug: rank of dragged tool = " << gToolBarView->mDragRank << llendl;
+ LLToolDragAndDrop::getInstance()->setEndDragCallback(boost::bind(&LLToolBarView::onEndDrag, gToolBarView));
+ }
+ */
+
+ llinfos << "Merov debug: Drag started cleanly" << llendl;
+ gToolBarView->mDragStarted = true;
return TRUE;
}
else
@@ -362,15 +396,15 @@ BOOL LLToolBarView::handleDragItem( S32 x, S32 y, const LLUUID& uuid, LLAssetTyp
return FALSE;
}
-BOOL LLToolBarView::handleDrop( void* cargo_data, S32 x, S32 y, LLToolBar* toolbar)
+BOOL LLToolBarView::handleDropTool( void* cargo_data, S32 x, S32 y, LLToolBar* toolbar)
{
LLInventoryItem* inv_item = (LLInventoryItem*)cargo_data;
- //llinfos << "Merov debug : handleDrop. Drop " << inv_item->getUUID() << " named " << inv_item->getName() << " of type " << inv_item->getType() << llendl;
-
+ //llinfos << "Merov debug : handleDropTool. Drop " << inv_item->getUUID() << " named " << inv_item->getName() << " of type " << inv_item->getType() << llendl;
+
LLAssetType::EType type = inv_item->getType();
if (type == LLAssetType::AT_WIDGET)
{
- //llinfos << "Merov debug : handleDrop. Drop source is a widget -> drop it in place..." << llendl;
+ //llinfos << "Merov debug : handleDropTool. Drop source is a widget -> drop it in place..." << llendl;
// Get the command from its uuid
LLCommandManager& mgr = LLCommandManager::instance();
LLCommandId command_id(inv_item->getUUID());
@@ -385,9 +419,10 @@ BOOL LLToolBarView::handleDrop( void* cargo_data, S32 x, S32 y, LLToolBar* toolb
}
// Suppress the command from the toolbars (including the one it's dropped in,
// this will handle move position).
- gToolBarView->mToolbarLeft->removeCommand(command->id());
- gToolBarView->mToolbarRight->removeCommand(command->id());
- gToolBarView->mToolbarBottom->removeCommand(command->id());
+ llinfos << "Merov debug : handleDropTool, " << command_id.name() << ", " << command_id.uuid() << llendl;
+ gToolBarView->mToolbarLeft->removeCommand(command_id);
+ gToolBarView->mToolbarRight->removeCommand(command_id);
+ gToolBarView->mToolbarBottom->removeCommand(command_id);
// Now insert it in the toolbar at the detected rank
if (!toolbar->isReadOnly())
{
@@ -399,8 +434,25 @@ BOOL LLToolBarView::handleDrop( void* cargo_data, S32 x, S32 y, LLToolBar* toolb
llwarns << "Command couldn't be found in command manager" << llendl;
}
}
-
+ stopDragTool();
return TRUE;
}
+void LLToolBarView::stopDragTool()
+{
+ // Clear the saved command, toolbar and rank
+ gToolBarView->mDragStarted = false;
+ gToolBarView->mDragCommand = LLCommandId::null;
+ gToolBarView->mDragRank = LLToolBar::RANK_NONE;
+ gToolBarView->mDragToolbar = NULL;
+}
+void LLToolBarView::onEndDrag()
+{
+ // If there's a saved command, reinsert it in the saved toolbar
+ if (gToolBarView->mDragRank != LLToolBar::RANK_NONE)
+ {
+ gToolBarView->mDragToolbar->addCommand(gToolBarView->mDragCommand,gToolBarView->mDragRank);
+ }
+ stopDragTool();
+}