neutrino menu classes: code reduced

- removed double codes for painting items, more will comming soon

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@1044 e54a6e83-5905-42d5-8d5c-058d10e6a962


Origin commit data
------------------
Branch: ni/coolstream
Commit: 5e83dabea2
Author: Thilo Graf <dbt@novatux.de>
Date: 2011-01-26 (Wed, 26 Jan 2011)

Origin message was:
------------------
*neutrino menu classes: code reduced
- removed double codes for painting items, more will comming soon

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@1044 e54a6e83-5905-42d5-8d5c-058d10e6a962


------------------
This commit was generated by Migit
This commit is contained in:
2011-01-26 11:03:57 +00:00
parent ccf5780bf7
commit ebeafb893d
3 changed files with 91 additions and 127 deletions

View File

@@ -64,7 +64,14 @@ CMenuForwarder * const GenericMenuCancel = &CGenericMenuCancel;
CMenuForwarder * const GenericMenuNext = &CGenericMenuNext; CMenuForwarder * const GenericMenuNext = &CGenericMenuNext;
CMenuItem::CMenuItem()
{
x = -1;
directKey = CRCInput::RC_nokey;
iconName = "";
can_arrow = false;
used = false;
}
void CMenuItem::init(const int X, const int Y, const int DX, const int OFFX) void CMenuItem::init(const int X, const int Y, const int DX, const int OFFX)
{ {
@@ -72,6 +79,7 @@ void CMenuItem::init(const int X, const int Y, const int DX, const int OFFX)
y = Y; y = Y;
dx = DX; dx = DX;
offx = OFFX; offx = OFFX;
name_start_x = x + offx + 15;
} }
void CMenuItem::setActive(const bool Active) void CMenuItem::setActive(const bool Active)
@@ -114,34 +122,60 @@ void CMenuItem::setItemColors(const bool select_mode, const fb_pixel_t &def_col
} }
void CMenuItem::paintItemBackground (const bool select_mode, const int &item_x, const int &item_y, const int &width, const int &height) void CMenuItem::paintItemBackground (const bool select_mode, /*const int &item_x, const int &item_y, const int &width,*/ const int &height)
{ {
CFrameBuffer *frameBuffer = CFrameBuffer::getInstance(); CFrameBuffer *frameBuffer = CFrameBuffer::getInstance();
if(select_mode) if(select_mode)
frameBuffer->paintBoxRel(item_x, item_y, width, height, item_bgcolor, RADIUS_LARGE); frameBuffer->paintBoxRel(x, y, dx, height, item_bgcolor, RADIUS_LARGE);
//else if(last) ?? Why do we need this? //else if(last) ?? Why do we need this?
//frameBuffer->paintBoxRel(item_x, item_y, width, height, i_bgcolor, RADIUS_LARGE, CORNER_BOTTOM); //FIXME //frameBuffer->paintBoxRel(x, y, dx, height, i_bgcolor, RADIUS_LARGE, CORNER_BOTTOM); //FIXME
else else
frameBuffer->paintBoxRel(item_x, item_y, width, height, item_bgcolor); frameBuffer->paintBoxRel(x, y, dx, height, item_bgcolor);
} }
void CMenuItem::paintItemCaption(const bool select_mode, const int &height, const char * left_text, const char * right_text)
{
if (select_mode)
{
char str[256];
void CMenuItem::paintItem(const bool select_mode, int &start_x, int &start_y, int &width, int &height) if (right_text != NULL)
{
snprintf(str, 255, "%s %s", left_text, right_text);
CVFD::getInstance()->showMenuText(0, str, -1, true);
}
else
CVFD::getInstance()->showMenuText(0, left_text, -1, true);
}
//left text
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(name_start_x, y+ height, dx- (name_start_x - x), left_text, item_color, 0, true); // UTF-8
//right text
if (right_text != NULL)
{
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) + 10, x + dx - stringwidth - 10); //+ offx
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposOption, y+height,dx- (stringstartposOption- x), right_text, item_color, 0, true);
}
}
void CMenuItem::paintItem(const bool select_mode, /*int &start_x, int &start_y, int &width,*/ int &height)
{ {
// //set colors // //set colors
// setItemColors(select_mode); // setItemColors(select_mode);
//paint item background //paint item background
paintItemBackground(select_mode, start_x, start_y, width, height); paintItemBackground(select_mode, /*start_x, start_y, width,*/ height);
} }
void CMenuItem::paintItemButton(const int startX, const int frame_height, const bool select_mode, const std::string &icon_Name, const bool icon_centered) void CMenuItem::paintItemButton(/*const int frame_height, */const bool select_mode, const std::string &icon_Name, const bool icon_centered)
{ {
CFrameBuffer *frameBuffer = CFrameBuffer::getInstance(); CFrameBuffer *frameBuffer = CFrameBuffer::getInstance();
bool selected = select_mode; bool selected = select_mode;
int height = frame_height; int height = getHeight();/*frame_height;*/
bool icon_painted = false; bool icon_painted = false;
bool centered = icon_centered; bool centered = icon_centered;
@@ -176,7 +210,7 @@ void CMenuItem::paintItemButton(const int startX, const int frame_height, const
int m_icon_h = h; int m_icon_h = h;
int icon_x = 0; int icon_x = 0;
int icon_start_x = (x+(startX-x)/*/2*/); //here starts the left part of caption itemtext, we need the the left space to paint the icon in it int icon_start_x = x+10 /*x+(name_start_x-x)*/;
//get data of number icon and paint //get data of number icon and paint
if (!icon_name.empty()) if (!icon_name.empty())
@@ -191,10 +225,10 @@ void CMenuItem::paintItemButton(const int startX, const int frame_height, const
if (!centered) if (!centered)
centered = (icon_name == NEUTRINO_ICON_BUTTON_OKAY || icon_name == NEUTRINO_ICON_BUTTON_HELP || icon_name == NEUTRINO_ICON_BUTTON_HOME || icon_name == NEUTRINO_ICON_BUTTON_RIGHT); centered = (icon_name == NEUTRINO_ICON_BUTTON_OKAY || icon_name == NEUTRINO_ICON_BUTTON_HELP || icon_name == NEUTRINO_ICON_BUTTON_HOME || icon_name == NEUTRINO_ICON_BUTTON_RIGHT);
if (centered/* || icon_name == NEUTRINO_ICON_BUTTON_OKAY || icon_name == NEUTRINO_ICON_BUTTON_HELP || icon_name == NEUTRINO_ICON_BUTTON_HOME*/) if (centered)
icon_x = x+ ((icon_start_x-x)/2) - (icon_w/2); //centered icon_x = x+ ((icon_start_x-x)/2) - (icon_w/2); //centered
else else
icon_x = icon_start_x - ((icon_w+m_icon_w)/*/2*/); icon_x = icon_start_x/* - ((icon_w+m_icon_w))*/;
icon_painted = frameBuffer->paintIcon(icon_name, icon_x, y+ ((height/2- icon_h/2)) ); icon_painted = frameBuffer->paintIcon(icon_name, icon_x, y+ ((height/2- icon_h/2)) );
} }
@@ -207,12 +241,6 @@ void CMenuItem::paintItemButton(const int startX, const int frame_height, const
//paint only number if no icon was painted and keyval is numeric //paint only number if no icon was painted and keyval is numeric
if (CRCInput::isNumeric(directKey) && !icon_painted) if (CRCInput::isNumeric(directKey) && !icon_painted)
{ {
// unsigned char i_color = COL_MENUCONTENT;
// if (selected)
// i_color = COL_MENUCONTENTSELECTED;
// if (!active)
// i_color = COL_MENUCONTENTINACTIVE;
number_w = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNELLIST_NUMBER]->getRenderWidth(CRCInput::getKeyName(directKey)); number_w = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNELLIST_NUMBER]->getRenderWidth(CRCInput::getKeyName(directKey));
number_x = icon_start_x - ((number_w+m_icon_w)/*/2*/); number_x = icon_start_x - ((number_w+m_icon_w)/*/2*/);
@@ -902,32 +930,20 @@ int CMenuOptionNumberChooser::paint(bool selected, bool /*last*/)
else else
l_option = g_Locale->getText(localized_value_name); l_option = g_Locale->getText(localized_value_name);
int stringwidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(l_option, true); // UTF-8 const char * l_optionName = (optionString != NULL) ? optionString : g_Locale->getText(optionName);
int stringstartposName = x + offx + 10;
int stringstartposOption = x + dx - stringwidth - 10; //+ offx
//set colors //set colors
setItemColors(selected); setItemColors(selected);
//paint item //paint item
paintItem(selected, x, y, dx, height); paintItem(selected, height);
//paint item icon //paint item icon
paintItemButton(stringstartposName, height, selected, NEUTRINO_ICON_BUTTON_OKAY); paintItemButton(selected, NEUTRINO_ICON_BUTTON_OKAY);
const char * l_optionName = (optionString != NULL) ? optionString : g_Locale->getText(optionName); //paint text
paintItemCaption(selected, height , l_optionName, l_option);
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposName, y+height,dx- (stringstartposName - x), l_optionName, item_color, 0, true); // UTF-8
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposOption, y+height,dx- (stringstartposOption - x), l_option, item_color, 0, true); // UTF-8
if (selected)
{
char str[256];
snprintf(str, 255, "%s %s", l_optionName, l_option);
CVFD::getInstance()->showMenuText(0, str, -1, true);
//CVFD::getInstance()->showMenuText(0, l_optionName, -1, true); // UTF-8
//CVFD::getInstance()->showMenuText(1, l_option, -1, true); // UTF-8
}
return y+height; return y+height;
} }
@@ -1110,7 +1126,9 @@ int CMenuOptionChooser::paint( bool selected , bool /*last*/)
break; break;
} }
} }
if(l_option == NULL) {
if(l_option == NULL)
{
*optionValue = options[0].key; *optionValue = options[0].key;
option = options[0].value; option = options[0].value;
if(options[0].valname != 0) if(options[0].valname != 0)
@@ -1119,30 +1137,17 @@ int CMenuOptionChooser::paint( bool selected , bool /*last*/)
l_option = g_Locale->getText(option); l_option = g_Locale->getText(option);
} }
int stringwidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(l_option, true); // UTF-8
int stringstartposName = x + offx + 10;
int stringstartposOption = x + dx - stringwidth - 10; //+ offx
//set colors //set colors
setItemColors(selected); setItemColors(selected);
//paint item //paint item
paintItem(selected, x, y, dx, height); paintItem(selected, /*x, y, dx,*/ height);
//paint item icon //paint item icon
paintItemButton(stringstartposName, height, selected, NEUTRINO_ICON_BUTTON_OKAY); paintItemButton(/*height, */selected, NEUTRINO_ICON_BUTTON_OKAY);
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposName, y+height,dx- (stringstartposName - x), optionNameString.c_str(), item_color, 0, true); // UTF-8 //paint text
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposOption, y+height,dx- (stringstartposOption - x), l_option, item_color, 0, true); // UTF-8 paintItemCaption(selected, height , optionNameString.c_str(), l_option);
if (selected)
{
char str[256];
snprintf(str, 255, "%s %s", optionNameString.c_str(), l_option);
CVFD::getInstance()->showMenuText(0, str, -1, true);
//CVFD::getInstance()->showMenuText(0, optionNameString.c_str(), -1, true); // UTF-8
//CVFD::getInstance()->showMenuText(1, l_option, -1, true); // UTF-8
}
return y+height; return y+height;
} }
@@ -1259,32 +1264,18 @@ int CMenuOptionStringChooser::exec(CMenuTarget* parent)
int CMenuOptionStringChooser::paint( bool selected, bool /*last*/ ) int CMenuOptionStringChooser::paint( bool selected, bool /*last*/ )
{ {
const char * l_optionName = g_Locale->getText(optionName); const char * l_optionName = g_Locale->getText(optionName);
int optionwidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(l_optionName, true);
//int stringwidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(optionValue, true);
int stringstartposName = x + offx + 10;
//int stringstartposOption = x + dx - stringwidth - 10; //+ offx
int stringstartposOption = x + offx + 10 + 10 + optionwidth;
//set colors //set colors
setItemColors(selected); setItemColors(selected);
//paint item //paint item
paintItem(selected, x, y, dx, height); paintItem(selected, height);
//paint item icon //paint item icon
paintItemButton(stringstartposName, height, selected, NEUTRINO_ICON_BUTTON_OKAY); paintItemButton(selected, NEUTRINO_ICON_BUTTON_OKAY);
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposName, y+height, dx- (stringstartposName - x), l_optionName, item_color, 0, true); // UTF-8 //paint text
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposOption, y+height, dx- (stringstartposOption - x), optionValue, item_color, 0, true); paintItemCaption(selected, height , l_optionName, optionValue);
if (selected)
{
char str[256];
snprintf(str, 255, "%s %s", l_optionName, optionValue);
CVFD::getInstance()->showMenuText(0, str, -1, true);
//CVFD::getInstance()->showMenuText(0, l_optionName, -1, true); // UTF-8
//CVFD::getInstance()->showMenuText(1, optionValue);
}
return y+height; return y+height;
} }
@@ -1346,11 +1337,9 @@ int CMenuOptionLanguageChooser::paint( bool selected, bool /*last*/ )
setItemColors(selected); setItemColors(selected);
//paint item //paint item
paintItem(selected, x, y, dx, height); paintItem(selected, height);
int stringstartposOption = x + offx + 10; paintItemButton( selected, iconName, true);
paintItemButton(stringstartposOption, height, selected, iconName, true);
//convert first letter to large //convert first letter to large
string s_optionValue = static_cast<std::string> (optionValue); string s_optionValue = static_cast<std::string> (optionValue);
@@ -1359,12 +1348,8 @@ int CMenuOptionLanguageChooser::paint( bool selected, bool /*last*/ )
s = toupper(s_optionValue[0]); s = toupper(s_optionValue[0]);
s_optionValue.replace(0, 1, s); s_optionValue.replace(0, 1, s);
//paint item string //paint text
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposOption, y+height,dx- (stringstartposOption - x), s_optionValue, item_color); paintItemCaption(selected, height , s_optionValue.c_str());
//show in vfd
if (selected)
CVFD::getInstance()->showMenuText(1, s_optionValue.c_str());
return y+height; return y+height;
} }
@@ -1470,41 +1455,20 @@ int CMenuForwarder::paint(bool selected, bool /*last*/)
{ {
int height = getHeight(); int height = getHeight();
const char * l_text = getName(); const char * l_text = getName();
int stringstartposX = x + offx + 10;
const char * option_text = getOption(); const char * option_text = getOption();
if (selected)
{
char str[256];
if (option_text != NULL) {
snprintf(str, 255, "%s %s", l_text, option_text);
CVFD::getInstance()->showMenuText(0, str, -1, true);
} else
CVFD::getInstance()->showMenuText(0, l_text, -1, true);
}
//set colors //set colors
setItemColors(selected); setItemColors(selected);
//paint item //paint item
paintItem(selected, x, y, dx, height); paintItem(selected, height);
//paint icon //paint icon
paintItemButton(stringstartposX, height, selected); paintItemButton(selected);
//caption //caption
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposX, y+ height, dx- (stringstartposX - x), l_text, item_color, 0, true); // UTF-8 paintItemCaption(selected, height, l_text, option_text);
//option text
if (option_text != NULL)
{
int stringwidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(option_text, true);
int stringstartposOption = std::max(stringstartposX + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(l_text, true) + 10,
x + dx - stringwidth - 10); //+ offx
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposOption, y+height,dx- (stringstartposOption- x), option_text, item_color, 0, true);
}
return y+ height; return y+ height;
} }
@@ -1615,7 +1579,7 @@ int CMenuSeparator::paint(bool selected, bool /*last*/)
/* if no alignment is specified, align centered */ /* if no alignment is specified, align centered */
if (type & ALIGN_LEFT) if (type & ALIGN_LEFT)
stringstartposX = x + (!SUB_HEAD ? 20 : 20 +18); stringstartposX = x + (!SUB_HEAD ? name_start_x : 20 +18);
else if (type & ALIGN_RIGHT) else if (type & ALIGN_RIGHT)
stringstartposX = x + dx - stringwidth - 20; stringstartposX = x + dx - stringwidth - 20;
else /* ALIGN_CENTER */ else /* ALIGN_CENTER */

