summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-06-01 13:12:54 +0300
committerAndrei Karas <akaras@inbox.ru>2013-06-01 13:12:54 +0300
commit14b6bc262cb761f7949f0d39606cb1b562d68cc7 (patch)
tree0fcc1c0c429a379193da17acb42a6f80d5bee4fc /src/gui
parentf45b10598c4a128510d7c469a6fe669587c01a3e (diff)
downloadmanaverse-14b6bc262cb761f7949f0d39606cb1b562d68cc7.tar.gz
manaverse-14b6bc262cb761f7949f0d39606cb1b562d68cc7.tar.bz2
manaverse-14b6bc262cb761f7949f0d39606cb1b562d68cc7.tar.xz
manaverse-14b6bc262cb761f7949f0d39606cb1b562d68cc7.zip
Add drag and drop to drops window.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/widgets/dropshortcutcontainer.cpp69
-rw-r--r--src/gui/widgets/dropshortcutcontainer.h1
-rw-r--r--src/gui/widgets/itemcontainer.cpp2
3 files changed, 21 insertions, 51 deletions
diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp
index d1c7b72c7..fcd708bdc 100644
--- a/src/gui/widgets/dropshortcutcontainer.cpp
+++ b/src/gui/widgets/dropshortcutcontainer.cpp
@@ -22,16 +22,17 @@
#include "gui/widgets/dropshortcutcontainer.h"
-#include "gui/inventorywindow.h"
-#include "gui/itempopup.h"
-#include "gui/viewport.h"
-
#include "client.h"
+#include "dragdrop.h"
#include "dropshortcut.h"
#include "keyboardconfig.h"
#include "localplayer.h"
#include "playerinfo.h"
+#include "gui/inventorywindow.h"
+#include "gui/itempopup.h"
+#include "gui/viewport.h"
+
#include "resources/image.h"
#include "resources/resourcemanager.h"
@@ -42,7 +43,6 @@
DropShortcutContainer::DropShortcutContainer():
ShortcutContainer(),
mItemClicked(false),
- mItemMoved(nullptr),
mItemPopup(new ItemPopup),
mEquipedColor(getThemeColor(Theme::ITEM_EQUIPPED)),
mEquipedColor2(getThemeColor(Theme::ITEM_EQUIPPED_OUTLINE)),
@@ -153,23 +153,6 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics)
}
}
}
-
- if (mItemMoved)
- {
- // Draw the item image being dragged by the cursor.
- const Image *const image = mItemMoved->getImage();
- if (image)
- {
- const int tPosX = mCursorPosX - (image->mBounds.w / 2);
- const int tPosY = mCursorPosY - (image->mBounds.h / 2);
- const std::string str = toString(mItemMoved->getQuantity());
-
- g->drawImage(image, tPosX, tPosY);
- font->drawString(g, str,
- tPosX + (mBoxWidth / 2 - font->getWidth(str)) / 2,
- tPosY + mBoxHeight - 14);
- }
- }
BLOCK_END("DropShortcutContainer::draw")
}
@@ -180,7 +163,7 @@ void DropShortcutContainer::mouseDragged(gcn::MouseEvent &event)
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- if (!mItemMoved && mItemClicked)
+ if (dragDrop.isEmpty() && mItemClicked)
{
const int index = getIndexFromGrid(event.getX(), event.getY());
@@ -201,14 +184,13 @@ void DropShortcutContainer::mouseDragged(gcn::MouseEvent &event)
if (item)
{
- mItemMoved = item;
+ dragDrop.dragItem(item, DragDropSource::DRAGDROP_SOURCE_DROP);
dropShortcut->removeItem(index);
}
- }
- if (mItemMoved)
- {
- mCursorPosX = event.getX();
- mCursorPosY = event.getY();
+ else
+ {
+ dragDrop.clear();
+ }
}
}
}
@@ -225,18 +207,7 @@ void DropShortcutContainer::mousePressed(gcn::MouseEvent &event)
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- // Stores the selected item if theirs one.
- if (dropShortcut->isItemSelected()
- && inventoryWindow->isWindowVisible())
- {
- dropShortcut->setItem(index);
- dropShortcut->setItemSelected(-1);
- inventoryWindow->unselectItem();
- }
- else if (dropShortcut->getItem(index))
- {
- mItemClicked = true;
- }
+ mItemClicked = true;
}
else if (event.getButton() == gcn::MouseEvent::RIGHT)
{
@@ -265,18 +236,20 @@ void DropShortcutContainer::mouseReleased(gcn::MouseEvent &event)
const int index = getIndexFromGrid(event.getX(), event.getY());
if (index == -1)
{
- mItemMoved = nullptr;
+ dragDrop.clear();
return;
}
- if (mItemMoved)
+ if (!dragDrop.isEmpty())
{
- dropShortcut->setItems(index, mItemMoved->getId(),
- mItemMoved->getColor());
- mItemMoved = nullptr;
+ Item *const item = dragDrop.getItem();
+ if (item)
+ {
+ dropShortcut->setItems(index, item->getId(), item->getColor());
+ dragDrop.clear();
+ }
}
- if (mItemClicked)
- mItemClicked = false;
+ mItemClicked = false;
}
}
diff --git a/src/gui/widgets/dropshortcutcontainer.h b/src/gui/widgets/dropshortcutcontainer.h
index c7dde87b9..a7930476d 100644
--- a/src/gui/widgets/dropshortcutcontainer.h
+++ b/src/gui/widgets/dropshortcutcontainer.h
@@ -81,7 +81,6 @@ class DropShortcutContainer final : public ShortcutContainer
private:
bool mItemClicked;
- Item *mItemMoved;
ItemPopup *mItemPopup;
gcn::Color mEquipedColor;
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 2246280fa..f591af19c 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -415,8 +415,6 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
if (itemShortcut[num])
itemShortcut[num]->setItemSelected(item);
}
- if (dropShortcut)
- dropShortcut->setItemSelected(item);
if (shopWindow)
shopWindow->setItemSelected(item->getId());
}