From a0021f305d242ebc98a3507fd15011b1b51232d0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 30 Mar 2014 12:20:30 +0300 Subject: Improve null pointer check in avatarlistbox. --- src/gui/widgets/avatarlistbox.cpp | 49 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 9411c2249..ecb92f876 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -99,13 +99,16 @@ void AvatarListBox::draw(Graphics *graphics) return; } + const Widget *const parent = mParent; + if (!parent) + return; + AvatarListModel *const model = static_cast( mListModel); updateAlpha(); Font *const font = getFont(); const int fontHeight = getFont()->getHeight(); - const Widget *const parent = mParent; const std::string name = player_node->getName(); // Draw the list elements @@ -155,7 +158,7 @@ void AvatarListBox::draw(Graphics *graphics) a->getHp(), a->getMaxHp()); } const bool isPoison = a->getPoison(); - if (a->getMaxHp() && (isPoison || parent)) + if (a->getMaxHp()) { const int themeColor = (isPoison ? Theme::PROG_HP_POISON : Theme::PROG_HP); @@ -182,28 +185,25 @@ void AvatarListBox::draw(Graphics *graphics) a->getDamageHp()); } - if (parent) - { - const int themeColor = (a->getPoison() - ? Theme::PROG_HP_POISON : Theme::PROG_HP); - Color color = Theme::getProgressColor(themeColor, 1); - color.a = 80; - graphics->setColor(color); - graphics->fillRectangle(Rect(mPadding, y + mPadding, - parent->getWidth() * a->getDamageHp() / 1024 - - 2 * mPadding, fontHeight)); + const int themeColor = (a->getPoison() + ? Theme::PROG_HP_POISON : Theme::PROG_HP); + Color color = Theme::getProgressColor(themeColor, 1); + color.a = 80; + graphics->setColor(color); + graphics->fillRectangle(Rect(mPadding, y + mPadding, + parent->getWidth() * a->getDamageHp() / 1024 + - 2 * mPadding, fontHeight)); - if (a->getLevel() > 1) - { - graphics->setColor(mForegroundColor); - int minHp = 40 + ((a->getLevel() - 1) * 5); - if (minHp < 0) - minHp = 40; - - graphics->drawLine(parent->getWidth()*minHp / 1024 - + mPadding, y + mPadding, - parent->getWidth() * minHp / 1024, y + fontHeight); - } + if (a->getLevel() > 1) + { + graphics->setColor(mForegroundColor); + int minHp = 40 + ((a->getLevel() - 1) * 5); + if (minHp < 0) + minHp = 40; + + graphics->drawLine(parent->getWidth()*minHp / 1024 + + mPadding, y + mPadding, + parent->getWidth() * minHp / 1024, y + fontHeight); } } else @@ -307,8 +307,7 @@ void AvatarListBox::draw(Graphics *graphics) if (useCaching) graphics->drawTileCollection(&vertexes); - if (parent) - setWidth(parent->getWidth() - 10); + setWidth(parent->getWidth() - 10); BLOCK_END("AvatarListBox::draw") } -- cgit v1.2.3-70-g09d2