CComponents: rework some members

*rename col_text to class relevant names,
 col_text is already defined in class CComponents InfoBox and
 its easy to confuse member names
*add member printItemBox() and
 move calculateElements() into CComponentsItemBox and use it
 in print() and refreshElement()
This commit is contained in:
2012-08-30 22:03:10 +02:00
parent cd4cb6645e
commit 806d840c86
2 changed files with 163 additions and 155 deletions

View File

@@ -241,7 +241,7 @@ class CComponentsInfoBox : public CComponentsContainer
void paintText(); void paintText();
void initVarInfobox(); void initVarInfobox();
std::string pic_name; std::string pic_name;
fb_pixel_t col_text; fb_pixel_t ibox_col_text;
public: public:
CComponentsInfoBox(); CComponentsInfoBox();
CComponentsInfoBox( const int x_pos, const int y_pos, const int w, const int h, CComponentsInfoBox( const int x_pos, const int y_pos, const int w, const int h,
@@ -256,7 +256,7 @@ class CComponentsInfoBox : public CComponentsContainer
void setText(neutrino_locale_t locale_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL); void setText(neutrino_locale_t locale_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL);
inline void setTextMode(const int mode){text_mode = mode;};//see textbox.h for possible modes inline void setTextMode(const int mode){text_mode = mode;};//see textbox.h for possible modes
inline void setTextFont(Font* font_text){font = font_text;}; inline void setTextFont(Font* font_text){font = font_text;};
inline void setTextColor(fb_pixel_t color_text){ col_text = color_text;}; inline void setTextColor(fb_pixel_t color_text){ ibox_col_text = color_text;};
inline void setSpaceOffset(const int offset){x_offset = offset;}; inline void setSpaceOffset(const int offset){x_offset = offset;};
inline void setPicture(const std::string& picture_name){pic_name = picture_name;}; inline void setPicture(const std::string& picture_name){pic_name = picture_name;};
void removeLineBreaks(std::string& str); void removeLineBreaks(std::string& str);
@@ -331,7 +331,7 @@ class CComponentsItemBox : public CComponentsContainer
int digit_offset, digit_h; int digit_offset, digit_h;
bool paintElements; bool paintElements;
bool onlyOneTextElement; bool onlyOneTextElement;
fb_pixel_t col_text; fb_pixel_t it_col_text;
Font* font_text; Font* font_text;
int hMax; int hMax;
bool has_TextElement; bool has_TextElement;
@@ -345,15 +345,15 @@ class CComponentsItemBox : public CComponentsContainer
void initVarItemBox(); void initVarItemBox();
void calSizeOfElements(); void calSizeOfElements();
void calPositionOfElements(); void calPositionOfElements();
void paintItemBox(bool do_save_bg = CC_SAVE_SCREEN_YES);
void calculateElements();
public: public:
CComponentsItemBox(); CComponentsItemBox();
virtual ~CComponentsItemBox(); virtual ~CComponentsItemBox();
inline virtual void setTextFont(Font* font){font_text = font;}; inline virtual void setTextFont(Font* font){font_text = font;};
inline virtual void setTextColor(fb_pixel_t color_text){ col_text = color_text;}; inline virtual void setTextColor(fb_pixel_t color_text){ it_col_text = color_text;};
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
virtual bool addElement(int align, int type, const std::string& element="", size_t *index=NULL); virtual bool addElement(int align, int type, const std::string& element="", size_t *index=NULL);
virtual void refreshElement(size_t index, const std::string& element); virtual void refreshElement(size_t index, const std::string& element);
@@ -370,7 +370,7 @@ class CComponentsTitleBar : public CComponentsItemBox
std::string tb_s_text; std::string tb_s_text;
neutrino_locale_t tb_locale_text; neutrino_locale_t tb_locale_text;
int tb_text_align; int tb_text_align;
bool addText(); bool addText();
void initVarTitleBar(); void initVarTitleBar();
@@ -382,8 +382,8 @@ class CComponentsTitleBar : public CComponentsItemBox
fb_pixel_t color_text = COL_MENUHEAD, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0); fb_pixel_t color_text = COL_MENUHEAD, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0);
CComponentsTitleBar( const int x_pos, const int y_pos, const int w, const int h, neutrino_locale_t locale_text = NONEXISTANT_LOCALE, const int text_alignment = CC_ALIGN_LEFT, CComponentsTitleBar( const int x_pos, const int y_pos, const int w, const int h, neutrino_locale_t locale_text = NONEXISTANT_LOCALE, const int text_alignment = CC_ALIGN_LEFT,
fb_pixel_t color_text = COL_MENUHEAD, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0); fb_pixel_t color_text = COL_MENUHEAD, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0);
void calculateElements(); void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
}; };

