diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index 7b91bcc5d..21e71cc80 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -81,12 +81,6 @@ enum CC_ALIGN_VER_CENTER = 16 }; -enum -{ - CC_PIC_ICON, - CC_PIC_IMAGE -}; - enum { CC_ITEMBOX_ICON, @@ -141,7 +135,7 @@ class CComponents inline virtual void setHeight(const int& h){height = h;}; inline virtual void setWidth(const int& w){width = w;}; inline virtual void setDimensionsAll(const int& xpos, const int& ypos, const int& w, const int& h){x = xpos; y = ypos; width = w; height = h;}; - + inline virtual int getXPos(){return x;}; inline virtual int getYPos(){return y;}; inline virtual int getHeight(){return height;}; @@ -153,6 +147,10 @@ class CComponents inline virtual void setColorBody(fb_pixel_t color){col_body = color;}; inline virtual void setColorShadow(fb_pixel_t color){col_shadow = color;}; inline virtual void setColorAll(fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow){col_frame = color_frame; col_body = color_body; col_shadow = color_shadow;}; +/// get colors + inline virtual fb_pixel_t getColorFrame(){return col_frame;}; + inline virtual fb_pixel_t getColorBody(){return col_body;}; + inline virtual fb_pixel_t getColorShadow(){return col_shadow;}; virtual void hide(); virtual bool isPainted(){return is_painted;}; @@ -172,48 +170,55 @@ class CComponentsItem : public CComponents /// set corner types: Possible corner types are defined in CFrameBuffer (see: driver/framebuffer.h). inline virtual void setCornerType(const int& type){corner_type = type;}; inline virtual void setCornerRadius(const int& radius){corner_rad = radius;}; - +/// get corner types: + inline virtual int getCornerType(){return corner_type;}; + inline virtual int getCornerRadius(){return corner_rad;}; + inline virtual void setFrameThickness(const int& thickness){fr_thickness = thickness;}; inline virtual void setShadowOnOff(bool has_shadow){shadow = has_shadow;}; virtual void paint(bool do_save_bg = CC_SAVE_SCREEN_YES) = 0; virtual void hide(bool no_restore = false); virtual void kill(); - + virtual void syncSysColors(); }; class CComponentsPicture : public CComponentsItem { private: + enum + { + CC_PIC_IMAGE_MODE_OFF = 0, //paint pictures in icon mode, mainly not scaled + CC_PIC_IMAGE_MODE_ON = 1, //paint pictures in image mode, paint scaled if required + CC_PIC_IMAGE_MODE_AUTO = 2 + }; + std::string pic_name; unsigned char pic_offset; bool pic_paint, pic_paintBg, pic_painted, do_paint; int pic_align, pic_x, pic_y, pic_width, pic_height; - int maxWidth, maxHeight, picMode; - + int maxWidth, maxHeight, pic_paint_mode; + void initVarPicture(); - void init( const int x_pos, const int y_pos, const std::string& picture_name, const int alignment, bool has_shadow, + void init( const int x_pos, const int y_pos, const std::string& image_name, const int alignment, bool has_shadow, fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow); - + public: - CComponentsPicture( const int x_pos, const int y_pos, - const std::string& picture_name, const int alignment = CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER, bool has_shadow = CC_SHADOW_OFF, - fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_background = 0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); CComponentsPicture( const int x_pos, const int y_pos, const int w_max, const int h_max, - const std::string& picture_name, const int alignment = CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER, bool has_shadow = CC_SHADOW_OFF, + const std::string& image_name, const int alignment = CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER, bool has_shadow = CC_SHADOW_OFF, fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_background = 0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); + inline void setPictureOffset(const unsigned char offset){pic_offset = offset;}; inline void setPicturePaint(bool paint_p){pic_paint = paint_p;}; inline void setPicturePaintBackground(bool paintBg){pic_paintBg = paintBg;}; inline void setPicture(const std::string& picture_name); void setPictureAlign(const int alignment); - + inline bool isPicPainted(){return pic_painted;}; void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); void hide(bool no_restore = false); inline void getPictureSize(int *pwidth, int *pheight){*pwidth=pic_width; *pheight=pic_height;}; - }; class CComponentsText : public CComponentsItem @@ -234,6 +239,11 @@ class CComponentsText : public CComponentsItem void paintText(bool do_save_bg = CC_SAVE_SCREEN_YES); public: CComponentsText(); + CComponentsText(const char* text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL); + CComponentsText( const int x_pos, const int y_pos, const int w, const int h, + const char* text = "", const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL, + bool has_shadow = CC_SHADOW_OFF, + 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); ~CComponentsText(); void hide(bool no_restore = false); @@ -256,24 +266,23 @@ class CComponentsInfoBox : public CComponentsText CComponentsText * cctext; CComponentsPicture * pic; std::string pic_default_name; - + void paintPicture(); -// void paintText(); void initVarInfobox(); std::string pic_name; - + public: CComponentsInfoBox(); CComponentsInfoBox( const int x_pos, const int y_pos, const int w, const int h, const char* info_text = "", const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL, bool has_shadow = CC_SHADOW_OFF, 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(); - + inline void setSpaceOffset(const int offset){x_offset = offset;}; inline void setPicture(const std::string& picture_name){pic_name = picture_name;}; - + void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); }; @@ -285,7 +294,7 @@ class CComponentsShapeCircle : public CComponentsItem public: CComponentsShapeCircle( const int x_pos, const int y_pos, const int diam, bool has_shadow = CC_SHADOW_ON, 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); - + inline void setDiam(const int& diam){d=width=height=diam, corner_rad=d/2;}; inline int getDiam(){return d;}; void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); @@ -296,7 +305,7 @@ class CComponentsShapeSquare : public CComponentsItem public: CComponentsShapeSquare( const int x_pos, const int y_pos, const int w, const int h, bool has_shadow = CC_SHADOW_ON, 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); - + void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); }; @@ -307,7 +316,7 @@ class CComponentsPIP : public CComponentsItem public: CComponentsPIP( const int x_pos, const int y_pos, const int percent, bool has_shadow = CC_SHADOW_OFF); ~CComponentsPIP(); - + void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); void hide(bool no_restore = false); }; @@ -416,24 +425,22 @@ class CComponentsTitleBar : public CComponentsItemBox class CComponentsForm : public CComponentsItem { + protected: + std::vector v_cc_items; + void paintCCItems(); private: - CComponentsTitleBar *tb; - std::string tb_text, tb_icon; - void initVarForm(); - void paintHead(); - public: + CComponentsForm(); + CComponentsForm(const int x_pos, const int y_pos, const int w, const int h); + CComponentsForm(const int x_pos, const int y_pos, const int w, const int h, bool has_shadow = CC_SHADOW_ON, + 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); ~CComponentsForm(); void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); void hide(bool no_restore = false); - void setCaption(const std::string& text); - void setCaption(neutrino_locale_t locale_text); - void setIcon(const std::string& icon_name){tb_icon = icon_name;}; + void addCCItem(CComponentsItem* cc_Item); }; - - #endif diff --git a/src/gui/components/components.cpp b/src/gui/components/components.cpp index 3aa6f28c3..ce1a235fd 100644 --- a/src/gui/components/components.cpp +++ b/src/gui/components/components.cpp @@ -269,6 +269,42 @@ CComponentsText::CComponentsText() initVarText(); } +CComponentsText::CComponentsText(const char* text, const int mode, Font* font_text) +{ + //CComponentsText + initVarText(); + + ct_text = text; + ct_text_mode = mode; + ct_font = font_text; +} + +CComponentsText::CComponentsText( const int x_pos, const int y_pos, const int w, const int h, + const char* text, const int mode, Font* font_text, + bool has_shadow, + fb_pixel_t color_text, fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) +{ + //CComponentsText + initVarText(); + + //CComponents + x = x_pos, + y = y_pos, + width = w; + height = h; + + col_frame = color_frame; + col_body = color_body; + col_shadow = color_shadow; + shadow = has_shadow; + + ct_font = font_text; + ct_text = text; + ct_text_mode = mode; + ct_col_text = color_text; +} + + CComponentsText::~CComponentsText() { @@ -444,7 +480,7 @@ void CComponentsInfoBox::paintPicture() { //init and set icon paint position if (pic == NULL) - pic = new CComponentsPicture(x+fr_thickness+x_offset, y+fr_thickness/*+y_offset*/, ""); + pic = new CComponentsPicture(x+fr_thickness+x_offset, y+fr_thickness/*+y_offset*/, 0, 0, ""); pic->setXPos(x+fr_thickness+x_offset); pic->setYPos(y+fr_thickness); @@ -730,40 +766,27 @@ void CComponentsPIP::hide(bool no_restore) //------------------------------------------------------------------------------------------------------- //sub class CComponentsPicture from CComponentsItem -CComponentsPicture::CComponentsPicture( const int x_pos, const int y_pos, - const std::string& picture_name, const int alignment, bool has_shadow, - fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow) -{ - init(x_pos, y_pos, picture_name, alignment, has_shadow, color_frame, color_background, color_shadow); - - maxWidth = 0; - maxHeight = 0; - picMode = CC_PIC_ICON; - - initVarPicture(); -} - CComponentsPicture::CComponentsPicture( const int x_pos, const int y_pos, const int w_max, const int h_max, - const std::string& picture_name, const int alignment, bool has_shadow, + const std::string& image_name, const int alignment, bool has_shadow, fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow) { - init(x_pos, y_pos, picture_name, alignment, has_shadow, color_frame, color_background, color_shadow); + init(x_pos, y_pos, image_name, alignment, has_shadow, color_frame, color_background, color_shadow); maxWidth = w_max; maxHeight = h_max; - picMode = CC_PIC_IMAGE; + pic_paint_mode = CC_PIC_IMAGE_MODE_AUTO, initVarPicture(); } -void CComponentsPicture::init( int x_pos, int y_pos, const string& picture_name, const int alignment, bool has_shadow, +void CComponentsPicture::init( int x_pos, int y_pos, const string& image_name, const int alignment, bool has_shadow, fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow) { //CComponents, CComponentsItem initVarItem(); //CComponentsPicture - pic_name = picture_name; + pic_name = image_name; pic_align = alignment; pic_offset = 1; pic_paint = true; @@ -805,9 +828,22 @@ void CComponentsPicture::initVarPicture() pic_painted = false; do_paint = false; - if (picMode == CC_PIC_ICON) + //set the image mode depends of name syntax, icon names contains no path, + //so we can detect the required image mode + if (pic_paint_mode == CC_PIC_IMAGE_MODE_AUTO){ + if (!access(pic_name.c_str(), F_OK )) + pic_paint_mode = CC_PIC_IMAGE_MODE_ON; + else + pic_paint_mode = CC_PIC_IMAGE_MODE_OFF; + } + + if (pic_paint_mode == CC_PIC_IMAGE_MODE_OFF){ frameBuffer->getIconSize(pic_name.c_str(), &pic_width, &pic_height); - else { + pic_width = max(pic_width, maxWidth); + pic_height = max(pic_height, maxHeight); + } + + if (pic_paint_mode == CC_PIC_IMAGE_MODE_ON) { g_PicViewer->getSize(pic_name.c_str(), &pic_width, &pic_height); if((pic_width > maxWidth) || (pic_height > maxHeight)) g_PicViewer->rescaleImageDimensions(&pic_width, &pic_height, maxWidth, maxHeight); @@ -850,9 +886,9 @@ void CComponentsPicture::paint(bool do_save_bg) pic_painted = false; if (do_paint){ - if (picMode == CC_PIC_ICON) + if (pic_paint_mode == CC_PIC_IMAGE_MODE_OFF) pic_painted = frameBuffer->paintIcon(pic_name, pic_x, pic_y, 0, pic_offset, pic_paint, pic_paintBg, col_body); - else + else if (pic_paint_mode == CC_PIC_IMAGE_MODE_ON) pic_painted = g_PicViewer->DisplayImage(pic_name, pic_x, pic_y, pic_width, pic_height); do_paint = false; } @@ -1080,7 +1116,7 @@ void CComponentsItemBox::paintImage(size_t index, bool newElement) pic = new CComponentsPicture( v_element_data[index].x, v_element_data[index].y, v_element_data[index].width, v_element_data[index].height, v_element_data[index].element); else - pic = new CComponentsPicture( v_element_data[index].x, v_element_data[index].y, v_element_data[index].element); + pic = new CComponentsPicture( v_element_data[index].x, v_element_data[index].y, 0, 0, v_element_data[index].element); v_element_data[index].handler1 = (void*)pic; } @@ -1448,18 +1484,53 @@ void CComponentsTitleBar::paint(bool do_save_bg) //------------------------------------------------------------------------------------------------------- -//sub class CComponentsForm from CComponentsItemBox +//sub class CComponentsForm from CComponentsItem CComponentsForm::CComponentsForm() { //CComponentsForm initVarForm(); } +CComponentsForm::CComponentsForm(const int x_pos, const int y_pos, const int w, const int h) +{ + //CComponentsForm + initVarForm(); + + //CComponents + x = x_pos; + y = y_pos; + width = w; + height = h; + +} + +CComponentsForm::CComponentsForm(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) +{ + //CComponentsForm + initVarForm(); + + //CComponents + x = x_pos; + y = y_pos; + width = w; + height = h; + + shadow = has_shadow; + col_frame = color_frame; + col_body = color_body; + col_shadow = color_shadow; +} + CComponentsForm::~CComponentsForm() { hide(); clearSavedScreen(); - delete tb; + for(size_t i=0; igetXPos(); + int ccy = v_cc_items[i]->getYPos(); - //init icon - if (!tb_icon.empty()) - tb->addIcon(tb_icon, CC_ALIGN_LEFT); + //set adapted position onto form + v_cc_items[i]->setXPos(x_tmp+ccx); + v_cc_items[i]->setYPos(y_tmp+ccy); - //init text - if (!tb_text.empty()) - tb->addText(tb_text, CC_ALIGN_LEFT); + //paint element without saved screen! + v_cc_items[i]->paint(CC_SAVE_SCREEN_NO); - int tbh = tb->getHeight(); - tb->setDimensionsAll(x, y, width, tbh); + //restore position + v_cc_items[i]->setXPos(ccx); + v_cc_items[i]->setYPos(ccy); } - - //paint titlebar - tb->paint(CC_SAVE_SCREEN_NO); -} - -void CComponentsForm::setCaption(const string& text) -{ - if (tb){ - delete tb; - tb = NULL; - } - tb_text = text; -} - -void CComponentsForm::setCaption(neutrino_locale_t locale_text) -{ - string tmptxt = g_Locale->getText(locale_text); - setCaption(tmptxt); } void CComponentsForm::hide(bool no_restore) @@ -1538,6 +1602,3 @@ void CComponentsForm::hide(bool no_restore) //hide body hideContainer(no_restore); } - - -