summaryrefslogtreecommitdiff
path: root/src/gui/itemcontainer.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-01-15 22:01:00 -0700
committerIra Rice <irarice@gmail.com>2009-01-15 22:01:00 -0700
commit600e10515e127d6393f0756cb72e5a63303557a2 (patch)
tree19afc618315e59e09355241ca2b8ae850dc89e6a /src/gui/itemcontainer.cpp
parent0a18932056e2a72f41cdd14c831344ad80cfb35b (diff)
downloadmana-600e10515e127d6393f0756cb72e5a63303557a2.tar.gz
mana-600e10515e127d6393f0756cb72e5a63303557a2.tar.bz2
mana-600e10515e127d6393f0756cb72e5a63303557a2.tar.xz
mana-600e10515e127d6393f0756cb72e5a63303557a2.zip
Integrated the ItemPopup class from Legends of Mazzeroth.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/itemcontainer.cpp')
-rw-r--r--src/gui/itemcontainer.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 26ca3379..2cc0bef3 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -48,6 +48,8 @@ ItemContainer::ItemContainer(Inventory *inventory, int offset):
mLastSelectedItemId(NO_ITEM),
mOffset(offset)
{
+ mItemPopup = new ItemPopup();
+
ResourceManager *resman = ResourceManager::getInstance();
mSelImg = resman->getImage("graphics/gui/selection.png");
@@ -222,7 +224,7 @@ void ItemContainer::distributeValueChangedEvent()
void ItemContainer::mousePressed(gcn::MouseEvent &event)
{
- int button = event.getButton();
+ const int button = event.getButton();
if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT)
{
@@ -240,3 +242,40 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
itemShortcut->setItemSelected(item->getId());
}
}
+
+// Show ItemTooltip
+void ItemContainer::mouseMoved(gcn::MouseEvent &event)
+{
+ Item *item = mInventory->getItem( getSlotIndex(event.getX(), event.getY() ) );
+
+ if( item )
+ {
+ mItemPopup->setPosition(getParent()->getParent()->getX() +
+ getParent()->getParent()->getWidth(),
+ getParent()->getParent()->getY());
+
+ mItemPopup->setItem(item->getInfo());
+
+ mItemPopup->setVisible(true);
+ }
+ else
+ {
+ mItemPopup->setVisible(false);
+ }
+}
+
+// Hide ItemTooltip
+void ItemContainer::mouseExited(gcn::MouseEvent &event)
+{
+ mItemPopup->setVisible(false);
+}
+
+int ItemContainer::getSlotIndex(const int posX, const int posY) const
+{
+ int columns = getWidth() / gridWidth;
+ int index = posX / gridWidth + ((posY / gridHeight) * columns) + mOffset;
+
+ return (index);
+}
+
+