From 2babe1d6491f5231b0e97349ccb198b92bb90ba9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 27 Dec 2012 01:22:21 +0300 Subject: Improve draw speed in listboxes. --- src/gui/widgets/avatarlistbox.cpp | 10 ++++------ src/gui/widgets/extendedlistbox.cpp | 11 ++++++----- src/gui/widgets/listbox.cpp | 7 ++++--- src/gui/widgets/shoplistbox.cpp | 7 +++---- 4 files changed, 17 insertions(+), 18 deletions(-) (limited to 'src/gui') diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 5a5027982..d9fe65dfe 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -105,13 +105,11 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) Graphics *const graphics = static_cast(gcnGraphics); mHighlightColor.a = static_cast(mAlpha * 255.0f); -// graphics->setColor(mHighlightColor); - graphics->setFont(getFont()); + gcn::Font *const font = getFont(); + graphics->setFont(font); const int fontHeight = getFont()->getHeight(); - const gcn::Widget *const parent = mParent; - const std::string name = player_node->getName(); // Draw the list elements @@ -271,9 +269,9 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) // Draw Name if (a->getType() == MapItem::SEPARATOR) - graphics->drawText(text, mPadding, y + mPadding); + font->drawString(graphics, text, mPadding, y + mPadding); else - graphics->drawText(text, 15 + mPadding, y + mPadding); + font->drawString(graphics, text, 15 + mPadding, y + mPadding); if (a->getDisplayBold()) graphics->setFont(getFont()); diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp index bad1472ac..af1480f86 100644 --- a/src/gui/widgets/extendedlistbox.cpp +++ b/src/gui/widgets/extendedlistbox.cpp @@ -60,7 +60,8 @@ void ExtendedListBox::draw(gcn::Graphics *graphics) Graphics *const g = static_cast(graphics); updateAlpha(); - graphics->setFont(getFont()); + gcn::Font *const font = getFont(); + graphics->setFont(font); const int height = getRowHeight(); int textPos = (height - getFont()->getHeight()) / 2 + mPadding; @@ -87,14 +88,14 @@ void ExtendedListBox::draw(gcn::Graphics *graphics) const Image *const image = model->getImageAt(i); if (!image) { - graphics->drawText(mListModel->getElementAt(i), + font->drawString(graphics, mListModel->getElementAt(i), mPadding, y + textPos); } else { g->drawImage(image, mImagePadding, y + (height - image->getHeight()) / 2 + mPadding); - graphics->drawText(mListModel->getElementAt(i), + font->drawString(graphics, mListModel->getElementAt(i), image->getWidth() + mImagePadding + mSpacing, y + textPos); } } @@ -104,13 +105,13 @@ void ExtendedListBox::draw(gcn::Graphics *graphics) const Image *const image = model->getImageAt(mSelected); if (!image) { - graphics->drawText(mListModel->getElementAt(mSelected), + font->drawString(graphics, mListModel->getElementAt(mSelected), mPadding, mSelected * height + textPos); } else { graphics->setColor(mForegroundSelectedColor); - graphics->drawText(mListModel->getElementAt(mSelected), + font->drawString(graphics, mListModel->getElementAt(mSelected), image->getWidth() + mImagePadding + mSpacing, mSelected * height + textPos); } diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 87ecc9460..dbd54f3f3 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -92,7 +92,8 @@ void ListBox::draw(gcn::Graphics *graphics) mHighlightColor.a = static_cast(mAlpha * 255.0f); graphics->setColor(mHighlightColor); - graphics->setFont(getFont()); + gcn::Font *const font = getFont(); + graphics->setFont(font); const int height = getRowHeight(); @@ -107,7 +108,7 @@ void ListBox::draw(gcn::Graphics *graphics) if (sel >= 0) { graphics->setColor(mForegroundSelectedColor); - graphics->drawText(mListModel->getElementAt(sel), + font->drawString(graphics, mListModel->getElementAt(sel), mPadding, sel * height + mPadding); } // Draw the list elements @@ -117,7 +118,7 @@ void ListBox::draw(gcn::Graphics *graphics) { if (i != sel) { - graphics->drawText(mListModel->getElementAt(i), + font->drawString(graphics, mListModel->getElementAt(i), mPadding, y + mPadding); } } diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 1dd58532e..11f350165 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -95,10 +95,9 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) mAlpha = Client::getGuiAlpha(); const int alpha = static_cast(mAlpha * 255.0f); - Graphics *graphics = static_cast(gcnGraphics); - - graphics->setFont(getFont()); + gcn::Font *const font = getFont(); + graphics->setFont(font); // Draw the list elements for (int i = 0, y = 0; @@ -159,7 +158,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) graphics->setColor(mForegroundSelectedColor); else graphics->setColor(mForegroundColor); - graphics->drawText(mListModel->getElementAt(i), + font->drawString(graphics, mListModel->getElementAt(i), ITEM_ICON_SIZE + mPadding, y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2 + mPadding); } -- cgit v1.2.3-70-g09d2