diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index 03bd8db8d..68ff7841f 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -32,7 +32,7 @@ #include #include -// #define DEBUG_CC +//#define DEBUG_CC class CComponents { @@ -185,8 +185,8 @@ class CComponentsText : public CComponentsItem fb_pixel_t ct_col_text; int ct_text_mode; //see textbox.h for possible modes - std::string ct_text; - bool ct_text_sent, ct_paint_textbg; + std::string ct_text, ct_old_text; + bool ct_text_sent, ct_paint_textbg, ct_force_text_paint; static std::string iToString(int int_val); //helper to convert int to string @@ -202,21 +202,38 @@ class CComponentsText : public CComponentsItem fb_pixel_t color_text = COL_MENUCONTENT, fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); virtual ~CComponentsText(); - void hide(bool no_restore = false); - void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); - + //default members to paint a text box and hide painted text + //hide textbox + void hide(bool no_restore = false); + //paint text box, parameter do_save_bg: default = true, causes fill of backckrond pixel buffer + void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); + + //send options for text font (size and type), color and mode (allignment) virtual inline void setTextFont(Font* font_text){ct_font = font_text;}; virtual inline void setTextColor(fb_pixel_t color_text){ ct_col_text = color_text;}; - virtual inline void setTextMode(const int mode){ct_text_mode = mode;};//see textbox.h for possible modes + //see textbox.h for possible allignment modes + virtual inline void setTextMode(const int mode){ct_text_mode = mode;}; + + //send option to CTextBox object to paint background box behind text or not virtual inline void doPaintTextBoxBg(bool do_paintbox_bg){ ct_paint_textbg = do_paintbox_bg;}; - virtual void setText(const char* ctext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); + + //sets text mainly with string also possible with overloades members for loacales, const char and text file virtual void setText(const std::string& stext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); + + virtual void setText(const char* ctext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); virtual void setText(neutrino_locale_t locale_text, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); virtual void setText(const int digit, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); virtual bool setTextFromFile(const std::string& path_to_textfile, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); - virtual void removeLineBreaks(std::string& str); - //get a Text Box object, so it's possible to get access directly to its methods + //helper to remove linebreak chars from a string if needed + virtual void removeLineBreaks(std::string& str); + + //returns true, if text was changed + virtual bool textChanged(){return ct_old_text != ct_text;}; + //force paint of text even if text was changed or not + virtual void forceTextPaint(bool force_text_paint = true){ct_force_text_paint = force_text_paint;}; + + //gets the embedded CTextBox object, so it's possible to get access directly to its methods and properties virtual CTextBox* getCTextBoxObject() { return ct_textbox; }; }; diff --git a/src/gui/components/cc_item_text.cpp b/src/gui/components/cc_item_text.cpp index 6b7efcf9c..abf3ae89d 100644 --- a/src/gui/components/cc_item_text.cpp +++ b/src/gui/components/cc_item_text.cpp @@ -91,10 +91,12 @@ void CComponentsText::initVarText() ct_box = NULL; ct_textbox = NULL; ct_text = ""; + ct_old_text = ct_text; ct_text_mode = CTextBox::AUTO_WIDTH; ct_col_text = COL_MENUCONTENT; ct_text_sent = false; ct_paint_textbg = true; + ct_force_text_paint = false; } @@ -135,9 +137,9 @@ void CComponentsText::initCCText() ct_textbox->setWindowMaxDimensions(ct_box->iWidth, ct_box->iHeight); ct_textbox->setWindowMinDimensions(ct_box->iWidth, ct_box->iHeight); - //set text - string new_text = static_cast (ct_text); - ct_text_sent = ct_textbox->setText(&new_text, ct_box->iWidth); + //send text to CTextBox object, but paint text only if text has changed or force option is enabled + if ((ct_old_text != ct_text) || ct_force_text_paint) + ct_text_sent = ct_textbox->setText(&ct_text, ct_box->iWidth); #ifdef DEBUG_CC printf(" [CComponentsText] [%s - %d] init text: %s [x %d, y %d, h %d, w %d]\n", __FUNCTION__, __LINE__, ct_text.c_str(), ct_box->iX, ct_box->iY, height, width); #endif @@ -154,26 +156,10 @@ void CComponentsText::clearCCText() ct_textbox = NULL; } -void CComponentsText::setText(neutrino_locale_t locale_text, int mode, Font* font_text) -{ - ct_text = g_Locale->getText(locale_text); - ct_text_mode = mode; - ct_font = font_text; -#ifdef DEBUG_CC - printf(" [CComponentsText] [%s - %d] ct_text: %s \n", __FUNCTION__, __LINE__, ct_text.c_str()); -#endif -} - -void CComponentsText::setText(const char* ctext, const int mode, Font* font_text) -{ - setText((string)ctext, mode, font_text); -#ifdef DEBUG_CC - printf(" [CComponentsText] [%s - %d] text: %s \n", __FUNCTION__, __LINE__, ctext); -#endif -} void CComponentsText::setText(const std::string& stext, const int mode, Font* font_text) { + ct_old_text = ct_text; ct_text = stext; ct_text_mode = mode; ct_font = font_text; @@ -182,13 +168,21 @@ void CComponentsText::setText(const std::string& stext, const int mode, Font* fo #endif } +void CComponentsText::setText(neutrino_locale_t locale_text, int mode, Font* font_text) +{ + string stext = g_Locale->getText(locale_text); + setText(stext, mode, font_text); +} + +void CComponentsText::setText(const char* ctext, const int mode, Font* font_text) +{ + setText((string)ctext, mode, font_text); +} + void CComponentsText::setText(const int digit, const int mode, Font* font_text) { string s_digit = iToString(digit); setText(s_digit, mode, font_text); -#ifdef DEBUG_CC - printf(" [CComponentsText] [%s - %d] ct_text: %s \n", __FUNCTION__, __LINE__, ct_text.c_str()); -#endif } //set text lines directly from a file, returns true on succsess