Main Menu: try to add dynamic possibility to disable items on runtime

The issue is that it's not really possible to disable/enable menu items on
runtime with an existant menu widget instance eg with personalized menu items.

Here we need a dynamic solution to disable items depends on stb-mode (mode_ts, mode_tv etc)
This should be solved here with an additional parameter for personalized items.

New paramter is named: disable_condition
Possible alvailable values at the moment are:

 DCOND_MODE_NONE as default

 DCOND_MODE_TV
 DCOND_MODE_RADIO
 DCOND_MODE_TS

includes some improvements by Sven

- menue: remove old_iconName handling
 ... icons should be painted on deactivated items too

- menue: try to fix position <-> selection missmatch


Origin commit data
------------------
Commit: 1f95f38d32
Author: Thilo Graf <dbt@novatux.de>
Date: 2015-12-13 (Sun, 13 Dec 2015)

Origin message was:
------------------
Main Menu: try to add dynamic possibility to disable items on runtime

The issue is that it's not really possible to disable/enable menu items on
runtime with an existant menu widget instance eg with personalized menu items.

Here we need a dynamic solution to disable items depends on stb-mode (mode_ts, mode_tv etc)
This should be solved here with an additional parameter for personalized items.

New paramter is named: disable_condition
Possible alvailable values at the moment are:

 DCOND_MODE_NONE as default

 DCOND_MODE_TV
 DCOND_MODE_RADIO
 DCOND_MODE_TS

includes some improvements by Sven

- menue: remove old_iconName handling
 ... icons should be painted on deactivated items too

- menue: try to fix position <-> selection missmatch
This commit is contained in:
2015-12-13 16:06:38 +01:00
committed by Michael Liebmann
parent 605506123d
commit e5e740fcf7
6 changed files with 127 additions and 44 deletions

View File

