diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-12-29 01:10:18 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-12-29 01:10:18 +0300 |
commit | f898898204f163ab807e681b4cc4bf2e26ece147 (patch) | |
tree | 169555c4117e49ecb19979a9c19ff3d24460c516 /src | |
parent | 0cd049b5b56b34b0b7ab3e3eac93dcb255c4e118 (diff) | |
download | manaplus-f898898204f163ab807e681b4cc4bf2e26ece147.tar.gz manaplus-f898898204f163ab807e681b4cc4bf2e26ece147.tar.bz2 manaplus-f898898204f163ab807e681b4cc4bf2e26ece147.tar.xz manaplus-f898898204f163ab807e681b4cc4bf2e26ece147.zip |
Add support for show icon also in selected item in dropdown.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/dropdown.cpp | 33 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.h | 22 |
2 files changed, 41 insertions, 14 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()) diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index 1707857cb..295c8b527 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -25,17 +25,15 @@ #include "gui/widgets/widget2.h" -#include "guichan/actionlistener.hpp" -#include "guichan/basiccontainer.hpp" -#include "guichan/focushandler.hpp" -#include "guichan/focuslistener.hpp" -#include "guichan/keylistener.hpp" -#include "guichan/listmodel.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/selectionlistener.hpp" - -#include "guichan/widgets/listbox.hpp" -#include "guichan/widgets/scrollarea.hpp" +#include <guichan/actionlistener.hpp> +#include <guichan/basiccontainer.hpp> +#include <guichan/focushandler.hpp> +#include <guichan/focuslistener.hpp> +#include <guichan/keylistener.hpp> +#include <guichan/listmodel.hpp> +#include <guichan/mouselistener.hpp> +#include <guichan/selectionlistener.hpp> +#include <guichan/widgets/scrollarea.hpp> #include "localconsts.h" @@ -147,11 +145,13 @@ class DropDown final : public gcn::ActionListener, */ void drawButton(gcn::Graphics *graphics); + bool mExtended; PopupList *mPopup; gcn::Color mShadowColor; gcn::Color mHighlightColor; int mPadding; int mImagePadding; + int mSpacing; bool mDroppedDown; bool mPushed; |