summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-03-30 12:20:30 +0300
committerAndrei Karas <akaras@inbox.ru>2014-03-30 12:20:30 +0300
commita0021f305d242ebc98a3507fd15011b1b51232d0 (patch)
tree5c634e7ff6b5504f383478f1a98c50c3438c3e9e /src/gui/widgets
parent02b61ee41a7dca0a29a32ceb136284b071d08f60 (diff)
downloadplus-a0021f305d242ebc98a3507fd15011b1b51232d0.tar.gz
plus-a0021f305d242ebc98a3507fd15011b1b51232d0.tar.bz2
plus-a0021f305d242ebc98a3507fd15011b1b51232d0.tar.xz
plus-a0021f305d242ebc98a3507fd15011b1b51232d0.zip
Improve null pointer check in avatarlistbox.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/avatarlistbox.cpp49
1 files changed, 24 insertions, 25 deletions
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<AvatarListModel *const>(
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")
}