summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-08 15:02:06 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-08 17:06:36 +0300
commitb930f7f858b0ad91206939ed1b6d5695bc10f9cc (patch)
tree2b6d2be95b1f387399709e99ffedf050866f534a /src/gui
parent4c404e75a4e36d2d3151200e09990a9b6e82dacf (diff)
downloadmanaplus-b930f7f858b0ad91206939ed1b6d5695bc10f9cc.tar.gz
manaplus-b930f7f858b0ad91206939ed1b6d5695bc10f9cc.tar.bz2
manaplus-b930f7f858b0ad91206939ed1b6d5695bc10f9cc.tar.xz
manaplus-b930f7f858b0ad91206939ed1b6d5695bc10f9cc.zip
use different item padding in listbox and extendedlistbox depend on DPI.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/widgets/extendedlistbox.cpp12
-rw-r--r--src/gui/widgets/extendedlistbox.h8
-rw-r--r--src/gui/widgets/listbox.cpp21
-rw-r--r--src/gui/widgets/listbox.h8
4 files changed, 27 insertions, 22 deletions
diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp
index 45497ae0a..68b4df766 100644
--- a/src/gui/widgets/extendedlistbox.cpp
+++ b/src/gui/widgets/extendedlistbox.cpp
@@ -33,22 +33,14 @@ ExtendedListBox::ExtendedListBox(const Widget2 *const widget,
const std::string &skin,
const int rowHeight) :
ListBox(widget, listModel, skin),
- mRowHeight(rowHeight),
mImagePadding(mSkin ? mSkin->getOption("imagePadding") : 0),
mSpacing(mSkin ? mSkin->getOption("spacing") : 0),
- mItemPadding(mSkin ? mSkin->getOption("itemPadding") : 1),
mHeight(0),
mListItems(),
mSelectedItems()
{
- if (!mRowHeight)
- {
- const gcn::Font *font = getFont();
- if (font)
- mRowHeight = font->getHeight() + 2 * mItemPadding;
- else
- mRowHeight = 13;
- }
+ if (rowHeight)
+ mRowHeight = rowHeight;
}
ExtendedListBox::~ExtendedListBox()
diff --git a/src/gui/widgets/extendedlistbox.h b/src/gui/widgets/extendedlistbox.h
index 79fef2f50..854c02f8b 100644
--- a/src/gui/widgets/extendedlistbox.h
+++ b/src/gui/widgets/extendedlistbox.h
@@ -61,21 +61,13 @@ class ExtendedListBox final : public ListBox
*/
void draw(gcn::Graphics *graphics) override;
- unsigned int getRowHeight() const override A_WARN_UNUSED
- { return mRowHeight; }
-
- void setRowHeight(unsigned int n)
- { mRowHeight = n; }
-
void adjustSize() override;
int getSelectionByMouse(const int y) const override;
protected:
- unsigned int mRowHeight;
int mImagePadding;
int mSpacing;
- int mItemPadding;
int mHeight;
std::vector<ExtendedListBoxItem> mListItems;
std::vector<ExtendedListBoxItem> mSelectedItems;
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index a31947e39..5010d3206 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -49,6 +49,8 @@ ListBox::ListBox(const Widget2 *const widget,
mOldSelected(-1),
mPadding(0),
mPressedIndex(-2),
+ mRowHeight(0),
+ mItemPadding(1),
mSkin(nullptr),
mDistributeMousePressed(true),
mCenterText(false)
@@ -61,7 +63,16 @@ ListBox::ListBox(const Widget2 *const widget,
mSkin = theme->load(skin, "listbox.xml");
if (mSkin)
+ {
mPadding = mSkin->getPadding();
+ mItemPadding = mSkin->getOption("itemPadding");
+ }
+
+ const gcn::Font *font = getFont();
+ if (font)
+ mRowHeight = font->getHeight() + 2 * mItemPadding;
+ else
+ mRowHeight = 13;
adjustSize();
}
@@ -113,12 +124,13 @@ void ListBox::draw(gcn::Graphics *graphics)
const std::string str = mListModel->getElementAt(mSelected);
font->drawString(graphics, str,
(width - font->getWidth(str)) / 2,
- mSelected * rowHeight + mPadding);
+ mSelected * rowHeight + mPadding + mItemPadding);
}
// Draw the list elements
g->setColorAll(mForegroundColor, mForegroundColor2);
const int sz = mListModel->getNumberOfElements();
- for (int i = 0, y = mPadding; i < sz; ++i, y += rowHeight)
+ for (int i = 0, y = mPadding + mItemPadding;
+ i < sz; ++i, y += rowHeight)
{
if (i != mSelected)
{
@@ -141,12 +153,13 @@ void ListBox::draw(gcn::Graphics *graphics)
mForegroundSelectedColor2);
const std::string str = mListModel->getElementAt(mSelected);
font->drawString(graphics, str, mPadding,
- mSelected * rowHeight + mPadding);
+ mSelected * rowHeight + mPadding + mItemPadding);
}
// Draw the list elements
g->setColorAll(mForegroundColor, mForegroundColor2);
const int sz = mListModel->getNumberOfElements();
- for (int i = 0, y = mPadding; i < sz; ++i, y += rowHeight)
+ for (int i = 0, y = mPadding + mItemPadding; i < sz;
+ ++i, y += rowHeight)
{
if (i != mSelected)
{
diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h
index 27e24a030..865a67216 100644
--- a/src/gui/widgets/listbox.h
+++ b/src/gui/widgets/listbox.h
@@ -98,6 +98,12 @@ class ListBox : public gcn::ListBox,
int getPressedIndex()
{ return mPressedIndex; }
+ unsigned int getRowHeight() const override A_WARN_UNUSED
+ { return mRowHeight; }
+
+ void setRowHeight(unsigned int n)
+ { mRowHeight = n; }
+
protected:
gcn::Color mHighlightColor;
gcn::Color mForegroundSelectedColor;
@@ -105,6 +111,8 @@ class ListBox : public gcn::ListBox,
int mOldSelected;
int mPadding;
int mPressedIndex;
+ unsigned int mRowHeight;
+ int mItemPadding;
Skin *mSkin;
static float mAlpha;
bool mDistributeMousePressed;