diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-06-02 22:14:54 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-06-02 22:14:54 +0300 |
commit | 65b614a0d142e229206fbde22a25f4a3b20b1dbc (patch) | |
tree | cb1f90dbbc8aedd3ef2dd7e2269a08b115d9fc7b /src | |
parent | bead0d26642bbc0c5e570306c226676c66d18b86 (diff) | |
download | manaverse-65b614a0d142e229206fbde22a25f4a3b20b1dbc.tar.gz manaverse-65b614a0d142e229206fbde22a25f4a3b20b1dbc.tar.bz2 manaverse-65b614a0d142e229206fbde22a25f4a3b20b1dbc.tar.xz manaverse-65b614a0d142e229206fbde22a25f4a3b20b1dbc.zip |
In drag and drop use ints and images but not pointer to item.
Diffstat (limited to 'src')
-rw-r--r-- | src/dragdrop.h | 88 | ||||
-rw-r--r-- | src/gui/gui.cpp | 14 | ||||
-rw-r--r-- | src/gui/outfitwindow.cpp | 19 | ||||
-rw-r--r-- | src/gui/widgets/dropshortcutcontainer.cpp | 18 |
4 files changed, 92 insertions, 47 deletions
diff --git a/src/dragdrop.h b/src/dragdrop.h index a2c94facf..6d45a69e1 100644 --- a/src/dragdrop.h +++ b/src/dragdrop.h @@ -23,6 +23,8 @@ #include "item.h" +#include "resources/image.h" + #include "localconsts.h" enum DragDropSource @@ -44,27 +46,64 @@ class DragDrop { public: DragDrop(Item *const item, const DragDropSource source) : - mItem(item), - mSelItem(nullptr), + mItem(item ? item->getId() : 0), + mItemColor(item ? item->getColor() : 1), + mItemImage(item ? item->getImage() : nullptr), + mSelItem(0), + mSelItemColor(1), mSource(source) { + if (mItemImage) + mItemImage->incRef(); + } + + ~DragDrop() + { + if (mItemImage) + mItemImage->decRef(); } - Item *getItem() + int getItem() { return mItem; } + int getItemColor() + { return mItemColor; } + + Image *getItemImage() + { return mItemImage; } + DragDropSource getSource() const { return mSource; } void dragItem(Item *const item, const DragDropSource source) { - mItem = item; + if (mItemImage) + mItemImage->decRef(); + + if (item) + { + mItem = item->getId(); + mItemColor = item->getColor(); + mItemImage = item->getImage(); + if (mItemImage) + mItemImage->incRef(); + } + else + { + mItem = 0; + mItemColor = 1; + mItemImage = nullptr; + } mSource = source; } void clear() { - mItem = nullptr; + if (mItemImage) + mItemImage->decRef(); + mItem = 0; + mItemColor = 1; + mItemImage = nullptr; mSource = DRAGDROP_SOURCE_EMPTY; } @@ -72,25 +111,44 @@ class DragDrop { return mSource == DRAGDROP_SOURCE_EMPTY; } void select(Item *const item) - { mSelItem = item; } + { + if (item) + { + mSelItem = item->getId(); + mSelItemColor = item->getColor(); + } + else + { + mSelItem = 0; + mSelItemColor = 1; + } + } void deselect() - { mSelItem = nullptr; } + { + mSelItem = 0; + mSelItemColor = 1; + } - Item *getSelected() + int getSelected() { return mSelItem; } - void clearItem(const Item *const item) + int getSelectedColor() + { return mSelItemColor; } + + bool isSelected() + { return mSelItem > 0; } + + void clearItem(const Item *const item A_UNUSED) { - if (mItem == item) - clear(); - if (mSelItem == item) - mSelItem = nullptr; } private: - Item *mItem; - Item *mSelItem; + int mItem; + uint8_t mItemColor; + Image *mItemImage; + int mSelItem; + uint8_t mSelItemColor; DragDropSource mSource; }; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index a12163d60..95a94900a 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -435,16 +435,12 @@ void Gui::draw() && mMouseCursors && mCustomCursor && mMouseCursorAlpha > 0.0f) { Graphics *g2 = static_cast<Graphics*>(mGraphics); - Item *const item = dragDrop.getItem(); - if (item) + const Image *const image = dragDrop.getItemImage(); + if (image) { - 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); - } + 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); diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index b00ab69b9..45ee8465f 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -443,11 +443,10 @@ void OutfitWindow::mousePressed(gcn::MouseEvent &event) } else { - Item *const selected = dragDrop.getSelected(); - if (selected) + if (dragDrop.isSelected()) { - mItems[mCurrentOutfit][index] = selected->getId(); - mItemColors[mCurrentOutfit][index] = selected->getColor(); + mItems[mCurrentOutfit][index] = dragDrop.getSelected(); + mItemColors[mCurrentOutfit][index] = dragDrop.getSelectedColor(); dragDrop.deselect(); } } @@ -475,14 +474,10 @@ void OutfitWindow::mouseReleased(gcn::MouseEvent &event) event.consume(); if (!dragDrop.isEmpty()) { - Item *const item = dragDrop.getItem(); - if (item) - { - mItems[mCurrentOutfit][index] = item->getId(); - mItemColors[mCurrentOutfit][index] = item->getColor(); - dragDrop.clear(); - dragDrop.deselect(); - } + mItems[mCurrentOutfit][index] = dragDrop.getItem(); + mItemColors[mCurrentOutfit][index] = dragDrop.getItemColor(); + dragDrop.clear(); + dragDrop.deselect(); } if (mItemClicked) mItemClicked = false; diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp index 2a65a57c1..ac2916c1d 100644 --- a/src/gui/widgets/dropshortcutcontainer.cpp +++ b/src/gui/widgets/dropshortcutcontainer.cpp @@ -214,11 +214,10 @@ void DropShortcutContainer::mousePressed(gcn::MouseEvent &event) } else { - Item *const selected = dragDrop.getSelected(); - if (selected) + if (dragDrop.isSelected()) { - dropShortcut->setItems(index, selected->getId(), - selected->getColor()); + dropShortcut->setItems(index, dragDrop.getSelected(), + dragDrop.getSelectedColor()); dragDrop.deselect(); } } @@ -255,13 +254,10 @@ void DropShortcutContainer::mouseReleased(gcn::MouseEvent &event) } if (!dragDrop.isEmpty()) { - Item *const item = dragDrop.getItem(); - if (item) - { - dropShortcut->setItems(index, item->getId(), item->getColor()); - dragDrop.clear(); - dragDrop.deselect(); - } + dropShortcut->setItems(index, dragDrop.getItem(), + dragDrop.getItemColor()); + dragDrop.clear(); + dragDrop.deselect(); } mItemClicked = false; |