summaryrefslogtreecommitdiff
path: root/src/gui/widgets/dropdown.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-29 01:10:18 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-29 01:10:18 +0300
commitf898898204f163ab807e681b4cc4bf2e26ece147 (patch)
tree169555c4117e49ecb19979a9c19ff3d24460c516 /src/gui/widgets/dropdown.cpp
parent0cd049b5b56b34b0b7ab3e3eac93dcb255c4e118 (diff)
downloadmv-f898898204f163ab807e681b4cc4bf2e26ece147.tar.gz
mv-f898898204f163ab807e681b4cc4bf2e26ece147.tar.bz2
mv-f898898204f163ab807e681b4cc4bf2e26ece147.tar.xz
mv-f898898204f163ab807e681b4cc4bf2e26ece147.zip
Add support for show icon also in selected item in dropdown.
Diffstat (limited to 'src/gui/widgets/dropdown.cpp')
-rw-r--r--src/gui/widgets/dropdown.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index dad85a0af..8a543b310 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -30,6 +30,7 @@
#include "gui/sdlinput.h"
#include "gui/viewport.h"
+#include "gui/widgets/extendedlistmodel.h"
#include "gui/widgets/listbox.h"
#include "gui/widgets/popuplist.h"
#include "gui/widgets/scrollarea.h"
@@ -68,6 +69,7 @@ DropDown::DropDown(const Widget2 *const widget,
gcn::FocusListener(),
gcn::SelectionListener(),
Widget2(widget),
+ mExtended(extended),
mPopup(new PopupList(this, listModel, extended)),
mShadowColor(getThemeColor(Theme::DROPDOWN_SHADOW)),
mHighlightColor(getThemeColor(Theme::HIGHLIGHT)),
@@ -157,6 +159,7 @@ DropDown::DropDown(const Widget2 *const widget,
mFrameSize = mSkin->getOption("frameSize");
mPadding = mSkin->getPadding();
mImagePadding = mSkin->getOption("imagePadding");
+ mSpacing = mSkin->getOption("spacing");
}
adjustHeight();
}
@@ -226,12 +229,36 @@ void DropDown::draw(gcn::Graphics* graphics)
mHighlightColor.a = alpha;
mShadowColor.a = alpha;
- if (mPopup->getListModel() && mPopup->getSelected() >= 0)
+ gcn::ListModel *const model = mPopup->getListModel();
+ if (model && mPopup->getSelected() >= 0)
{
gcn::Font *const font = getFont();
graphics->setColor(mForegroundColor);
- font->drawString(graphics, mPopup->getListModel()->getElementAt(
- mPopup->getSelected()), mPadding, mPadding);
+ if (mExtended)
+ {
+ const int sel = mPopup->getSelected();
+ ExtendedListModel *const model2
+ = static_cast<ExtendedListModel *const>(model);
+ const Image *const image = model2->getImageAt(sel);
+ if (!image)
+ {
+ font->drawString(graphics, model->getElementAt(sel),
+ mPadding, mPadding);
+ }
+ else
+ {
+ static_cast<Graphics*>(graphics)->drawImage(
+ image, mImagePadding, (getHeight()
+ - image->getHeight()) / 2 + mPadding);
+ font->drawString(graphics, model->getElementAt(sel),
+ image->getWidth() + mImagePadding + mSpacing, mPadding);
+ }
+ }
+ else
+ {
+ font->drawString(graphics, model->getElementAt(
+ mPopup->getSelected()), mPadding, mPadding);
+ }
}
if (isFocused())