From 3078fd67b62f4dd7de5cb6e944709e5b51c3c8fb Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 14 Jun 2013 20:00:13 +0300 Subject: Improve shoplistbox. --- src/gui/widgets/shoplistbox.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/gui') diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index ec3ed12e4..615b93010 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -94,17 +94,21 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) Graphics *graphics = static_cast(gcnGraphics); gcn::Font *const font = getFont(); + const int sz = mListModel->getNumberOfElements(); + const int fontHeigh = getFont()->getHeight(); + const int width = mDimension.width - 2 * mPadding; // Draw the list elements for (int i = 0, y = 0; - i < mListModel->getNumberOfElements(); + i < sz; ++i, y += mRowHeight) { bool needDraw(false); gcn::Color temp; gcn::Color* backgroundColor = &mBackgroundColor; - if (mShopItems && mShopItems->at(i) && - mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) + ShopItem *const item = mShopItems->at(i); + if (mShopItems && item && + mPlayerMoney < item->getPrice() && mPriceCheck) { if (i != mSelected) { @@ -137,12 +141,12 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) { graphics->setColor(*backgroundColor); graphics->fillRectangle(gcn::Rectangle(mPadding, y + mPadding, - getWidth() - 2 * mPadding, mRowHeight)); + width, mRowHeight)); } if (mShopItems) { - Image *const icon = mShopItems->at(i)->getImage(); + Image *const icon = item->getImage(); if (icon) { icon->setAlpha(1.0f); @@ -160,7 +164,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) } font->drawString(graphics, mListModel->getElementAt(i), ITEM_ICON_SIZE + mPadding, - y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2 + mPadding); + y + (ITEM_ICON_SIZE - fontHeigh) / 2 + mPadding); } BLOCK_END("ShopListBox::draw") } -- cgit v1.2.3-60-g2f50