summaryrefslogtreecommitdiff
path: root/src/gui/widgets/avatarlistbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets/avatarlistbox.cpp')
-rw-r--r--src/gui/widgets/avatarlistbox.cpp64
1 files changed, 33 insertions, 31 deletions
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index f7d6e801..a5109267 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -32,33 +32,21 @@
#include <guichan/font.hpp>
-int AvatarListBox::instances = 0;
-ResourceRef<Image> AvatarListBox::onlineIcon;
-ResourceRef<Image> AvatarListBox::offlineIcon;
-
AvatarListBox::AvatarListBox(AvatarListModel *model):
ListBox(model)
{
- instances++;
-
- if (instances == 1)
- {
- onlineIcon = Theme::getImageFromTheme("circle-green.png");
- offlineIcon = Theme::getImageFromTheme("circle-gray.png");
- }
-
setWidth(200);
}
-AvatarListBox::~AvatarListBox()
+unsigned int AvatarListBox::getRowHeight() const
{
- instances--;
+ auto rowHeight = ListBox::getRowHeight();
- if (instances == 0)
- {
- onlineIcon = nullptr;
- offlineIcon = nullptr;
- }
+ auto theme = gui->getTheme();
+ if (auto onlineIcon = theme->getIcon("online"))
+ rowHeight = std::max<unsigned>(rowHeight, onlineIcon->getHeight() + 2);
+
+ return rowHeight;
}
void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
@@ -69,29 +57,43 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
auto *model = static_cast<AvatarListModel *>(mListModel);
auto *graphics = static_cast<Graphics *>(gcnGraphics);
- const int alpha = gui->getTheme()->getGuiAlpha();
-
- graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, alpha));
graphics->setFont(getFont());
- const int fontHeight = getFont()->getHeight();
+ const int rowHeight = getRowHeight();
// Draw filled rectangle around the selected list element
if (mSelected >= 0)
- graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected,
- getWidth(), fontHeight));
+ {
+ auto highlightColor = Theme::getThemeColor(Theme::HIGHLIGHT);
+ highlightColor.a = gui->getTheme()->getGuiAlpha();
+ graphics->setColor(highlightColor);
+ graphics->fillRectangle(gcn::Rectangle(0, rowHeight * mSelected,
+ getWidth(), rowHeight));
+ }
+
+ auto theme = gui->getTheme();
+ auto onlineIcon = theme->getIcon("online");
+ auto offlineIcon = theme->getIcon("offline");
// Draw the list elements
- graphics->setColor(Theme::getThemeColor(Theme::TEXT));
for (int i = 0, y = 0;
i < model->getNumberOfElements();
- ++i, y += fontHeight)
+ ++i, y += rowHeight)
{
+ if (mSelected == i)
+ graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT_TEXT));
+ else
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
+
Avatar *a = model->getAvatarAt(i);
+ int x = 1;
+
// Draw online status
- Image *icon = a->getOnline() ? onlineIcon : offlineIcon;
- if (icon)
- graphics->drawImage(icon, 2, y + 1);
+ if (const Image *icon = a->getOnline() ? onlineIcon : offlineIcon)
+ {
+ graphics->drawImage(icon, x, y + (rowHeight - icon->getHeight()) / 2);
+ x += icon->getWidth() + 4;
+ }
if (a->getDisplayBold())
graphics->setFont(boldFont);
@@ -109,7 +111,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
}
// Draw Name
- graphics->drawText(text, 15, y);
+ graphics->drawText(text, x, y);
if (a->getDisplayBold())
graphics->setFont(getFont());