@@ -59,7 +59,7 @@ CMenuForwarder * const GenericMenuNext = &CGenericMenuNext;
CMenuItem::CMenuItem(bool Active, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right, bool IsStatic)
{
active = Active;
active = current_active = Active;
directKey = DirectKey;
isStatic = IsStatic;
@@ -89,6 +89,7 @@ CMenuItem::CMenuItem(bool Active, neutrino_msg_t DirectKey, const char * const I
selected_iconName = NULL;
height = 0;
actObserv = NULL;
parent_widget = NULL;
}
void CMenuItem::init(const int X, const int Y, const int DX, const int OFFX)
@@ -104,7 +105,7 @@ void CMenuItem::init(const int X, const int Y, const int DX, const int OFFX)
void CMenuItem::setActive(const bool Active)
{
active = Active;
active = current_active = Active;
/* used gets set by the addItem() function. This is for disabling
machine-specific options by just not calling the addItem() function.
Without this, the changeNotifiers would become machine-dependent. */
@@ -112,6 +113,48 @@ void CMenuItem::setActive(const bool Active)
paint();
}
bool CMenuItem::initModeCondition(const int& stb_mode)
{
if (CNeutrinoApp::getInstance()->getMode() == stb_mode){
active = false;
marked = false;
if (parent_widget)
if (!isSelectable())
parent_widget->initSelectable();
return true;
}
printf("\033[33m[CMenuItem] [%s - %d] missmatching stb mode condition \033[0m\n", __func__, __LINE__, stb_mode);
return false;
}
void CMenuItem::disableByCondition(const menu_item_disable_cond_t& condition)
{
int stb_mode = CNeutrinoApp::getInstance()->getMode();
if (condition & DCOND_MODE_TS){
if (stb_mode == CNeutrinoApp::mode_ts)
if (initModeCondition(stb_mode))
return;
}
if (condition & DCOND_MODE_RADIO){
if (stb_mode == CNeutrinoApp::mode_radio)
if (initModeCondition(stb_mode))
return;
}
if (condition & DCOND_MODE_TV){
if (stb_mode == CNeutrinoApp::mode_tv)
if (initModeCondition(stb_mode))
return;
}
active = current_active;
if (parent_widget){
if (!isSelectable())
parent_widget->initSelectable();
}
}
void CMenuItem::setMarked(const bool Marked)
{
marked = Marked;
@@ -605,6 +648,7 @@ void CMenuWidget::addItem(CMenuItem* menuItem, const bool defaultselected)
menuItem->isUsed();
items.push_back(menuItem);
menuItem->setParentWidget(this);
}
void CMenuWidget::resetWidget(bool delete_items)
@@ -668,12 +712,7 @@ int CMenuWidget::exec(CMenuTarget* parent, const std::string &)
neutrino_msg_data_t data;
bool bAllowRepeatLR = false;
CVFD::MODES oldLcdMode = CVFD::getInstance()->getMode();
int pos = 0;
if (selected > 0 && selected < (int)items.size())
pos = selected;
else
selected = -1;
exit_pressed = false;
frameBuffer->Lock();
@@ -693,21 +732,22 @@ int CMenuWidget::exec(CMenuTarget* parent, const std::string &)
}
}
}
/* make sure we start with a selectable item... */
while (pos < (int)items.size()) {
if (items[pos]->isSelectable())
break;
pos++;
}
checkHints();
if(savescreen) {
calcSize();
saveScreen();
}
/* make sure we start with a selectable item... */
initSelectable();
paint();
frameBuffer->blit();
int pos = selected;
int retval = menu_return::RETURN_REPAINT;
uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]);
@@ -1132,6 +1172,22 @@ void CMenuWidget::calcSize()
setMenuPos(full_width);
}
void CMenuWidget::initSelectable()
{
int pos = 0;
if (selected > 0 && selected < (int)items.size())
pos = selected;
else
selected = -1;
while (pos < (int)items.size()) {
if (items[pos]->isSelectable())
break;
pos++;
}
selected = pos;
}
void CMenuWidget::paint()
{
calcSize();
@@ -1218,16 +1274,16 @@ void CMenuWidget::paintItems()
* different height and this might leave artifacts otherwise after changing pages */
frameBuffer->paintBoxRel(x,item_start_y, width,item_height, COL_MENUCONTENT_PLUS_0);
}
int ypos=item_start_y;
for (int count = 0; count < (int)items.size(); count++)
{
CMenuItem* item = items[count];
item->OnPaintItem();
if ((count >= page_start[current_page]) &&
(count < page_start[current_page + 1]))
{
item->init(x, ypos, width, iconOffset);
if (item->isSelectable() && selected == -1)
selected = count;
@@ -2124,7 +2180,8 @@ std::string CMenuForwarder::getOption(void)
int CMenuForwarder::paint(bool selected)
{
std::string option_name = getOption();
std::string option_name = getOption();
fb_pixel_t bgcol = 0;
if (jumpTarget)
bgcol = jumpTarget->getColor();
@@ -2137,7 +2194,7 @@ int CMenuForwarder::paint(bool selected)
//caption
paintItemCaption(selected, option_name.c_str(), bgcol);
return y+ height;
}

View File

@@ -56,7 +56,8 @@ extern "C" {
#define NO_WIDGET_ID -1
typedef int mn_widget_id_t;
typedef int menu_item_disable_cond_t;
class CMenuWidget;
struct menu_return
{
enum
@@ -69,6 +70,15 @@ struct menu_return
};
};
enum
{
DCOND_MODE_NONE = 1,
DCOND_MODE_TV = 2,
DCOND_MODE_RADIO = 4,
DCOND_MODE_TS = 8
}/*menu_item_disable_cond_t*/;
class CChangeObserver
{
public:
@@ -104,15 +114,16 @@ class CMenuTarget
virtual fb_pixel_t getColor(void) { return 0; }
};
class CMenuItem
class CMenuItem : public CComponentsSignals
{
private:
void setIconName();
CMenuWidget* parent_widget;
protected:
int x, y, dx, offx, name_start_x, icon_frame_w;
bool used;
fb_pixel_t item_color, item_bgcolor;
bool initModeCondition(const int& stb_mode);
void initItemColors(const bool select_mode);
lua_State *luaState;
std::string luaAction;
@@ -124,7 +135,7 @@ class CMenuItem
CActivateObserver * actObserv;
public:
int height;
bool active;
bool active, current_active;
bool marked;
bool inert;
bool isStatic;
@@ -157,7 +168,7 @@ class CMenuItem
}
virtual int getYPosition(void) const { return y; }
virtual bool isSelectable(void) const { return active; }
virtual bool isSelectable(void) const { return (active && current_active); }
virtual int exec(CMenuTarget* /*parent*/)
{
@@ -166,9 +177,9 @@ class CMenuItem
virtual void setActive(const bool Active);
virtual void setMarked(const bool Marked);
virtual void setInert(const bool Inert);
virtual void paintItemButton(const bool select_mode, int item_height, const char * const icon_Name = NEUTRINO_ICON_BUTTON_RIGHT);
virtual void prepareItem(const bool select_mode, const int &item_height);
virtual void setItemButton(const char * const icon_Name, const bool is_select_button = false);
@@ -180,17 +191,20 @@ class CMenuItem
virtual int isMenueOptionChooser(void) const{return 0;}
void setHint(const char * const icon, const neutrino_locale_t text) { hintIcon = (icon && *icon) ? icon : NULL; hint = text; }
void setHint(const char * const icon, const std::string text) { hintIcon = (icon && *icon) ? icon : NULL; hintText = text; }
void setLua(lua_State *_luaState, std::string &_luaAction, std::string &_luaId) { luaState = _luaState; luaAction = _luaAction; luaId = _luaId; };
virtual const char *getName();
virtual void setName(const std::string& text);
virtual void setName(const neutrino_locale_t text);
sigc::signal<void> OnPaintItem;
virtual const char *getDescription();
virtual void setDescription(const std::string& text);
virtual void setDescription(const neutrino_locale_t text);
virtual int getDescriptionHeight(void);
void setActivateObserver(CActivateObserver * Observ) { actObserv = Observ; }
void activateNotify(void);
virtual void disableByCondition(const menu_item_disable_cond_t& condition);
void setParentWidget(CMenuWidget* parent){parent_widget = parent;}
};
class CMenuSeparator : public CMenuItem
@@ -355,7 +369,7 @@ struct CMenuOptionChooserCompareItem: public std::binary_function <const CMenuOp
};
};
class CMenuOptionChooser : public CAbstractMenuOptionChooser, public sigc::trackable
class CMenuOptionChooser : public CAbstractMenuOptionChooser
{
public:
struct keyval
@@ -577,6 +591,7 @@ class CMenuWidget : public CMenuTarget
virtual const char *getName();
virtual void integratePlugins(CPlugins::i_type_t integration, const unsigned int shortcut=CRCInput::RC_nokey, bool enabled=true);
void setSelected(const int &Preselected){ selected = Preselected; };
void initSelectable();
int getSelected()const { return selected; };
void move(int xoff, int yoff);
int getSelectedLine(void)const {return exit_pressed ? -1 : selected;};
@@ -584,6 +599,7 @@ class CMenuWidget : public CMenuTarget
void enableFade(bool _enable) { fade = _enable; };
void enableSaveScreen(bool enable);
void paintHint(int num);
void paintHint(){hint_painted = false;}
enum
{
MENU_POS_CENTER ,