From da50354af7fffe79ee7137a3f3dd9d8b9f34afda Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 5 May 2010 00:36:41 +0300 Subject: Draw item image in item popups. Now draw image only in chat item popup. Reviewed-by: Bertram --- src/gui/itempopup.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'src/gui/itempopup.cpp') 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 #include 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); } + -- cgit v1.2.3-70-g09d2