summaryrefslogtreecommitdiff
path: root/src/gui/widgets/listbox.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-07 20:25:34 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-07 20:25:34 +0300
commitf34f096ee0f3c2e66eec7dc024dd18a74698840f (patch)
treed061471178dce461038d4af000c9e4535bd703ad /src/gui/widgets/listbox.cpp
parentd6c201415ccf5b1ceebf92fc588f22dc20f9bd81 (diff)
downloadmanaplus-f34f096ee0f3c2e66eec7dc024dd18a74698840f.tar.gz
manaplus-f34f096ee0f3c2e66eec7dc024dd18a74698840f.tar.bz2
manaplus-f34f096ee0f3c2e66eec7dc024dd18a74698840f.tar.xz
manaplus-f34f096ee0f3c2e66eec7dc024dd18a74698840f.zip
add support for centered text in listbox.
Diffstat (limited to 'src/gui/widgets/listbox.cpp')
-rw-r--r--src/gui/widgets/listbox.cpp71
1 files changed, 53 insertions, 18 deletions
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index 4d05e496e..51751c463 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -51,7 +51,8 @@ ListBox::ListBox(const Widget2 *const widget,
mOldSelected(-1),
mPadding(0),
mSkin(nullptr),
- mDistributeMousePressed(true)
+ mDistributeMousePressed(true),
+ mCenterText(false)
{
mForegroundColor = getThemeColor(Theme::LISTBOX);
@@ -96,28 +97,62 @@ void ListBox::draw(gcn::Graphics *graphics)
graphics->setColor(mHighlightColor);
gcn::Font *const font = getFont();
const int rowHeight = getRowHeight();
+ const int width = mDimension.width;
- // Draw filled rectangle around the selected list element
- if (mSelected >= 0)
+ if (mCenterText)
{
- graphics->fillRectangle(gcn::Rectangle(mPadding,
- rowHeight * mSelected + mPadding,
- mDimension.width - 2 * mPadding, rowHeight));
-
- g->setColorAll(mForegroundSelectedColor,
- mForegroundSelectedColor2);
- font->drawString(graphics, mListModel->getElementAt(mSelected),
- mPadding, mSelected * rowHeight + mPadding);
+ // Draw filled rectangle around the selected list element
+ if (mSelected >= 0)
+ {
+ graphics->fillRectangle(gcn::Rectangle(mPadding,
+ rowHeight * mSelected + mPadding,
+ mDimension.width - 2 * mPadding, rowHeight));
+
+ g->setColorAll(mForegroundSelectedColor,
+ mForegroundSelectedColor2);
+ const std::string str = mListModel->getElementAt(mSelected);
+ font->drawString(graphics, str,
+ (width - font->getWidth(str)) / 2,
+ mSelected * rowHeight + mPadding);
+ }
+ // Draw the list elements
+ g->setColorAll(mForegroundColor, mForegroundColor2);
+ const int sz = mListModel->getNumberOfElements();
+ for (int i = 0, y = mPadding; i < sz; ++i, y += rowHeight)
+ {
+ if (i != mSelected)
+ {
+ const std::string str = mListModel->getElementAt(i);
+ font->drawString(graphics, str,
+ (width - font->getWidth(str)) / 2, y);
+ }
+ }
}
- // Draw the list elements
- g->setColorAll(mForegroundColor, mForegroundColor2);
- const int sz = mListModel->getNumberOfElements();
- for (int i = 0, y = mPadding; i < sz; ++i, y += rowHeight)
+ else
{
- if (i != mSelected)
+ // Draw filled rectangle around the selected list element
+ if (mSelected >= 0)
+ {
+ graphics->fillRectangle(gcn::Rectangle(mPadding,
+ rowHeight * mSelected + mPadding,
+ mDimension.width - 2 * mPadding, rowHeight));
+
+ g->setColorAll(mForegroundSelectedColor,
+ mForegroundSelectedColor2);
+ const std::string str = mListModel->getElementAt(mSelected);
+ font->drawString(graphics, str, mPadding,
+ mSelected * rowHeight + mPadding);
+ }
+ // Draw the list elements
+ g->setColorAll(mForegroundColor, mForegroundColor2);
+ const int sz = mListModel->getNumberOfElements();
+ for (int i = 0, y = mPadding; i < sz; ++i, y += rowHeight)
{
- font->drawString(graphics, mListModel->getElementAt(i),
- mPadding, y);
+ if (i != mSelected)
+ {
+ const std::string str = mListModel->getElementAt(i);
+ font->drawString(graphics, str, mPadding, y);
+ }
}
}
BLOCK_END("ListBox::draw")