From b09ede7286093519af8f2b044ad7be17600d2cda Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 11 Jan 2010 20:18:45 +0200 Subject: Fix segfault in ShopListBox --- src/gui/widgets/shoplistbox.cpp | 26 +++++++++++++++++++------- src/gui/widgets/shoplistbox.h | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src/gui') 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: -- cgit v1.2.3-70-g09d2