summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2010-05-05 00:36:41 +0300
committerBertram <yohanndotferreiraatorange.fr>2010-05-13 00:21:48 +0200
commitda50354af7fffe79ee7137a3f3dd9d8b9f34afda (patch)
treefc497b9a29dec5dacad514598665eced09d05baf
parent46cd4e737a5a74f823877c1fd00a6af84005612f (diff)
downloadmana-da50354af7fffe79ee7137a3f3dd9d8b9f34afda.tar.gz
mana-da50354af7fffe79ee7137a3f3dd9d8b9f34afda.tar.bz2
mana-da50354af7fffe79ee7137a3f3dd9d8b9f34afda.tar.xz
mana-da50354af7fffe79ee7137a3f3dd9d8b9f34afda.zip
Draw item image in item popups.
Now draw image only in chat item popup. Reviewed-by: Bertram
-rw-r--r--src/gui/itempopup.cpp47
-rw-r--r--src/gui/itempopup.h4
-rw-r--r--src/gui/widgets/icon.cpp10
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp5
4 files changed, 55 insertions, 11 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);
}
+
diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h
index 67d1eb2f..a3976a11 100644
--- a/src/gui/itempopup.h
+++ b/src/gui/itempopup.h
@@ -29,6 +29,7 @@
#include <guichan/mouselistener.hpp>
+class Icon;
class TextBox;
/**
@@ -50,7 +51,7 @@ class ItemPopup : public Popup
/**
* Sets the info to be displayed given a particular item.
*/
- void setItem(const ItemInfo &item);
+ void setItem(const ItemInfo &item, bool showImage = false);
void mouseMoved(gcn::MouseEvent &mouseEvent);
@@ -60,6 +61,7 @@ class ItemPopup : public Popup
TextBox *mItemEffect;
TextBox *mItemWeight;
ItemType mItemType;
+ Icon *mIcon;
static gcn::Color getColor(ItemType type);
};
diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp
index ef22c37d..4e590212 100644
--- a/src/gui/widgets/icon.cpp
+++ b/src/gui/widgets/icon.cpp
@@ -30,20 +30,22 @@ Icon::Icon(const std::string &file)
: mImage(0)
{
mImage = ResourceManager::getInstance()->getImage(file);
- setSize(mImage->getWidth(), mImage->getHeight());
-
+ if (mImage)
+ setSize(mImage->getWidth(), mImage->getHeight());
}
Icon::Icon(Image *image)
: mImage(image)
{
- setSize(mImage->getWidth(), mImage->getHeight());
+ if (mImage)
+ setSize(mImage->getWidth(), mImage->getHeight());
}
void Icon::setImage(Image *image)
{
mImage = image;
- setSize(mImage->getWidth(), mImage->getHeight());
+ if (mImage)
+ setSize(mImage->getWidth(), mImage->getHeight());
}
void Icon::draw(gcn::Graphics *g)
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
index 0c51aeb3..b7341084 100644
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ b/src/gui/widgets/itemlinkhandler.cpp
@@ -49,9 +49,8 @@ void ItemLinkHandler::handleLink(const std::string &link)
if (id > 0)
{
- const ItemInfo &iteminfo = ItemDB::get(id);
-
- mItemPopup->setItem(iteminfo);
+ const ItemInfo &itemInfo = ItemDB::get(id);
+ mItemPopup->setItem(itemInfo, true);
if (mItemPopup->isVisible())
mItemPopup->setVisible(false);