View File

@@ -78,7 +78,7 @@ class CMenuTarget
class CMenuItem class CMenuItem
{ {
protected: protected:
int x, y, dx, offx; int x, y, dx, offx, name_start_x;
bool used; bool used;
public: public:
@@ -93,14 +93,7 @@ class CMenuItem
fb_pixel_t item_bgcolor; fb_pixel_t item_bgcolor;
CMenuItem() CMenuItem();
{
x = -1;
directKey = CRCInput::RC_nokey;
iconName = "";
can_arrow = false;
used = false;
}
virtual ~CMenuItem(){} virtual ~CMenuItem(){}
virtual void isUsed(void) virtual void isUsed(void)
@@ -129,17 +122,19 @@ class CMenuItem
} }
virtual void setActive(const bool Active); virtual void setActive(const bool Active);
virtual void paintItemButton(const int startX, const int frame_height, const bool select_mode, const std::string& icon_Name = NEUTRINO_ICON_BUTTON_RIGHT, const bool icon_centered = false); virtual void paintItemButton(/*const int frame_height, */const bool select_mode, const std::string& icon_Name = NEUTRINO_ICON_BUTTON_RIGHT, const bool icon_centered = false);
virtual void setItemColors(const bool select_mode , const fb_pixel_t &def_color = COL_MENUCONTENT, const fb_pixel_t &def_bgcolor = COL_MENUCONTENT_PLUS_0, virtual void setItemColors(const bool select_mode , const fb_pixel_t &def_color = COL_MENUCONTENT, const fb_pixel_t &def_bgcolor = COL_MENUCONTENT_PLUS_0,
const fb_pixel_t &def_sel_color = COL_MENUCONTENTSELECTED, const fb_pixel_t &def_sel_bgcolor = COL_MENUCONTENTSELECTED_PLUS_0, const fb_pixel_t &def_sel_color = COL_MENUCONTENTSELECTED, const fb_pixel_t &def_sel_bgcolor = COL_MENUCONTENTSELECTED_PLUS_0,
const fb_pixel_t &def_inactiv_color = COL_MENUCONTENTINACTIVE, const fb_pixel_t &def_inactiv_bgcolor = COL_MENUCONTENTINACTIVE_PLUS_0); const fb_pixel_t &def_inactiv_color = COL_MENUCONTENTINACTIVE, const fb_pixel_t &def_inactiv_bgcolor = COL_MENUCONTENTINACTIVE_PLUS_0);
virtual void paintItemBackground (const bool select_mode, const int &x, const int &y, const int &width, const int &height); virtual void paintItemBackground (const bool select_mode, const int &height);
virtual void paintItem(const bool select_mode, int &start_x, int &start_y, int &width, int &height); virtual void paintItem(const bool select_mode, int &height);
virtual void setItemButton(const std::string& icon_Name, const bool is_select_button = false); virtual void setItemButton(const std::string& icon_Name, const bool is_select_button = false);
virtual void paintItemCaption(const bool select_mode, const int &height, const char * left_text=NULL, const char * right_text=NULL);
}; };
class CMenuSeparator : public CMenuItem class CMenuSeparator : public CMenuItem

