Preparing the menu classes for Lua Part #2

- Remove CMenuForwarderNonLocalized
- Add overloaded function CMenuForwarder for non local
 THX Martii


Origin commit data
------------------
Commit: b41819190d
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2014-01-16 (Thu, 16 Jan 2014)

Origin message was:
------------------
Preparing the menu classes for Lua Part #2

- Remove CMenuForwarderNonLocalized
- Add overloaded function CMenuForwarder for non local
 THX Martii
This commit is contained in:
Michael Liebmann
2014-01-16 23:20:04 +01:00
parent 37e4b0bda8
commit 1918153c0a
35 changed files with 298 additions and 356 deletions

View File

@@ -39,6 +39,7 @@
#include <neutrino_menue.h>
#include <driver/fade.h>
#include <system/helpers.h>
#include <cctype>
@@ -174,14 +175,12 @@ void CMenuItem::paintItemCaption(const bool select_mode, const int &item_height,
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(name_start_x, y+ item_height, _dx- (name_start_x - x), left_text, item_color, 0, true); // UTF-8
//right text
if (right_text || right_bgcol)
if (right_text && (*right_text || right_bgcol))
{
int stringwidth = 0;
if (right_text)
stringwidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(right_text, true);
int stringwidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(right_text, true);
int stringstartposOption = std::max(name_start_x + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(left_text, true) + icon_frame_w, x + dx - stringwidth - icon_frame_w); //+ offx
if (right_bgcol) {
if (!right_text)
if (!*right_text)
stringstartposOption -= 60;
fb_pixel_t right_frame_col, right_bg_col;
if (active) {
@@ -197,7 +196,7 @@ void CMenuItem::paintItemCaption(const bool select_mode, const int &item_height,
col.setCorner(RADIUS_LARGE);
col.paint(false);
}
if (right_text) {
if (*right_text) {
stringstartposOption -= (icon_w == 0 ? 0 : icon_w + icon_frame_w);
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposOption, y+item_height,dx- (stringstartposOption- x), right_text, item_color, 0, true);
}
@@ -1457,7 +1456,7 @@ int CMenuOptionChooser::exec(CMenuTarget*)
else
l_option = g_Locale->getText(options[count].value);
sprintf(cnt, "%d", count);
CMenuForwarderNonLocalized *mn_option = new CMenuForwarderNonLocalized(l_option, true, NULL, selector, cnt);
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);
}
@@ -1640,7 +1639,7 @@ int CMenuOptionStringChooser::exec(CMenuTarget* parent)
if (strcmp(options[count].c_str(), optionValue) == 0)
selected = true;
sprintf(cnt, "%d", count);
CMenuForwarderNonLocalized *mn_option = new CMenuForwarderNonLocalized(options[count].c_str(), true, NULL, selector, cnt);
CMenuForwarder *mn_option = new CMenuForwarder(options[count], true, NULL, selector, to_string(count).c_str());
mn_option->setItemButton(NEUTRINO_ICON_BUTTON_OKAY, true /*for selected item*/);
menu->addItem(mn_option, selected);
}
@@ -1757,25 +1756,11 @@ int CMenuOptionLanguageChooser::paint( bool selected )
}
//-------------------------------------------------------------------------------------------------------------------------------
CMenuForwarder::CMenuForwarder(const neutrino_locale_t Text, const bool Active, const char * const Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right, bool IsStatic)
{
option = Option;
option_string = NULL;
text=Text;
active = Active;
jumpTarget = Target;
actionKey = ActionKey ? ActionKey : "";
directKey = DirectKey;
iconName = IconName ? IconName : "";
iconName_Info_right = IconName_Info_right ? IconName_Info_right : "";
isStatic = IsStatic;
}
CMenuForwarder::CMenuForwarder(const neutrino_locale_t Text, const bool Active, const std::string &Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right, bool IsStatic)
{
option = NULL;
option_string = &Option;
text=Text;
option_string_ptr = &Option;
name = Text;
nameString = "";
active = Active;
jumpTarget = Target;
actionKey = ActionKey ? ActionKey : "";
@@ -1785,20 +1770,65 @@ CMenuForwarder::CMenuForwarder(const neutrino_locale_t Text, const bool Active,
isStatic = IsStatic;
}
void CMenuForwarder::setOption(const char * const Option)
CMenuForwarder::CMenuForwarder(const std::string& Text, const bool Active, const std::string &Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right, bool IsStatic)
{
option = Option;
option_string = NULL;
if (used && x != -1)
paint();
option_string_ptr = &Option;
name = NONEXISTANT_LOCALE;
nameString = Text;
active = Active;
jumpTarget = Target;
actionKey = ActionKey ? ActionKey : "";
directKey = DirectKey;
iconName = IconName ? IconName : "";
iconName_Info_right = IconName_Info_right ? IconName_Info_right : "";
isStatic = IsStatic;
}
CMenuForwarder::CMenuForwarder(const neutrino_locale_t Text, const bool Active, const char * const Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right, bool IsStatic)
{
option_string = Option ? Option : "";
option_string_ptr = &option_string;
name = Text;
nameString = "";
active = Active;
jumpTarget = Target;
actionKey = ActionKey ? ActionKey : "";
directKey = DirectKey;
iconName = IconName ? IconName : "";
iconName_Info_right = IconName_Info_right ? IconName_Info_right : "";
isStatic = IsStatic;
}
CMenuForwarder::CMenuForwarder(const std::string& Text, const bool Active, const char * const Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right, bool IsStatic)
{
option_string = Option ? Option : "";
option_string_ptr = &option_string;
name = NONEXISTANT_LOCALE;
nameString = Text;
active = Active;
jumpTarget = Target;
actionKey = ActionKey ? ActionKey : "";
directKey = DirectKey;
iconName = IconName ? IconName : "";
iconName_Info_right = IconName_Info_right ? IconName_Info_right : "";
isStatic = IsStatic;
}
void CMenuForwarder::setName(const std::string& t)
{
name = NONEXISTANT_LOCALE;
nameString = t;
}
void CMenuForwarder::setName(const neutrino_locale_t t)
{
name = t;
nameString = "";
}
void CMenuForwarder::setOption(const std::string &Option)
{
option = NULL;
option_string = &Option;
if (used && x != -1)
paint();
option_string = Option;
}
int CMenuForwarder::getHeight(void) const
@@ -1806,32 +1836,18 @@ int CMenuForwarder::getHeight(void) const
return g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
}
// used gets set by the addItem() function. This is for set to paint Text from locales by just not calling the addItem() function.
// Without this, the changeNotifiers would become machine-dependent.
void CMenuForwarder::setTextLocale(const neutrino_locale_t Text)
{
text=Text;
if (used && x != -1)
paint();
}
int CMenuForwarder::getWidth(void)
{
int tw = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(g_Locale->getText(text), true);
const char * option_text = NULL;
if (option)
option_text = option;
else if (option_string)
option_text = option_string->c_str();
const char *_name = (name == NONEXISTANT_LOCALE) ? nameString.c_str() : g_Locale->getText(name);
int tw = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(_name, true);
fb_pixel_t bgcol = 0;
std::string option_name = getOption();
if (jumpTarget)
bgcol = jumpTarget->getColor();
if (option_text != NULL)
tw += 10 + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(option_text, true);
if (!option_name.empty())
tw += 10 + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(option_name.c_str(), true);
else if (bgcol)
tw += 10 + 60;
@@ -1850,28 +1866,21 @@ int CMenuForwarder::exec(CMenuTarget* parent)
}
}
const char * CMenuForwarder::getOption(void)
std::string CMenuForwarder::getOption(void)
{
if (option)
return option;
if (option_string)
return option_string->c_str();
if (!option_string_ptr->empty())
return *option_string_ptr;
if (jumpTarget)
return jumpTarget->getTargetValue();
return NULL;
}
const char * CMenuForwarder::getName(void)
{
return g_Locale->getText(text);
return jumpTarget->getValue();
return "";
}
int CMenuForwarder::paint(bool selected)
{
int height = getHeight();
const char * l_text = getName();
const char * l_name = getName();
const char * option_text = getOption();
std::string option_name = getOption();
fb_pixel_t bgcol = 0;
if (jumpTarget)
bgcol = jumpTarget->getColor();
@@ -1883,80 +1892,11 @@ int CMenuForwarder::paint(bool selected)
paintItemButton(selected, height);
//caption
paintItemCaption(selected, height, l_text, option_text, bgcol);
paintItemCaption(selected, height, l_name, option_name.c_str(), bgcol);
return y+ height;
}
CMenuDForwarder::CMenuDForwarder(const neutrino_locale_t Text, const bool Active, const char * const Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right)
: CMenuForwarder(Text, Active, Option, Target, ActionKey, DirectKey, IconName, IconName_Info_right)
{
}
CMenuDForwarder::CMenuDForwarder(const neutrino_locale_t Text, const bool Active, const std::string &Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right)
: CMenuForwarder(Text, Active, Option, Target, ActionKey, DirectKey, IconName, IconName_Info_right)
{
}
CMenuDForwarder::~CMenuDForwarder()
{
delete jumpTarget;
}
//-------------------------------------------------------------------------------------------------------------------------------
const char * CMenuForwarderNonLocalized::getName(void)
{
return the_text.c_str();
}
CMenuForwarderNonLocalized::CMenuForwarderNonLocalized(const char * const Text, const bool Active, const char * const Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right) : CMenuForwarder(NONEXISTANT_LOCALE, Active, Option, Target, ActionKey, DirectKey, IconName, IconName_Info_right)
{
the_text = Text;
}
CMenuForwarderNonLocalized::CMenuForwarderNonLocalized(const char * const Text, const bool Active, const std::string &Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right) : CMenuForwarder(NONEXISTANT_LOCALE, Active, Option, Target, ActionKey, DirectKey, IconName, IconName_Info_right)
{
the_text = Text;
}
// used gets set by the addItem() function. This is for set to paint non localized Text by just not calling the addItem() function.
// Without this, the changeNotifiers would become machine-dependent.
void CMenuForwarderNonLocalized::setText(const char * const Text)
{
the_text = Text;
if (used && x != -1)
paint();
}
int CMenuForwarderNonLocalized::getWidth(void)
{
int tw = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(the_text, true);
const char * option_text = NULL;
if (option)
option_text = option;
else if (option_string)
option_text = option_string->c_str();
if (option_text != NULL)
tw += 10 + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(option_text, true);
return tw;
}
CMenuDForwarderNonLocalized::CMenuDForwarderNonLocalized(const char * const Text, const bool Active, const char * const Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right) : CMenuForwarderNonLocalized(Text, Active, Option, Target, ActionKey, DirectKey, IconName, IconName_Info_right)
{
}
CMenuDForwarderNonLocalized::CMenuDForwarderNonLocalized(const char * const Text, const bool Active, const std::string &Option, CMenuTarget* Target, const char * const ActionKey, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right) : CMenuForwarderNonLocalized(Text, Active, Option, Target, ActionKey, DirectKey, IconName, IconName_Info_right)
{
}
CMenuDForwarderNonLocalized::~CMenuDForwarderNonLocalized()
{
delete jumpTarget;
}
//-------------------------------------------------------------------------------------------------------------------------------
CMenuSeparator::CMenuSeparator(const int Type, const neutrino_locale_t Text, bool IsStatic)
{

View File

@@ -79,13 +79,16 @@ class CChangeObserver
class CMenuTarget
{
protected:
std::string *valueString;
std::string valueStringTmp;
public:
CMenuTarget(){}
CMenuTarget(){ valueString = &valueStringTmp; }
virtual ~CMenuTarget(){}
virtual void hide(){}
virtual int exec(CMenuTarget* parent, const std::string & actionKey) = 0;
virtual std::string &getValue(void) { return *valueString; }
virtual fb_pixel_t getColor(void) { return 0; }
virtual const char * getTargetValue() { return NULL; }
};
class CMenuItem
@@ -200,72 +203,67 @@ class CMenuSeparator : public CMenuItem
class CMenuForwarder : public CMenuItem
{
std::string actionKey;
std::string actionKey;
protected:
const char * option;
const std::string * option_string;
CMenuTarget * jumpTarget;
neutrino_locale_t text;
std::string option_string;
const std::string * option_string_ptr;
CMenuTarget * jumpTarget;
virtual const char * getOption(void);
virtual const char * getName(void);
virtual std::string getOption(void);
public:
CMenuForwarder(const neutrino_locale_t Text, const bool Active=true, const char * const Option=NULL, CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const char * const IconName = NULL, const char * const IconName_Info_right = NULL, bool IsStatic = false);
CMenuForwarder(const neutrino_locale_t Text, const bool Active, const std::string &Option, CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const char * const IconName = NULL, const char * const IconName_Info_right = NULL, bool IsStatic = false);
CMenuForwarder(const neutrino_locale_t Text, const bool Active, const std::string &Option,
CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey,
const char * const IconName = NULL, const char * const IconName_Info_right = NULL, bool IsStatic = false);
CMenuForwarder(const std::string & Text, const bool Active, const std::string &Option,
CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey,
const char * const IconName = NULL, const char * const IconName_Info_right = NULL, bool IsStatic = false);
CMenuForwarder(const neutrino_locale_t Text, const bool Active = true, const char * const Option=NULL,
CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey,
const char * const IconName = NULL, const char * const IconName_Info_right = NULL, bool IsStatic = false);
CMenuForwarder(const std::string & Text, const bool Active = true, const char * const Option=NULL,
CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey,
const char * const IconName = NULL, const char * const IconName_Info_right = NULL, bool IsStatic = false);
virtual ~CMenuForwarder(){}
int paint(bool selected=false);
int getHeight(void) const;
int getWidth(void);
void setTextLocale(const neutrino_locale_t Text);
neutrino_locale_t getTextLocale() const {return text;};
CMenuTarget* getTarget() const {return jumpTarget;};
std::string getActionKey(){return actionKey;};
neutrino_locale_t getTextLocale() const {return name;}
CMenuTarget* getTarget() const {return jumpTarget;}
std::string getActionKey(){return actionKey;}
int exec(CMenuTarget* parent);
bool isSelectable(void) const
{
return active;
}
void setOption(const char * const Option);
bool isSelectable(void) const { return active; }
void setOption(const std::string &Option);
void setName(const std::string& text);
void setName(const neutrino_locale_t text);
};
class CMenuDForwarder : public CMenuForwarder
{
public:
CMenuDForwarder(const neutrino_locale_t Text, const bool Active=true, const char * const Option=NULL, CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const char * const IconName = NULL, const char * const IconName_Info_right = NULL);
CMenuDForwarder(const neutrino_locale_t Text, const bool Active, const std::string &Option, CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const char * const IconName = NULL, const char * const IconName_Info_right = NULL);
CMenuDForwarder(const neutrino_locale_t Text, const bool Active, const std::string &Option,
CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey,
const char * const IconName = NULL, const char * const IconName_Info_right = NULL)
: CMenuForwarder(Text, Active, Option, Target, ActionKey, DirectKey, IconName, IconName_Info_right) { };
CMenuDForwarder(const std::string & Text, const bool Active, const std::string &Option,
CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey,
const char * const IconName = NULL, const char * const IconName_Info_right = NULL)
: CMenuForwarder(Text, Active, Option, Target, ActionKey, DirectKey, IconName, IconName_Info_right) { };
CMenuDForwarder(const neutrino_locale_t Text, const bool Active=true, const char * const Option=NULL,
CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey,
const char * const IconName = NULL, const char * const IconName_Info_right = NULL)
: CMenuForwarder(Text, Active, Option, Target, ActionKey, DirectKey, IconName, IconName_Info_right) { };
CMenuDForwarder(const std::string & Text, const bool Active=true, const char * const Option=NULL,
CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey,
const char * const IconName = NULL, const char * const IconName_Info_right = NULL)
: CMenuForwarder(Text, Active, Option, Target, ActionKey, DirectKey, IconName, IconName_Info_right) { };
~CMenuDForwarder();
};
class CMenuForwarderNonLocalized : public CMenuForwarder
{
protected:
std::string the_text;
virtual const char * getName(void);
public:
// Text must be UTF-8 encoded:
CMenuForwarderNonLocalized(const char * const Text, const bool Active=true, const char * const Option=NULL, CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const char * const IconName = NULL, const char * const IconName_Info_right = NULL);
CMenuForwarderNonLocalized(const char * const Text, const bool Active, const std::string &Option, CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const char * const IconName = NULL, const char * const IconName_Info_right = NULL);
virtual ~CMenuForwarderNonLocalized(){}
int getWidth(void);
void setText(const char * const Text);
};
class CMenuDForwarderNonLocalized : public CMenuForwarderNonLocalized
{
public:
CMenuDForwarderNonLocalized(const char * const Text, const bool Active=true, const char * const Option=NULL, CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const char * const IconName = NULL, const char * const IconName_Info_right = NULL);
CMenuDForwarderNonLocalized(const char * const Text, const bool Active, const std::string &Option, CMenuTarget* Target=NULL, const char * const ActionKey = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const char * const IconName = NULL, const char * const IconName_Info_right = NULL);
~CMenuDForwarderNonLocalized();
~CMenuDForwarder() { delete jumpTarget; }
};
class CAbstractMenuOptionChooser : public CMenuItem

View File

@@ -53,7 +53,7 @@ CMountChooser::CMountChooser(const neutrino_locale_t Name, const std::string & I
{
std::string s = g_settings.network_nfs[i].local_dir + " (" + g_settings.network_nfs[i].ip + ":" + g_settings.network_nfs[i].dir + ")";
snprintf(indexStr,sizeof(indexStr),"%d",i);
addItem(new CMenuForwarderNonLocalized(s.c_str(),true,NULL,this,(std::string("MID:") + std::string(indexStr)).c_str()),
addItem(new CMenuForwarder(s.c_str(),true,NULL,this,(std::string("MID:") + std::string(indexStr)).c_str()),
selectedLocalDir == g_settings.network_nfs[i].local_dir);
}
}

View File

@@ -180,7 +180,6 @@ class CDateInput : public CExtendedInput
public:
CDateInput(const neutrino_locale_t Name, time_t* Time, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ = NULL);
~CDateInput();
char* getValue() {return value;}
};
//----------------------------------------------------------------------------------------------------
@@ -230,9 +229,6 @@ class CIntInput : public CExtendedInput
*@param Size how many digits can be entered
*/
CIntInput(const neutrino_locale_t Name, int& Value, const unsigned int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ = NULL);
char* getValue() {
return myValueStringOutput;
}
void updateValue() { onBeforeExec(); }
};