summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp37
-rw-r--r--src/gui/outfitwindow.cpp60
-rw-r--r--src/gui/outfitwindow.h10
-rw-r--r--src/gui/widgets/itemcontainer.cpp25
4 files changed, 57 insertions, 75 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 9418d3e4c..a12163d60 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -33,6 +33,7 @@
#include "gui/widgets/window.h"
#include "configuration.h"
+#include "dragdrop.h"
#include "keydata.h"
#include "keyevent.h"
#include "keyinput.h"
@@ -433,14 +434,24 @@ void Gui::draw()
if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1))
&& mMouseCursors && mCustomCursor && mMouseCursorAlpha > 0.0f)
{
+ Graphics *g2 = static_cast<Graphics*>(mGraphics);
+ Item *const item = dragDrop.getItem();
+ if (item)
+ {
+ const Image *const image = item->getImage();
+ if (image)
+ {
+ const int tPosX = mouseX - (image->mBounds.w / 2);
+ const int tPosY = mouseY - (image->mBounds.h / 2);
+ g2->drawImage(image, tPosX, tPosY);
+ }
+ }
+
Image *const mouseCursor = mMouseCursors->get(mCursorType);
if (mouseCursor)
{
mouseCursor->setAlpha(mMouseCursorAlpha);
- static_cast<Graphics*>(mGraphics)->drawImage(
- mouseCursor,
- mouseX - 15,
- mouseY - 17);
+ g2->drawImage(mouseCursor, mouseX - 15, mouseY - 17);
}
}
@@ -598,6 +609,7 @@ void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
(*it)->mousePressed(mouseEvent);
break;
case gcn::MouseEvent::RELEASED:
+ case 100: // manual hack for release on target after drag
(*it)->mouseReleased(mouseEvent);
break;
case gcn::MouseEvent::WHEEL_MOVED_UP:
@@ -625,6 +637,9 @@ void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
widget = parent;
parent = swap->getParent();
+ if (type == gcn::MouseEvent::RELEASED)
+ dragDrop.clear();
+
// If a non modal focused widget has been reach
// and we have modal focus cancel the distribution.
if (mFocusHandler->getModalFocused()
@@ -734,17 +749,27 @@ void Gui::handleMouseReleased(const gcn::MouseInput &mouseInput)
gcn::Widget *sourceWidget = getMouseEventSource(
mouseInput.getX(), mouseInput.getY());
+ int sourceWidgetX, sourceWidgetY;
if (mFocusHandler->getDraggedWidget())
{
if (sourceWidget != mFocusHandler->getLastWidgetPressed())
mFocusHandler->setLastWidgetPressed(nullptr);
+ gcn::Widget *oldWidget = sourceWidget;
sourceWidget = mFocusHandler->getDraggedWidget();
+ if (oldWidget != sourceWidget)
+ {
+ oldWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
+ distributeMouseEvent(oldWidget,
+ 100,
+ mouseInput.getButton(),
+ mouseInput.getX(),
+ mouseInput.getY());
+
+ }
}
- int sourceWidgetX, sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
-
distributeMouseEvent(sourceWidget,
MouseEvent::RELEASED,
mouseInput.getButton(),
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp
index 2b9f57825..04320049c 100644
--- a/src/gui/outfitwindow.cpp
+++ b/src/gui/outfitwindow.cpp
@@ -23,6 +23,7 @@
#include "gui/outfitwindow.h"
#include "configuration.h"
+#include "dragdrop.h"
#include "emoteshortcut.h"
#include "equipment.h"
#include "game.h"
@@ -78,13 +79,9 @@ OutfitWindow::OutfitWindow():
keyName(mCurrentOutfit).c_str()))),
mBoxWidth(33),
mBoxHeight(33),
- mCursorPosX(0),
- mCursorPosY(0),
mGridWidth(4),
mGridHeight(4),
- mItemMoved(nullptr),
mItems(),
- mItemSelected(-1),
mAwayOutfit(0),
mBorderColor(getThemeColor(Theme::BORDER, 64)),
mBackgroundColor(getThemeColor(Theme::BACKGROUND, 32)),
@@ -374,6 +371,7 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
}
}
}
+/*
if (mItemMoved)
{
// Draw the item image being dragged by the cursor.
@@ -386,6 +384,7 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
g->drawImage(image, tPosX, tPosY);
}
}
+*/
BLOCK_END("OutfitWindow::draw")
}
@@ -394,7 +393,7 @@ void OutfitWindow::mouseDragged(gcn::MouseEvent &event)
{
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- if (!mItemMoved && mItemClicked)
+ if (dragDrop.isEmpty() && mItemClicked)
{
if (mCurrentOutfit < 0 || mCurrentOutfit
>= static_cast<signed int>(OUTFITS_COUNT))
@@ -423,17 +422,12 @@ void OutfitWindow::mouseDragged(gcn::MouseEvent &event)
{
Item *const item = inv->findItem(itemId, itemColor);
if (item)
- mItemMoved = item;
+ dragDrop.dragItem(item, DragDropSource::DRAGDROP_SOURCE_OUTFIT);
else
- mItemMoved = nullptr;
+ dragDrop.clear();
mItems[mCurrentOutfit][index] = -1;
}
}
- if (mItemMoved)
- {
- mCursorPosX = event.getX();
- mCursorPosY = event.getY();
- }
}
Window::mouseDragged(event);
}
@@ -457,19 +451,9 @@ void OutfitWindow::mousePressed(gcn::MouseEvent &event)
mMoved = false;
event.consume();
- // Stores the selected item if there is one.
- if (isItemSelected())
- {
- mItems[mCurrentOutfit][index] = mItemSelected;
- mItemColors[mCurrentOutfit][index] = mItemColorSelected;
-
- if (inventoryWindow)
- inventoryWindow->unselectItem();
- }
- else if (mItems[mCurrentOutfit][index])
- {
+ if (mItems[mCurrentOutfit][index])
mItemClicked = true;
- }
+
Window::mousePressed(event);
}
@@ -485,17 +469,21 @@ void OutfitWindow::mouseReleased(gcn::MouseEvent &event)
const int index = getIndexFromGrid(event.getX(), event.getY());
if (index == -1)
{
- mItemMoved = nullptr;
+ dragDrop.clear();
Window::mouseReleased(event);
return;
}
mMoved = false;
event.consume();
- if (mItemMoved)
+ if (!dragDrop.isEmpty())
{
- mItems[mCurrentOutfit][index] = mItemMoved->getId();
- mItemColors[mCurrentOutfit][index] = mItemMoved->getColor();
- mItemMoved = nullptr;
+ Item *const item = dragDrop.getItem();
+ if (item)
+ {
+ mItems[mCurrentOutfit][index] = item->getId();
+ mItemColors[mCurrentOutfit][index] = item->getColor();
+ dragDrop.clear();
+ }
}
if (mItemClicked)
mItemClicked = false;
@@ -665,20 +653,6 @@ void OutfitWindow::unwearAwayOutfit()
wearOutfit(OUTFITS_COUNT);
}
-void OutfitWindow::setItemSelected(const Item *const item)
-{
- if (item)
- {
- mItemSelected = item->getId();
- mItemColorSelected = item->getColor();
- }
- else
- {
- mItemSelected = -1;
- mItemColorSelected = 1;
- }
-}
-
void OutfitWindow::clearCurrentOutfit()
{
if (mCurrentOutfit < 0 || mCurrentOutfit
diff --git a/src/gui/outfitwindow.h b/src/gui/outfitwindow.h
index 7a5638f01..efb59346a 100644
--- a/src/gui/outfitwindow.h
+++ b/src/gui/outfitwindow.h
@@ -64,14 +64,6 @@ class OutfitWindow final : public Window,
void load(const bool oldConfig = false);
- void setItemSelected(const int itemId)
- { mItemSelected = itemId; }
-
- void setItemSelected(const Item *const item);
-
- bool isItemSelected() const A_WARN_UNUSED
- { return mItemSelected > 0; }
-
void wearOutfit(const int outfit, const bool unwearEmpty = true,
const bool select = false);
@@ -123,10 +115,8 @@ class OutfitWindow final : public Window,
int mCursorPosY;
int mGridWidth;
int mGridHeight;
- Item *mItemMoved;
int mItems[OUTFITS_COUNT + 1][OUTFIT_ITEM_COUNT];
- int mItemSelected;
int mAwayOutfit;
gcn::Color mBorderColor;
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index f65624eae..2246280fa 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -22,6 +22,7 @@
#include "gui/widgets/itemcontainer.h"
+#include "dragdrop.h"
#include "inventory.h"
#include "item.h"
#include "itemshortcut.h"
@@ -267,18 +268,8 @@ void ItemContainer::draw(gcn::Graphics *graphics)
{
if (mShowMatrix[itemIndex] == mSelectedIndex)
{
- if (mSelectionStatus == SEL_DRAGGING)
- {
- // Reposition the coords to that of the cursor.
- itemX = mDragPosX - (mBoxWidth / 2);
- itemY = mDragPosY - (mBoxHeight / 2);
- }
- else
- {
- // Draw selection border image.
- if (mSelImg)
- g->drawImage(mSelImg, itemX, itemY);
- }
+ if (mSelImg)
+ g->drawImage(mSelImg, itemX, itemY);
}
image->setAlpha(1.0f); // ensure the image if fully drawn...
g->drawImage(image, itemX + mPaddingItemX,
@@ -332,14 +323,16 @@ void ItemContainer::draw(gcn::Graphics *graphics)
void ItemContainer::selectNone()
{
+ dragDrop.clear();
+
setSelectedIndex(-1);
mSelectionStatus = SEL_NONE;
+/*
if (outfitWindow)
outfitWindow->setItemSelected(-1);
if (shopWindow)
shopWindow->setItemSelected(-1);
-// if (skillDialog)
-// skillDialog->setItemSelected(-1);
+*/
}
void ItemContainer::setSelectedIndex(const int newIndex)
@@ -407,10 +400,12 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
if (mSelectedIndex == index && mClicks != 2)
{
+ dragDrop.dragItem(item, DragDropSource::DRAGDROP_SOURCE_INVENTORY);
mSelectionStatus = SEL_DESELECTING;
}
else if (item && item->getId())
{
+ dragDrop.dragItem(item, DragDropSource::DRAGDROP_SOURCE_INVENTORY);
setSelectedIndex(index);
mSelectionStatus = SEL_SELECTING;
@@ -422,8 +417,6 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
}
if (dropShortcut)
dropShortcut->setItemSelected(item);
- if (item->isEquipment() && outfitWindow)
- outfitWindow->setItemSelected(item);
if (shopWindow)
shopWindow->setItemSelected(item->getId());
}