From 0cd049b5b56b34b0b7ab3e3eac93dcb255c4e118 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 29 Dec 2012 00:16:54 +0300 Subject: Show flags icons in language selection list Also add support for extended listboxes in popuplist control. --- configure.ac | 1 + data/graphics/CMakeLists.txt | 1 + data/graphics/Makefile.am | 2 +- data/graphics/flags/CMakeLists.txt | 19 ++++++++++ data/graphics/flags/Makefile.am | 22 ++++++++++++ data/graphics/flags/cn.png | Bin 0 -> 442 bytes data/graphics/flags/cz.png | Bin 0 -> 444 bytes data/graphics/flags/de.png | Bin 0 -> 446 bytes data/graphics/flags/en.png | Bin 0 -> 614 bytes data/graphics/flags/es.png | Bin 0 -> 441 bytes data/graphics/flags/fi.png | Bin 0 -> 464 bytes data/graphics/flags/fr.png | Bin 0 -> 462 bytes data/graphics/flags/id.png | Bin 0 -> 378 bytes data/graphics/flags/it.png | Bin 0 -> 377 bytes data/graphics/flags/jp.png | Bin 0 -> 408 bytes data/graphics/flags/pl.png | Bin 0 -> 345 bytes data/graphics/flags/pt.png | Bin 0 -> 494 bytes data/graphics/flags/pt_BR.png | Bin 0 -> 571 bytes data/graphics/flags/ru.png | Bin 0 -> 414 bytes data/graphics/flags/vls.png | Bin 0 -> 399 bytes src/gui/inventorywindow.cpp | 2 +- src/gui/logindialog.cpp | 2 +- src/gui/setup_theme.cpp | 70 +++++++++++++++++++++++++----------- src/gui/widgets/dropdown.cpp | 3 +- src/gui/widgets/dropdown.h | 1 + src/gui/widgets/extendedlistbox.cpp | 13 +++++-- src/gui/widgets/extendedlistbox.h | 3 +- src/gui/widgets/popuplist.cpp | 8 +++-- src/gui/widgets/popuplist.h | 2 +- 29 files changed, 117 insertions(+), 32 deletions(-) create mode 100644 data/graphics/flags/CMakeLists.txt create mode 100644 data/graphics/flags/Makefile.am create mode 100644 data/graphics/flags/cn.png create mode 100644 data/graphics/flags/cz.png create mode 100644 data/graphics/flags/de.png create mode 100644 data/graphics/flags/en.png create mode 100644 data/graphics/flags/es.png create mode 100644 data/graphics/flags/fi.png create mode 100644 data/graphics/flags/fr.png create mode 100644 data/graphics/flags/id.png create mode 100644 data/graphics/flags/it.png create mode 100644 data/graphics/flags/jp.png create mode 100644 data/graphics/flags/pl.png create mode 100644 data/graphics/flags/pt.png create mode 100644 data/graphics/flags/pt_BR.png create mode 100644 data/graphics/flags/ru.png create mode 100644 data/graphics/flags/vls.png diff --git a/configure.ac b/configure.ac index 4281f4f2e..2433d27cc 100755 --- a/configure.ac +++ b/configure.ac @@ -310,6 +310,7 @@ data/Makefile data/evol/Makefile data/fonts/Makefile data/graphics/Makefile +data/graphics/flags/Makefile data/graphics/gui/Makefile data/graphics/images/Makefile data/graphics/sprites/Makefile diff --git a/data/graphics/CMakeLists.txt b/data/graphics/CMakeLists.txt index 5a9b0f65b..2713d7899 100644 --- a/data/graphics/CMakeLists.txt +++ b/data/graphics/CMakeLists.txt @@ -1,3 +1,4 @@ +ADD_SUBDIRECTORY(flags) ADD_SUBDIRECTORY(gui) ADD_SUBDIRECTORY(images) ADD_SUBDIRECTORY(sprites) diff --git a/data/graphics/Makefile.am b/data/graphics/Makefile.am index c0e91d050..c566673ec 100644 --- a/data/graphics/Makefile.am +++ b/data/graphics/Makefile.am @@ -4,4 +4,4 @@ graphicsdir = $(pkgdatadir)/data/graphics EXTRA_DIST = \ CMakeLists.txt -SUBDIRS = gui images sprites +SUBDIRS = flags gui images sprites diff --git a/data/graphics/flags/CMakeLists.txt b/data/graphics/flags/CMakeLists.txt new file mode 100644 index 000000000..02a07eaba --- /dev/null +++ b/data/graphics/flags/CMakeLists.txt @@ -0,0 +1,19 @@ +SET(FILES + cn.png + cz.png + de.png + en.png + es.png + fi.png + fr.png + id.png + it.png + jp.png + pl.png + pt_BR.png + pt.png + ru.png + vls.png + ) + +INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/graphics/flags) diff --git a/data/graphics/flags/Makefile.am b/data/graphics/flags/Makefile.am new file mode 100644 index 000000000..4396903f6 --- /dev/null +++ b/data/graphics/flags/Makefile.am @@ -0,0 +1,22 @@ +flagsdir = $(pkgdatadir)/data/graphics/flags + +flags_DATA = \ + cn.png \ + cz.png \ + de.png \ + en.png \ + es.png \ + fi.png \ + fr.png \ + id.png \ + it.png \ + jp.png \ + pl.png \ + pt_BR.png \ + pt.png \ + ru.png \ + vls.png + +EXTRA_DIST = \ + $(flags_DATA) \ + CMakeLists.txt diff --git a/data/graphics/flags/cn.png b/data/graphics/flags/cn.png new file mode 100644 index 000000000..dfe68b743 Binary files /dev/null and b/data/graphics/flags/cn.png differ diff --git a/data/graphics/flags/cz.png b/data/graphics/flags/cz.png new file mode 100644 index 000000000..d6ceb5b2b Binary files /dev/null and b/data/graphics/flags/cz.png differ diff --git a/data/graphics/flags/de.png b/data/graphics/flags/de.png new file mode 100644 index 000000000..b162c174a Binary files /dev/null and b/data/graphics/flags/de.png differ diff --git a/data/graphics/flags/en.png b/data/graphics/flags/en.png new file mode 100644 index 000000000..bbc1d224d Binary files /dev/null and b/data/graphics/flags/en.png differ diff --git a/data/graphics/flags/es.png b/data/graphics/flags/es.png new file mode 100644 index 000000000..f9b3221ae Binary files /dev/null and b/data/graphics/flags/es.png differ diff --git a/data/graphics/flags/fi.png b/data/graphics/flags/fi.png new file mode 100644 index 000000000..0d8029469 Binary files /dev/null and b/data/graphics/flags/fi.png differ diff --git a/data/graphics/flags/fr.png b/data/graphics/flags/fr.png new file mode 100644 index 000000000..086ca9f2f Binary files /dev/null and b/data/graphics/flags/fr.png differ diff --git a/data/graphics/flags/id.png b/data/graphics/flags/id.png new file mode 100644 index 000000000..ca18a70a7 Binary files /dev/null and b/data/graphics/flags/id.png differ diff --git a/data/graphics/flags/it.png b/data/graphics/flags/it.png new file mode 100644 index 000000000..5b1bc0ef7 Binary files /dev/null and b/data/graphics/flags/it.png differ diff --git a/data/graphics/flags/jp.png b/data/graphics/flags/jp.png new file mode 100644 index 000000000..6f295e292 Binary files /dev/null and b/data/graphics/flags/jp.png differ diff --git a/data/graphics/flags/pl.png b/data/graphics/flags/pl.png new file mode 100644 index 000000000..007d5a0c6 Binary files /dev/null and b/data/graphics/flags/pl.png differ diff --git a/data/graphics/flags/pt.png b/data/graphics/flags/pt.png new file mode 100644 index 000000000..31411a17a Binary files /dev/null and b/data/graphics/flags/pt.png differ diff --git a/data/graphics/flags/pt_BR.png b/data/graphics/flags/pt_BR.png new file mode 100644 index 000000000..0c0d050fa Binary files /dev/null and b/data/graphics/flags/pt_BR.png differ diff --git a/data/graphics/flags/ru.png b/data/graphics/flags/ru.png new file mode 100644 index 000000000..92b8d13ce Binary files /dev/null and b/data/graphics/flags/ru.png differ diff --git a/data/graphics/flags/vls.png b/data/graphics/flags/vls.png new file mode 100644 index 000000000..0625b14d0 Binary files /dev/null and b/data/graphics/flags/vls.png differ diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index d875644f6..3bf526b40 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -108,7 +108,7 @@ InventoryWindow::InventoryWindow(Inventory *const inventory): mSlotsBar(new ProgressBar(this, 0.0f, 100, 0, Theme::PROG_INVY_SLOTS)), mFilter(nullptr), mSortModel(new SortListModel), - mSortDropDown(new DropDown(this, mSortModel, this, "sort")), + mSortDropDown(new DropDown(this, mSortModel, false, this, "sort")), mNameFilter(new TextField(this, "", true, this, "namefilter", true)), mSortDropDownCell(nullptr), mNameFilterCell(nullptr), diff --git a/src/gui/logindialog.cpp b/src/gui/logindialog.cpp index 41016b05c..26093634e 100644 --- a/src/gui/logindialog.cpp +++ b/src/gui/logindialog.cpp @@ -163,7 +163,7 @@ LoginDialog::LoginDialog(LoginData *const data, std::string serverName, mLoginData->updateHost.c_str())); mUpdateListModel = new UpdateListModel(mLoginData); mUpdateHostDropDown = new DropDown(this, mUpdateListModel, - this, "updateselect"); + false, this, "updateselect"); const std::string str = serverConfig.getValue("updateHost2", ""); if (!str.empty()) mUpdateHostDropDown->setSelectedString(str); diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index 277ddadae..2a8836bcb 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -29,6 +29,7 @@ #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" #include "gui/widgets/dropdown.h" +#include "gui/widgets/extendedlistmodel.h" #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/namesmodel.h" @@ -116,46 +117,73 @@ struct Language final { std::string name; std::string value; + std::string icon; }; const int langs_count = 16; const Language LANG_NAME[langs_count] = { - {N_("(default)"), ""}, - {N_("Chinese (China)"), "zh_CN"}, - {N_("Czech"), "cs_CZ"}, - {N_("English"), "C"}, - {N_("Finnish"), "fi_FI"}, - {N_("French"), "fr_FR"}, - {N_("German"), "de_DE"}, - {N_("Indonesian"), "id_ID"}, - {N_("Italian"), "it_IT"}, - {N_("Polish"), "pl_PL"}, - {N_("Japanese"), "ja_JP.utf8"}, - {N_("Dutch (Belgium/Flemish)"), "nl_BE"}, - {N_("Portuguese"), "pt_PT"}, - {N_("Portuguese (Brazilian)"), "pt_BR"}, - {N_("Russian"), "ru_RU"}, - {N_("Spanish (Castilian)"), "es_ES"} + {N_("(default)"), "", ""}, + {N_("Chinese (China)"), "zh_CN", "cn.png"}, + {N_("Czech"), "cs_CZ", "cz.png"}, + {N_("English"), "C", "en.png"}, + {N_("Finnish"), "fi_FI", "fi.png"}, + {N_("French"), "fr_FR", "fr.png"}, + {N_("German"), "de_DE", "de.png"}, + {N_("Indonesian"), "id_ID", "id.png"}, + {N_("Italian"), "it_IT", "it.png"}, + {N_("Polish"), "pl_PL", "pl.png"}, + {N_("Japanese"), "ja_JP", "jp.png"}, + {N_("Dutch (Belgium/Flemish)"), "nl_BE", ""}, + {N_("Portuguese"), "pt_PT", "pt.png"}, + {N_("Portuguese (Brazilian)"), "pt_BR", "pt_BR.png"}, + {N_("Russian"), "ru_RU", "ru.png"}, + {N_("Spanish (Castilian)"), "es_ES", "es.png"} }; -class LangListModel final : public gcn::ListModel +class LangListModel final : public ExtendedListModel { public: + LangListModel() + { + ResourceManager *const resman = ResourceManager::getInstance(); + for (int f = 0; f < langs_count; f ++) + { + mIcons[f] = resman->getImage("graphics/flags/" + + LANG_NAME[f].icon); + } + } + virtual ~LangListModel() - { } + { + for (int f = 0; f < langs_count; f ++) + { + Image *const img = mIcons[f]; + if (img) + img->decRef(); + } + } - virtual int getNumberOfElements() override + int getNumberOfElements() override A_WARN_UNUSED { return langs_count; } - virtual std::string getElementAt(int i) override + std::string getElementAt(int i) override A_WARN_UNUSED { if (i >= getNumberOfElements() || i < 0) return _("???"); return gettext(LANG_NAME[i].name.c_str()); } + + const Image *getImageAt(int i) override A_WARN_UNUSED + { + if (i >= getNumberOfElements() || i < 0) + return nullptr; + return mIcons[i]; + } + + Image *mIcons[langs_count]; }; Setup_Theme::Setup_Theme(const Widget2 *const widget) : @@ -170,7 +198,7 @@ Setup_Theme::Setup_Theme(const Widget2 *const widget) : mFont(config.getStringValue("font")), mLangListModel(new LangListModel), mLangLabel(new Label(this, _("Language"))), - mLangDropDown(new DropDown(this, mLangListModel)), + mLangDropDown(new DropDown(this, mLangListModel, true)), mLang(config.getStringValue("lang")), mBoldFontLabel(new Label(this, _("Bold font"))), mBoldFontDropDown(new DropDown(this, mFontsModel)), diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 384371107..dad85a0af 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -58,6 +58,7 @@ static std::string const dropdownFiles[2] = DropDown::DropDown(const Widget2 *const widget, gcn::ListModel *const listModel, + bool extended, gcn::ActionListener *const listener, const std::string &eventId): gcn::ActionListener(), @@ -67,7 +68,7 @@ DropDown::DropDown(const Widget2 *const widget, gcn::FocusListener(), gcn::SelectionListener(), Widget2(widget), - mPopup(new PopupList(this, listModel)), + mPopup(new PopupList(this, listModel, extended)), mShadowColor(getThemeColor(Theme::DROPDOWN_SHADOW)), mHighlightColor(getThemeColor(Theme::HIGHLIGHT)), mPadding(1), diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index 6b3b6503a..1707857cb 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -72,6 +72,7 @@ class DropDown final : public gcn::ActionListener, */ DropDown(const Widget2 *const widget, gcn::ListModel *const listModel = nullptr, + bool extended = false, gcn::ActionListener *const listener = nullptr, const std::string &eventId = ""); diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp index b932f91b0..8c850775a 100644 --- a/src/gui/widgets/extendedlistbox.cpp +++ b/src/gui/widgets/extendedlistbox.cpp @@ -37,12 +37,21 @@ #include "debug.h" ExtendedListBox::ExtendedListBox(const Widget2 *const widget, - gcn::ListModel *const listModel) : + gcn::ListModel *const listModel, + int rowHeight) : ListBox(widget, listModel), - mRowHeight(13), + mRowHeight(rowHeight), mImagePadding(mSkin ? mSkin->getOption("imagePadding") : 0), mSpacing(mSkin ? mSkin->getOption("spacing") : 0) { + if (!mRowHeight) + { + const gcn::Font *font = getFont(); + if (font) + mRowHeight = font->getHeight() + 2 * mPadding; + else + mRowHeight = 13; + } } ExtendedListBox::~ExtendedListBox() diff --git a/src/gui/widgets/extendedlistbox.h b/src/gui/widgets/extendedlistbox.h index 32fd274aa..79ae868cf 100644 --- a/src/gui/widgets/extendedlistbox.h +++ b/src/gui/widgets/extendedlistbox.h @@ -30,7 +30,8 @@ class ExtendedListBox final : public ListBox * Constructor. */ ExtendedListBox(const Widget2 *const widget, - gcn::ListModel *const listModel); + gcn::ListModel *const listModel, + int rowHeight = 13); A_DELETE_COPY(ExtendedListBox) diff --git a/src/gui/widgets/popuplist.cpp b/src/gui/widgets/popuplist.cpp index 260dcb6a9..80fd12e85 100644 --- a/src/gui/widgets/popuplist.cpp +++ b/src/gui/widgets/popuplist.cpp @@ -23,7 +23,7 @@ #include "gui/gui.h" #include "gui/widgets/dropdown.h" -#include "gui/widgets/listbox.h" +#include "gui/widgets/extendedlistbox.h" #include "gui/widgets/scrollarea.h" #include "utils/gettext.h" @@ -31,11 +31,13 @@ #include "debug.h" PopupList::PopupList(DropDown *const widget, - gcn::ListModel *const listModel): + gcn::ListModel *const listModel, + bool extended): Popup("PopupList", "popuplist.xml"), gcn::FocusListener(), mListModel(listModel), - mListBox(new ListBox(widget, listModel)), + mListBox(extended ? new ExtendedListBox(widget, listModel, 0) : + new ListBox(widget, listModel)), mScrollArea(new ScrollArea(mListBox, false)), mDropDown(widget) { diff --git a/src/gui/widgets/popuplist.h b/src/gui/widgets/popuplist.h index e609b52f6..3ba3773fe 100644 --- a/src/gui/widgets/popuplist.h +++ b/src/gui/widgets/popuplist.h @@ -39,7 +39,7 @@ class PopupList final : public Popup, { public: PopupList(DropDown *const widget, - gcn::ListModel *const listModel); + gcn::ListModel *const listModel, bool extended); ~PopupList(); -- cgit v1.2.3-70-g09d2