diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index b6a2e1b10..01b84298c 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -180,7 +180,7 @@ class CComponentsPicture : public CComponentsContainer void setPicturePaintBackground(bool paintBg){pic_paintBg = paintBg;}; void setPicture(const std::string& picture_name); void setPictureAlign(const int alignment); - + bool isPainted(){return pic_painted;}; void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); void getPictureSize(int *pwidth, int *pheight){*pwidth=pic_width; *pheight=pic_height;}; @@ -193,31 +193,35 @@ class CComponentsInfoBox : public CComponentsContainer private: const char* text; int text_mode; //see textbox.h for possible modes - int x_text; + int x_text, x_offset; Font* font; CBox * box; CTextBox * textbox; CComponentsPicture * pic; + std::string pic_default_name; void paintPicture(); void paintText(); void initVarInfobox(); std::string pic_name; - + fb_pixel_t col_text; public: 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 | CTextBox::AUTO_HIGH, 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); + 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); ~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 setText(const char* info_text, const int mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH, 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 | CTextBox::AUTO_HIGH, 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 | CTextBox::AUTO_HIGH, Font* font_text = NULL); + void setTextMode(const int mode){text_mode = mode;};//see textbox.h for possible modes void setTextFont(Font* font_text){font = font_text;}; + void setTextColor(fb_pixel_t color_text){ col_text = color_text;}; + void setSpaceOffset(const int offset){x_offset = offset;}; void setPicture(const std::string& picture_name){pic_name = picture_name;}; + void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); }; diff --git a/src/gui/components/components.cpp b/src/gui/components/components.cpp index 58c828aa5..73996a151 100644 --- a/src/gui/components/components.cpp +++ b/src/gui/components/components.cpp @@ -263,12 +263,14 @@ void CComponentsContainer::syncSysColors() 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) + fb_pixel_t color_text, fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) { //CComponentsInfoBox + initVarInfobox(); text = info_text; text_mode = mode; font = font_text; + col_text = color_text; //CComponents x = x_pos; @@ -280,7 +282,7 @@ CComponentsInfoBox::CComponentsInfoBox(const int x_pos, const int y_pos, const i col_body = color_body; col_shadow = color_shadow; - initVarInfobox(); + } CComponentsInfoBox::~CComponentsInfoBox() @@ -313,6 +315,7 @@ void CComponentsInfoBox::initVarInfobox() pic = NULL; pic_name = ""; x_text = x; + x_offset = 10; } @@ -325,31 +328,63 @@ void CComponentsInfoBox::setText(neutrino_locale_t locale_text, int mode, Font* void CComponentsInfoBox::paintPicture() { + //init and set icon paint position if (pic == NULL) - pic = new CComponentsPicture(x+fr_thickness+corner_rad, y+fr_thickness+corner_rad, ""); + pic = new CComponentsPicture(x+fr_thickness+x_offset, y+fr_thickness/*+y_offset*/, ""); + pic->setXPos(x+fr_thickness+x_offset); + pic->setYPos(y+fr_thickness); + + //define icon pic->setPicture(pic_name); - int pic_w = pic->getWidth(); - pic->setHeight(height-2*fr_thickness-2*corner_rad); + + //fit icon into infobox + pic->setHeight(height-2*fr_thickness); pic->setColorBody(col_body); + pic->paint(); - if (pic->isPainted()) - x_text = x+fr_thickness+pic_w+corner_rad; } void CComponentsInfoBox::paintText() -{ - box = new CBox( x_text+fr_thickness, y+fr_thickness, width-2*fr_thickness-(x_text-x), height-2*fr_thickness); - textbox = new CTextBox(text, font, text_mode, box, col_body); +{ + if (box == NULL) + box = new CBox(); + + //define text x position + x_text = x+fr_thickness+x_offset; + if (pic->isPainted()){ + int pic_w = pic->getWidth(); + x_text += pic_w+x_offset; + } + + box->iX = x_text; + box->iY = y+fr_thickness; + + //text width and height + box->iWidth = width-2*fr_thickness-(x_text-x); + box->iHeight = height-2*fr_thickness; + + //init textbox + if (textbox == NULL) + textbox = new CTextBox(text, font, text_mode, box, col_body); + + //set properties + textbox->movePosition(box->iX, box->iY); + textbox->setTextColor(col_text); textbox->enableBackgroundPaint(false); - textbox->paint(); + + //set text + string new_text = static_cast (text); + if (textbox->setText(&new_text)) + textbox->paint(); } void CComponentsInfoBox::paint(bool do_save_bg) { paintInit(do_save_bg); paintPicture(); - if (text != NULL) + if (text) paintText(); + text = NULL; } //------------------------------------------------------------------------------------------------------- @@ -632,14 +667,15 @@ void CComponentsPicture::setPictureAlign(const int alignment) void CComponentsPicture::initDimensions() { - if (pic_name.empty()){ - printf("CComponentsPicture: %s no picture file defined !\n", __FUNCTION__); - pic_width = pic_height = 0; - return; - } + pic_width = pic_height = 0; + pic_painted = false; + do_paint = false; frameBuffer->getIconSize(pic_name.c_str(), &pic_width, &pic_height); + if (pic_width == 0 || pic_height == 0) + printf("CComponentsPicture: %s file: %s, no icon dimensions found! width = %d, height = %d\n", __FUNCTION__, pic_name.c_str(), pic_width, pic_height); + pic_x += fr_thickness; pic_y += fr_thickness; @@ -659,18 +695,18 @@ void CComponentsPicture::initDimensions() do_paint = true; } - - width = max(pic_width, width); - height = max(pic_height, height); + + int sw = (shadow ? shadow_w :0); + width = max(pic_width, width) + sw ; + height = max(pic_height, height) + sw ; } void CComponentsPicture::paint(bool do_save_bg) { - pic_painted = false; initDimensions(); + paintInit(do_save_bg); - if (do_paint){ - paintInit(do_save_bg); + if (do_paint){ pic_painted = frameBuffer->paintIcon(pic_name, pic_x, pic_y, 0, pic_offset, pic_paint, pic_paintBg, col_body); do_paint = false; }