From 2e6ac2420adc06d0c21292e7cac8f7a0650eae41 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Thu, 16 Aug 2012 17:37:29 +0200 Subject: [PATCH] CComponents: add text functionality into class CComponentsInfoBox() --- src/gui/components/cc.h | 24 +++++++++++- src/gui/components/components.cpp | 63 ++++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index 49b6027cd..24c8383d3 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -29,6 +29,7 @@ #include #include #include +#include "textbox.h" #include #include @@ -165,9 +166,30 @@ class CComponentsContainer : public CComponents #define INFO_BOX_Y_OFFSET 2 class CComponentsInfoBox : public CComponentsContainer { + private: + const char* text; + int text_mode; //see textbox.h for possible modes + Font* font; + CBox * box; + CTextBox * textbox; + + void paintText(); + void initVarInfobox(); + public: - CComponentsInfoBox( const int x_pos, const int y_pos, const int w, const int h, bool has_shadow = CC_SHADOW_ON, + CComponentsInfoBox( const int x_pos, const int y_pos, const int w, const int h, + const char* info_text = NULL, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL, + bool has_shadow = CC_SHADOW_OFF, 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); + + ~CComponentsInfoBox(); + + void setText(const char* info_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL){text = info_text; text_mode = mode, font = font_text;}; + void setText(const std::string info_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL){text = info_text.c_str(); text_mode = mode, font = font_text;}; + void setText(neutrino_locale_t locale_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL); + void setTextMode(const int mode){text_mode = mode;}; + void setTextFont(Font* font_text){font = font_text;}; + void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); }; class CComponentsShapeCircle : public CComponentsContainer diff --git a/src/gui/components/components.cpp b/src/gui/components/components.cpp index 0edd246ad..d632c92bf 100644 --- a/src/gui/components/components.cpp +++ b/src/gui/components/components.cpp @@ -260,25 +260,78 @@ void CComponentsContainer::syncSysColors() //------------------------------------------------------------------------------------------------------- //sub class CComponentsInfoBox from CComponentsContainer -CComponentsInfoBox::CComponentsInfoBox(const int x_pos, const int y_pos, const int w, const int h, bool has_shadow, fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) +CComponentsInfoBox::CComponentsInfoBox(const int x_pos, const int y_pos, const int w, const int h, + const char* info_text, const int mode, Font* font_text, + bool has_shadow, + fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) { + //CComponentsInfoBox + text = info_text; + text_mode = mode; + font = font_text; + //CComponents x = x_pos; y = y_pos; width = w; height = h; shadow = has_shadow; - shadow_w = SHADOW_OFFSET; col_frame = color_frame; col_body = color_body; col_shadow = color_shadow; - firstPaint = true; - v_fbdata.clear(); - bgMode = CC_BGMODE_PERMANENT; + initVarInfobox(); +} + +CComponentsInfoBox::~CComponentsInfoBox() +{ + + hide(); +// if (saved_screen.pixbuf) +// delete[] saved_screen.pixbuf; + delete textbox; + delete box; + clear(); +} + +void CComponentsInfoBox::initVarInfobox() +{ //CComponentsContainer corner_rad = RADIUS_LARGE; fr_thickness = 2; + + //CComponents + firstPaint = true; + v_fbdata.clear(); + bgMode = CC_BGMODE_PERMANENT; + shadow_w = SHADOW_OFFSET; + + //CComponentsInfoBox + box = NULL; + textbox = NULL; + +} + +void CComponentsInfoBox::setText(neutrino_locale_t locale_text, int mode, Font* font_text) +{ + text = g_Locale->getText(locale_text); + text_mode = mode; + font = font_text; +} + +void CComponentsInfoBox::paintText() +{ + box = new CBox( x+fr_thickness, y+fr_thickness, width-2*fr_thickness, height-2*fr_thickness); + textbox = new CTextBox(text, font, text_mode, box, col_body); + textbox->enableBackgroundPaint(false); + textbox->paint(); +} + +void CComponentsInfoBox::paint(bool do_save_bg) +{ + paintInit(do_save_bg); + if (text != NULL) + paintText(); } //-------------------------------------------------------------------------------------------------------