View File

@@ -288,7 +288,7 @@ CComponentsInfoBox::CComponentsInfoBox()
text = NULL; text = NULL;
text_mode = CTextBox::AUTO_WIDTH; text_mode = CTextBox::AUTO_WIDTH;
font = NULL; font = NULL;
col_text = COL_MENUCONTENT; ibox_col_text = COL_MENUCONTENT;
} }
CComponentsInfoBox::CComponentsInfoBox(const int x_pos, const int y_pos, const int w, const int h, CComponentsInfoBox::CComponentsInfoBox(const int x_pos, const int y_pos, const int w, const int h,
@@ -313,7 +313,7 @@ CComponentsInfoBox::CComponentsInfoBox(const int x_pos, const int y_pos, const i
text = info_text; text = info_text;
text_mode = mode; text_mode = mode;
font = font_text; font = font_text;
col_text = color_text; ibox_col_text = color_text;
} }
CComponentsInfoBox::~CComponentsInfoBox() CComponentsInfoBox::~CComponentsInfoBox()
@@ -395,7 +395,7 @@ void CComponentsInfoBox::paintText()
//set properties //set properties
textbox->setTextFont(font); textbox->setTextFont(font);
textbox->movePosition(box->iX, box->iY); textbox->movePosition(box->iX, box->iY);
textbox->setTextColor(col_text); textbox->setTextColor(ibox_col_text);
//set text //set text
string new_text = static_cast <string> (text); string new_text = static_cast <string> (text);
@@ -823,7 +823,7 @@ void CComponentsItemBox::initVarItemBox()
initVarContainer(); initVarContainer();
//CComponentsItemBox //CComponentsItemBox
col_text = COL_MENUCONTENT; it_col_text = COL_MENUCONTENT;
hSpacer = 2; hSpacer = 2;
hOffset = 4; hOffset = 4;
vOffset = 1; vOffset = 1;
@@ -959,6 +959,7 @@ void CComponentsItemBox::refreshElement(size_t index, const std::string& element
default: default:
break; break;
} }
calculateElements();
} }
void CComponentsItemBox::paintElement(size_t index, bool newElement) void CComponentsItemBox::paintElement(size_t index, bool newElement)
@@ -1015,13 +1016,13 @@ void CComponentsItemBox::paintElement(size_t index, bool newElement)
textbox->enableBackgroundPaint(false); textbox->enableBackgroundPaint(false);
textbox->setTextFont(font_text); textbox->setTextFont(font_text);
textbox->movePosition(box->iX, box->iY); textbox->movePosition(box->iX, box->iY);
textbox->setTextColor(col_text); textbox->setTextColor(it_col_text);
if (textbox->setText(&v_element_data[index].element)) if (textbox->setText(&v_element_data[index].element))
textbox->paint(); textbox->paint();
break; break;
case CC_ITEMBOX_CLOCK: case CC_ITEMBOX_CLOCK:
font_text->RenderString(v_element_data[index].x, v_element_data[index].y, v_element_data[index].width, font_text->RenderString(v_element_data[index].x, v_element_data[index].y, v_element_data[index].width,
v_element_data[index].element.c_str(), col_text); v_element_data[index].element.c_str(), it_col_text);
break; break;
default: default:
break; break;
@@ -1119,146 +1120,7 @@ void CComponentsItemBox::calPositionOfElements()
} }
} }
void CComponentsItemBox::paint(bool do_save_bg) void CComponentsItemBox::calculateElements()
{
// paint background
paintInit(do_save_bg);
if ((v_element_data.empty()) || (!paintElements))
return;
// paint elements
for (size_t i = 0; i < v_element_data.size(); i++)
paintElement(i);
}
void CComponentsItemBox::clearTitlebar()
{
clearElements();
paintElements = false;
paint(false);
paintElements = true;
}
//-------------------------------------------------------------------------------------------------------
//sub class CComponentsTitleBar from CComponentsItemBox
CComponentsTitleBar::CComponentsTitleBar()
{
//CComponentsTitleBar
initVarTitleBar();
}
CComponentsTitleBar::CComponentsTitleBar(const int x_pos, const int y_pos, const int w, const int h, const char* c_text, const int text_alignment,
fb_pixel_t color_text, fb_pixel_t color_body)
{
//CComponentsItemBox
initVarTitleBar();
//CComponents
x = x_pos;
y = y_pos;
height = h;
width = w;
col_body = color_body;
//CComponentsTitleBar
col_text = color_text;
tb_c_text = c_text;
tb_text_align = text_alignment;
if (addText())
calculateElements();
}
CComponentsTitleBar::CComponentsTitleBar(const int x_pos, const int y_pos, const int w, const int h, const string& s_text, const int text_alignment,
fb_pixel_t color_text, fb_pixel_t color_body)
{
//CComponentsItemBox
initVarTitleBar();
//CComponents
x = x_pos;
y = y_pos;
height = h;
width = w;
col_body = color_body;
//CComponentsTitleBar
col_text = color_text;
tb_s_text = s_text;
tb_text_align = text_alignment;
if (addText())
calculateElements();
}
CComponentsTitleBar::CComponentsTitleBar(const int x_pos, const int y_pos, const int w, const int h, neutrino_locale_t locale_text, const int text_alignment,
fb_pixel_t color_text, fb_pixel_t color_body)
{
//CComponentsItemBox
initVarTitleBar();
//CComponents
x = x_pos;
y = y_pos;
height = h;
width = w;
col_body = color_body;
//CComponentsTitleBar
col_text = color_text;
tb_locale_text = locale_text;
tb_text_align = text_alignment;
if (addText())
calculateElements();
}
bool CComponentsTitleBar::addText()
{
if (tb_c_text){
addElement (tb_text_align, CC_ITEMBOX_TEXT, tb_c_text);
return true;
}
else if (!tb_s_text.empty()){
addElement (tb_text_align, CC_ITEMBOX_TEXT, tb_s_text);
return true;
}
else if (tb_locale_text != NONEXISTANT_LOCALE){
addElement (tb_text_align, CC_ITEMBOX_TEXT, g_Locale->getText(tb_locale_text));
return true;
}
else
return false;
}
void CComponentsTitleBar::initVarTitleBar()
{
//CComponentsItemBox
initVarItemBox();
onlyOneTextElement = true;
font_text = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE];
col_text = COL_MENUHEAD;
//CComponents
x = 0;
y = 0;
height = font_text->getHeight() + 2*hSpacer;
width = frameBuffer->getScreenWidth(true);;
col_body = COL_MENUHEAD_PLUS_0;
corner_type = CORNER_TOP;
corner_rad = RADIUS_LARGE;
//CComponentsTitleBar
tb_text_align = CC_ALIGN_LEFT;
tb_c_text = NULL;
tb_s_text = "";
tb_locale_text = NONEXISTANT_LOCALE;
}
void CComponentsTitleBar::calculateElements()
{ {
if (v_element_data.empty()) if (v_element_data.empty())
return; return;
@@ -1299,3 +1161,149 @@ void CComponentsTitleBar::calculateElements()
calPositionOfElements(); calPositionOfElements();
} }
void CComponentsItemBox::paintItemBox(bool do_save_bg)
{
// paint background
paintInit(do_save_bg);
if ((v_element_data.empty()) || (!paintElements))
return;
// paint elements
for (size_t i = 0; i < v_element_data.size(); i++)
paintElement(i);
}
void CComponentsItemBox::clearTitlebar()
{
clearElements();
paintElements = false;
paint(false);
paintElements = true;
}
//-------------------------------------------------------------------------------------------------------
//sub class CComponentsTitleBar from CComponentsItemBox
CComponentsTitleBar::CComponentsTitleBar()
{
//CComponentsTitleBar
initVarTitleBar();
}
CComponentsTitleBar::CComponentsTitleBar(const int x_pos, const int y_pos, const int w, const int h, const char* c_text, const int text_alignment,
fb_pixel_t color_text, fb_pixel_t color_body)
{
//CComponentsItemBox
initVarTitleBar();
it_col_text = color_text;
//CComponents
x = x_pos;
y = y_pos;
height = h;
width = w;
col_body = color_body;
//CComponentsTitleBar
tb_c_text = c_text;
tb_text_align = text_alignment;
if (addText())
calculateElements();
}
CComponentsTitleBar::CComponentsTitleBar(const int x_pos, const int y_pos, const int w, const int h, const string& s_text, const int text_alignment,
fb_pixel_t color_text, fb_pixel_t color_body)
{
//CComponentsItemBox
initVarTitleBar();
it_col_text = color_text;
//CComponents
x = x_pos;
y = y_pos;
height = h;
width = w;
col_body = color_body;
//CComponentsTitleBar
tb_s_text = s_text;
tb_text_align = text_alignment;
if (addText())
calculateElements();
}
CComponentsTitleBar::CComponentsTitleBar(const int x_pos, const int y_pos, const int w, const int h, neutrino_locale_t locale_text, const int text_alignment,
fb_pixel_t color_text, fb_pixel_t color_body)
{
//CComponentsItemBox
initVarTitleBar();
it_col_text = color_text;
//CComponents
x = x_pos;
y = y_pos;
height = h;
width = w;
col_body = color_body;
//CComponentsTitleBar
tb_locale_text = locale_text;
tb_text_align = text_alignment;
if (addText())
calculateElements();
}
bool CComponentsTitleBar::addText()
{
if (tb_c_text){
addElement (tb_text_align, CC_ITEMBOX_TEXT, tb_c_text);
return true;
}
else if (!tb_s_text.empty()){
addElement (tb_text_align, CC_ITEMBOX_TEXT, tb_s_text);
return true;
}
else if (tb_locale_text != NONEXISTANT_LOCALE){
addElement (tb_text_align, CC_ITEMBOX_TEXT, g_Locale->getText(tb_locale_text));
return true;
}
else
return false;
}
void CComponentsTitleBar::initVarTitleBar()
{
//CComponentsItemBox
initVarItemBox();
onlyOneTextElement = true;
font_text = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE];
it_col_text = COL_MENUHEAD;
//CComponents
x = 0;
y = 0;
height = font_text->getHeight() + 2*hSpacer;
width = frameBuffer->getScreenWidth(true);;
col_body = COL_MENUHEAD_PLUS_0;
corner_type = CORNER_TOP;
corner_rad = RADIUS_LARGE;
//CComponentsTitleBar
tb_text_align = CC_ALIGN_LEFT;
tb_c_text = NULL;
tb_s_text = "";
tb_locale_text = NONEXISTANT_LOCALE;
}
void CComponentsTitleBar::paint(bool do_save_bg)
{
calculateElements();
paintItemBox(do_save_bg);
}