View File

@@ -727,6 +727,7 @@ int CTPSelectHandler::exec(CMenuTarget* parent, const std::string &/*actionkey*/
CMenuWidget* menu = new CMenuWidget(LOCALE_SCANTS_SELECT_TP, NEUTRINO_ICON_SETTINGS); CMenuWidget* menu = new CMenuWidget(LOCALE_SCANTS_SELECT_TP, NEUTRINO_ICON_SETTINGS);
CMenuSelectorTarget * selector = new CMenuSelectorTarget(&select); CMenuSelectorTarget * selector = new CMenuSelectorTarget(&select);
menu->addIntroItems(NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, CMenuWidget::BTN_TYPE_CANCEL); //add cancel button, ensures that we have enought space left from item caption
i = 0; i = 0;
for (tI = select_transponders.begin(); tI != select_transponders.end(); tI++) { for (tI = select_transponders.begin(); tI != select_transponders.end(); tI++) {
t_satellite_position satpos = GET_SATELLITEPOSITION_FROM_TRANSPONDER_ID(tI->first) & 0xFFF; t_satellite_position satpos = GET_SATELLITEPOSITION_FROM_TRANSPONDER_ID(tI->first) & 0xFFF;
@@ -758,7 +759,11 @@ int CTPSelectHandler::exec(CMenuTarget* parent, const std::string &/*actionkey*/
} }
//menu->addItem(new CMenuForwarderNonLocalized(buf, true, NULL, selector, cnt), old_selected == i); //menu->addItem(new CMenuForwarderNonLocalized(buf, true, NULL, selector, cnt), old_selected == i);
menu->addItem(new CMenuForwarderNonLocalized(buf, true, NULL, selector, cnt, CRCInput::RC_nokey, NULL), false);
CMenuForwarderNonLocalized * ts_item = new CMenuForwarderNonLocalized(buf, true, NULL, selector, NULL, CRCInput::RC_nokey, NULL)/*, false*/;
ts_item->setItemButton(NEUTRINO_ICON_BUTTON_OKAY, true);
menu->addItem(ts_item);
tmplist.insert(std::pair <int, transponder>(i, tI->second)); tmplist.insert(std::pair <int, transponder>(i, tI->second));
i++; i++;
} }