summaryrefslogtreecommitdiff
path: root/src/gui/itempopup.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-05-21 21:56:41 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-05-21 21:56:41 +0200
commit63b4c9869b6256ed7644113cd23305b07cf9df03 (patch)
treeaff0d99f5b58cbaf4195ac755ecfb79f97bf7b65 /src/gui/itempopup.cpp
parent8c4c5a58c256cce7beb21b68c8a7d6b6ff5c4a3a (diff)
parent2953a3f92c5097bd99ff21f4536fe167a32d90c5 (diff)
downloadMana-63b4c9869b6256ed7644113cd23305b07cf9df03.tar.gz
Mana-63b4c9869b6256ed7644113cd23305b07cf9df03.tar.bz2
Mana-63b4c9869b6256ed7644113cd23305b07cf9df03.tar.xz
Mana-63b4c9869b6256ed7644113cd23305b07cf9df03.zip
Merge branch '1.0'
Conflicts: src/beingmanager.cpp src/beingmanager.h src/client.cpp src/localplayer.cpp
Diffstat (limited to 'src/gui/itempopup.cpp')
-rw-r--r--src/gui/itempopup.cpp47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 3f22c442..2618810b 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -28,17 +28,22 @@
#include "gui/gui.h"
#include "gui/theme.h"
+#include "gui/widgets/icon.h"
#include "gui/widgets/textbox.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
+#include "resources/image.h"
+#include "resources/resourcemanager.h"
+
#include <guichan/font.hpp>
#include <guichan/widgets/label.hpp>
ItemPopup::ItemPopup():
- Popup("ItemPopup")
+ Popup("ItemPopup"),
+ mIcon(0)
{
// Item Name
mItemName = new gcn::Label;
@@ -62,28 +67,62 @@ ItemPopup::ItemPopup():
mItemWeight->setEditable(false);
mItemWeight->setPosition(getPadding(), 3 * fontHeight + 4 * getPadding());
+ mIcon = new Icon(0);
+
add(mItemName);
add(mItemDesc);
add(mItemEffect);
add(mItemWeight);
+ add(mIcon);
addMouseListener(this);
}
ItemPopup::~ItemPopup()
{
+ if (mIcon)
+ {
+ Image *image = mIcon->getImage();
+ if (image)
+ image->decRef();
+ }
}
-void ItemPopup::setItem(const ItemInfo &item)
+void ItemPopup::setItem(const ItemInfo &item, bool showImage)
{
if (item.getName() == mItemName->getCaption())
return;
+ int space = 0;
+
+ Image *oldImage = mIcon->getImage();
+ if (oldImage)
+ oldImage->decRef();
+
+ if (showImage)
+ {
+ ResourceManager *resman = ResourceManager::getInstance();
+ Image *image = resman->getImage("graphics/items/" + item.getImageName());
+ mIcon->setImage(image);
+ if (image)
+ {
+ int x = getPadding();
+ int y = getPadding();
+ mIcon->setPosition(x, y);
+ space = mIcon->getWidth();
+ }
+ }
+ else
+ {
+ mIcon->setImage(0);
+ }
+
mItemType = item.getType();
mItemName->setCaption(item.getName());
mItemName->adjustSize();
mItemName->setForegroundColor(getColor(mItemType));
+ mItemName->setPosition(getPadding() + space, getPadding());
mItemDesc->setTextWrapped(item.getDescription(), 196);
mItemEffect->setTextWrapped(item.getEffect(), 196);
@@ -91,7 +130,7 @@ void ItemPopup::setItem(const ItemInfo &item)
Units::formatWeight(item.getWeight()).c_str()),
196);
- int minWidth = mItemName->getWidth();
+ int minWidth = mItemName->getWidth() + space;
if (mItemDesc->getMinWidth() > minWidth)
minWidth = mItemDesc->getMinWidth();
@@ -127,6 +166,7 @@ void ItemPopup::setItem(const ItemInfo &item)
mItemDesc->setPosition(getPadding(), 2 * height);
mItemEffect->setPosition(getPadding(), (numRowsDesc + getPadding()) * height);
+
}
gcn::Color ItemPopup::getColor(ItemType type)
@@ -171,3 +211,4 @@ void ItemPopup::mouseMoved(gcn::MouseEvent &event)
// When the mouse moved on top of the popup, hide it
setVisible(false);
}
+