diff options
author | Andrei Karas <akaras@inbox.ru> | 2010-01-11 20:18:45 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-01-11 20:03:21 +0100 |
commit | b09ede7286093519af8f2b044ad7be17600d2cda (patch) | |
tree | 1e864de27634cd94baf471f4299a2cad97c2cb10 /src/gui/widgets/shoplistbox.cpp | |
parent | 440150cba3cd8441283d9914fc444358dee64495 (diff) | |
download | mana-b09ede7286093519af8f2b044ad7be17600d2cda.tar.gz mana-b09ede7286093519af8f2b044ad7be17600d2cda.tar.bz2 mana-b09ede7286093519af8f2b044ad7be17600d2cda.tar.xz mana-b09ede7286093519af8f2b044ad7be17600d2cda.zip |
Fix segfault in ShopListBox
Diffstat (limited to 'src/gui/widgets/shoplistbox.cpp')
-rw-r--r-- | src/gui/widgets/shoplistbox.cpp | 26 |
1 files changed, 19 insertions, 7 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); + } } } |