diff --git a/src/gui/widget/menue.cpp b/src/gui/widget/menue.cpp index ad9b91ff4..35cae0a4b 100644 --- a/src/gui/widget/menue.cpp +++ b/src/gui/widget/menue.cpp @@ -76,7 +76,7 @@ CMenuItem::CMenuItem(bool Active, neutrino_msg_t DirectKey, const char * const I setInfoIconRight(IconName_Info_right); hintIcon = NULL; - + has_option_icon = false; x = -1; used = false; hint = NONEXISTANT_LOCALE; @@ -274,7 +274,9 @@ void CMenuItem::paintItemCaption(const bool select_mode, const char * right_text } if (*right_text) { stringstartposOption -= (icon_w == 0 ? 0 : icon_w + OFFSET_INNER_MID); - g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposOption, y+item_height - desc_height, dx - stringstartposOption + x - OFFSET_INNER_MID, right_text, item_color); + if (!has_option_icon || icon_w == 0) //don't render text if we use an 'option icon' + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposOption, y+item_height - desc_height, dx - stringstartposOption + x - OFFSET_INNER_MID, right_text, item_color); + has_option_icon = false; } } if (desc_text && *desc_text) @@ -539,6 +541,31 @@ void CMenuItem::activateNotify() actObserv->activateNotify(name); } +void CMenuItem::handleOptionIcon(const std::string& str_option) +{ + std::string on = g_Locale->getText(LOCALE_OPTIONS_ON); + std::string off = g_Locale->getText(LOCALE_OPTIONS_OFF); + std::string yes = g_Locale->getText(LOCALE_MESSAGEBOX_YES); + std::string no = g_Locale->getText(LOCALE_MESSAGEBOX_NO); + + if (str_option == on || str_option == off || str_option == yes || str_option == no){ + if (str_option == on || str_option == yes) + setInfoIconRight(active ? NEUTRINO_ICON_BUTTON_OPTION_ON_ACTIVE : NEUTRINO_ICON_BUTTON_OPTION_ON_INACTIVE); + if (str_option == off || str_option == no) + setInfoIconRight(active ? NEUTRINO_ICON_BUTTON_OPTION_OFF_ACTIVE : NEUTRINO_ICON_BUTTON_OPTION_OFF_INACTIVE); + has_option_icon = true; + }else + setInfoIconRight(NULL); +} + +const char* CMenuItem::getValName(const neutrino_locale_t& Option, const char* ValName) +{ + if (ValName) + return ValName; + else + return g_Locale->getText(Option); +} + //small helper class to manage values e.g.: handling needed but deallocated widget objects CMenuGlobal::CMenuGlobal() { @@ -1726,6 +1753,9 @@ int CMenuOptionNumberChooser::paint(bool selected) } } + //manage toggle button + handleOptionIcon(l_option); + //paint item prepareItem(selected, height); @@ -1935,7 +1965,7 @@ int CMenuOptionChooser::exec(CMenuTarget*) { CMenuOptionChooserOptions* co = new CMenuOptionChooserOptions(); co->key = options[i1].key; - co->valname = (options[i1].valname != 0) ? options[i1].valname : g_Locale->getText(options[i1].value); + co->valname = getValName(options[i1].value, options[i1].valname ); option_chooser_options_v.push_back(co); } @@ -1966,11 +1996,8 @@ int CMenuOptionChooser::exec(CMenuTarget*) const char * l_option; if (options[count].key == (*optionValue)) selected = true; + l_option = getValName(options[count].value, options[count].valname); - if(options[count].valname != 0) - l_option = options[count].valname; - else - l_option = g_Locale->getText(options[count].value); CMenuForwarder *mn_option = new CMenuForwarder(l_option, true, NULL, selector, to_string(count).c_str()); mn_option->setItemButton(NEUTRINO_ICON_BUTTON_OKAY, true /*for selected item*/); menu->addItem(mn_option, selected); @@ -2017,33 +2044,27 @@ int CMenuOptionChooser::exec(CMenuTarget*) int CMenuOptionChooser::paint( bool selected) { - neutrino_locale_t option = NONEXISTANT_LOCALE; const char * l_option = NULL; for(unsigned int count = 0 ; count < number_of_options; count++) { if (options[count].key == *optionValue) { - option = options[count].value; - if(options[count].valname != 0) - l_option = options[count].valname; - else - l_option = g_Locale->getText(option); + l_option = getValName(options[count].value, options[count].valname); break; } } - - if(l_option == NULL) + + if(l_option == NULL) { *optionValue = options[0].key; - option = options[0].value; - if(options[0].valname != 0) - l_option = options[0].valname; - else - l_option = g_Locale->getText(option); + l_option = getValName(options[0].value, options[0].valname); } + //manage toggle button + handleOptionIcon(l_option); + //paint item prepareItem(selected, height); - + //paint item icon paintItemButton(selected, height, NEUTRINO_ICON_BUTTON_OKAY); diff --git a/src/gui/widget/menue.h b/src/gui/widget/menue.h index df9185f90..11165f095 100644 --- a/src/gui/widget/menue.h +++ b/src/gui/widget/menue.h @@ -126,6 +126,10 @@ class CMenuItem : public CComponentsSignals neutrino_locale_t desc; std::string descString; CActivateObserver * actObserv; + + bool has_option_icon; + void handleOptionIcon(const std::string& str_option); + const char* getValName(const neutrino_locale_t& Option, const char* ValName); public: int height; bool active, current_active; @@ -442,7 +446,6 @@ class CMenuOptionChooser : public CAbstractMenuOptionChooser bool OptionsSort ); - public: CMenuOptionChooser(const neutrino_locale_t Name, int * const OptionValue, const struct keyval * const Options, const size_t Number_Of_Options, const bool Active = false, CChangeObserver * const Observ = NULL,