summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2010-01-11 20:18:45 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-01-11 20:03:21 +0100
commitb09ede7286093519af8f2b044ad7be17600d2cda (patch)
tree1e864de27634cd94baf471f4299a2cad97c2cb10 /src
parent440150cba3cd8441283d9914fc444358dee64495 (diff)
downloadmana-b09ede7286093519af8f2b044ad7be17600d2cda.tar.gz
mana-b09ede7286093519af8f2b044ad7be17600d2cda.tar.bz2
mana-b09ede7286093519af8f2b044ad7be17600d2cda.tar.xz
mana-b09ede7286093519af8f2b044ad7be17600d2cda.zip
Fix segfault in ShopListBox
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/shoplistbox.cpp26
-rw-r--r--src/gui/widgets/shoplistbox.h2
2 files changed, 20 insertions, 8 deletions
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index 4779b8c2..b1fde91d 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -93,9 +93,12 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
if (mShopItems &&
mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck)
+ {
if (i != mSelected)
+ {
backgroundColor = &guiPalette->getColor(Palette::SHOP_WARNING,
alpha);
+ }
else
{
temp = guiPalette->getColor(Palette::SHOP_WARNING, alpha);
@@ -104,8 +107,11 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
temp.b = (temp.g + highlightColor->b) / 2;
backgroundColor = &temp;
}
+ }
else if (i == mSelected)
+ {
backgroundColor = highlightColor;
+ }
graphics->setColor(*backgroundColor);
graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight));
@@ -128,9 +134,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
void ShopListBox::adjustSize()
{
if (mListModel)
- {
setHeight(mRowHeight * mListModel->getNumberOfElements());
- }
}
void ShopListBox::setPriceCheck(bool check)
@@ -143,15 +147,23 @@ void ShopListBox::mouseMoved(gcn::MouseEvent &event)
if (!mShopItems)
return;
- Item *item = mShopItems->at(event.getY() / mRowHeight);
+ int index = event.getY() / mRowHeight;
- if (item)
+ if (index < 0 || index >= mShopItems->getNumberOfElements())
{
- mItemPopup->setItem(item->getInfo());
- mItemPopup->view(viewport->getMouseX(), viewport->getMouseY());
+ mItemPopup->setVisible(false);
}
else
{
- mItemPopup->setVisible(false);
+ Item *item = mShopItems->at(index);
+ if (item)
+ {
+ mItemPopup->setItem(item->getInfo());
+ mItemPopup->view(viewport->getMouseX(), viewport->getMouseY());
+ }
+ else
+ {
+ mItemPopup->setVisible(false);
+ }
}
}
diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h
index 99d3b9bd..635e9ab3 100644
--- a/src/gui/widgets/shoplistbox.h
+++ b/src/gui/widgets/shoplistbox.h
@@ -72,7 +72,7 @@ class ShopListBox : public ListBox
* (Good for selling mode.)
*/
void setPriceCheck(bool check);
-
+
void mouseMoved(gcn::MouseEvent &event);
private: