diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index 282ca76f9..ae4f89db5 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -445,45 +445,11 @@ class CComponentsForm : public CComponentsItem virtual void paintCCItems(); }; -class CComponentsHeader : public CComponentsForm -{ - private: - CComponentsPicture * cch_icon_obj; - CComponentsText * cch_text_obj; - std::string cch_text; - const char* cch_icon_name; - neutrino_locale_t cch_locale_text; - fb_pixel_t cch_col_text; - Font* cch_font; - int cch_icon_x, cch_items_y, cch_text_x; - - void initCCHeaderIcon(); - void initCCHeaderText(); - - protected: - void initVarHeader(); - - public: - CComponentsHeader(); - CComponentsHeader(const int x_pos, const int y_pos, const int w, const int h = 0, const std::string& caption = "header", const char* icon_name = NULL, bool has_shadow = CC_SHADOW_OFF, - fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); - CComponentsHeader(const int x_pos, const int y_pos, const int w, const int h = 0, neutrino_locale_t caption_locale = NONEXISTANT_LOCALE, const char* icon_name = NULL, bool has_shadow = CC_SHADOW_OFF, - fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); - -// ~CComponentsHeader(); - - void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); - void setHeaderText(const std::string& caption); - void setHeaderText(neutrino_locale_t caption_locale); - void setColorHeaderBody(fb_pixel_t text_color){cch_col_text = text_color;}; - void setHeaderIcon(const char* icon_name); -}; - class CComponentsIconForm : public CComponentsForm { private: std::vector v_icons; - int ccif_offset; + int ccif_offset, ccif_icon_align; protected: void initVarIconForm(); @@ -502,9 +468,56 @@ class CComponentsIconForm : public CComponentsForm void removeIcon(const uint& icon_id); void removeIcon(const std::string& icon_name); void removeAllIcons(); - int getIconId(const std::string& icon_name); - void setIconOffset(const int offset){ccif_offset = offset;}; + + enum //alignements + { + CC_ICONS_FRM_ALIGN_RIGHT , + CC_ICONS_FRM_ALIGN_LEFT + }; + void setIconAlign(int alignment){ccif_icon_align = alignment;}; + + int getIconId(const std::string& icon_name); +}; + +class CComponentsHeader : public CComponentsForm +{ + private: + CComponentsPicture * cch_icon_obj; + CComponentsText * cch_text_obj; + CComponentsIconForm * cch_btn_obj; + std::string cch_text; + const char* cch_icon_name; + neutrino_locale_t cch_locale_text; + fb_pixel_t cch_col_text; + Font* cch_font; + int cch_icon_x, cch_items_y, cch_text_x, ccif_width, cch_icon_w; + std::vector v_cch_btn; + + void initCCHeaderIcon(); + void initCCHeaderText(); + void initCCHeaderButtons(); + + protected: + void initVarHeader(); + + public: + CComponentsHeader(); + CComponentsHeader(const int x_pos, const int y_pos, const int w, const int h = 0, const std::string& caption = "header", const char* icon_name = NULL, bool has_shadow = CC_SHADOW_OFF, + fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); + CComponentsHeader(const int x_pos, const int y_pos, const int w, const int h = 0, neutrino_locale_t caption_locale = NONEXISTANT_LOCALE, const char* icon_name = NULL, bool has_shadow = CC_SHADOW_OFF, + fb_pixel_t color_frame = COL_MENUCONTENT_PLUS_6, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0); + +// ~CComponentsHeader(); + + void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); + void setHeaderText(const std::string& caption); + void setHeaderText(neutrino_locale_t caption_locale); + void setColorHeaderBody(fb_pixel_t text_color){cch_col_text = text_color;}; + void setHeaderIcon(const char* icon_name); + + void addHeaderButton(const std::string& button_name); + void removeHeaderButtons(){v_cch_btn.clear();}; }; #endif diff --git a/src/gui/components/components.cpp b/src/gui/components/components.cpp index b8e1143be..7fc197d88 100644 --- a/src/gui/components/components.cpp +++ b/src/gui/components/components.cpp @@ -1691,12 +1691,16 @@ void CComponentsHeader::initVarHeader() cch_icon_obj = NULL; cch_text_obj = NULL; cch_icon_name = NULL; + cch_btn_obj = NULL; cch_text = "header"; cch_locale_text = NONEXISTANT_LOCALE; cch_col_text = COL_MENUHEAD; cch_items_y = 0; cch_icon_x = 0; + cch_icon_w = 5; cch_text_x = 0; + ccif_width = 5; + v_cch_btn.clear(); //CComponentsForm initVarForm(); @@ -1724,6 +1728,11 @@ void CComponentsHeader::setHeaderIcon(const char* icon_name) void CComponentsHeader::initCCHeaderIcon() { + if (cch_icon_name == NULL) { +// cch_icon_w = 5; + return; + } + if (cch_icon_name) cch_icon_obj = new CComponentsPicture(cch_icon_x, cch_items_y, 0, 0, cch_icon_name); cch_icon_obj->setWidth(height-2*fr_thickness); @@ -1739,12 +1748,50 @@ void CComponentsHeader::initCCHeaderIcon() else cc_icon_corner_type = CORNER_LEFT; cch_icon_obj->setCornerType(cc_icon_corner_type); + + //set width of icon object + cch_icon_w = cch_icon_obj->getWidth(); +} + +void CComponentsHeader::addHeaderButton(const std::string& button_name) +{ + v_cch_btn.push_back(button_name); +} + +void CComponentsHeader::initCCHeaderButtons() +{ + //exit here, if no icons added + if (v_cch_btn.empty()) + return; + + int ccbtn_offset = 8; + int btnw = 0; + + // calculate minimal width of icon form + size_t btncnt = v_cch_btn.size(); + for(size_t i=0; igetIconSize(v_cch_btn[i].c_str(), &bw, &bh); + btnw += bw; + if (i < (btncnt-1)) + btnw += ccbtn_offset; + } + btnw = max(btnw, ccif_width); + + cch_btn_obj = new CComponentsIconForm(); + cch_btn_obj->setDimensionsAll(0+width-btnw, 0, btnw-ccbtn_offset, height); + cch_btn_obj->doPaintBg(false); + cch_btn_obj->setIconOffset(ccbtn_offset); + cch_btn_obj->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_RIGHT); + cch_btn_obj->removeAllIcons(); + cch_btn_obj->addIcon(v_cch_btn); + } void CComponentsHeader::initCCHeaderText() { - cch_text_x = cch_icon_x+cch_icon_obj->getWidth(); - cch_text_obj = new CComponentsText(cch_text_x, cch_items_y, width-cch_icon_obj->getWidth()-fr_thickness, height-2*fr_thickness, cch_text.c_str()); + cch_text_x = cch_icon_x+cch_icon_w; + cch_text_obj = new CComponentsText(cch_text_x, cch_items_y, width-cch_icon_w-fr_thickness, height-2*fr_thickness, cch_text.c_str()); cch_text_obj->setTextFont(cch_font); cch_text_obj->setTextColor(cch_col_text); cch_text_obj->doPaintBg(false); @@ -1752,6 +1799,7 @@ void CComponentsHeader::initCCHeaderText() //corner of text item cch_text_obj->setCornerRadius(corner_rad-fr_thickness); cch_text_obj->setCornerType(corner_type); + } void CComponentsHeader::paint(bool do_save_bg) @@ -1767,10 +1815,17 @@ void CComponentsHeader::paint(bool do_save_bg) //init text initCCHeaderText(); + + //init buttons + initCCHeaderButtons(); //add elements - addCCItem(cch_icon_obj); - addCCItem(cch_text_obj); + if (cch_icon_obj) + addCCItem(cch_icon_obj); //icon + if (cch_text_obj) + addCCItem(cch_text_obj); //text + if (cch_btn_obj) + addCCItem(cch_btn_obj); //buttons //paint paintCCItems(); @@ -1812,6 +1867,7 @@ void CComponentsIconForm::initVarIconForm() v_icons.clear(); ccif_offset = 2; + ccif_icon_align = CC_ICONS_FRM_ALIGN_LEFT; } void CComponentsIconForm::addIcon(const std::string& icon_name) @@ -1862,41 +1918,71 @@ void CComponentsIconForm::initCCIcons() { //clean up first possible old item objects, includes delete and clean up vector and icons clearCCItems(); - - int ccp_x = 0+fr_thickness; - int ccp_y = 0; - int ccp_w = 0; - int ccp_h = 0; - //detect maximal form height + //icon count + size_t i_cnt = v_icons.size(); + + //calculate start pos of first icon + int ccp_x = 0; + if (ccif_icon_align == CC_ICONS_FRM_ALIGN_RIGHT) + ccp_x = width-fr_thickness; + else + ccp_x = 0+fr_thickness; //CC_ICONS_FRM_ALIGN_LEFT + + int ccp_y = 0; + int ccp_h = 0; + int ccp_w = 0; + + //get width of first icon + frameBuffer->getIconSize(v_icons[0].c_str(), &ccp_w, &ccp_h); + + //get maximal form height depends of biggest icon height, but don't touch defined form height int h = height; - for (size_t i= 0; i< v_icons.size(); i++){ - frameBuffer->getIconSize(v_icons[i].c_str(), &ccp_w, &ccp_h); + for (size_t i= 0; i< i_cnt; i++){ + int dummy; + frameBuffer->getIconSize(v_icons[i].c_str(), &dummy, &ccp_h); h = max(ccp_h, h)/*+2*fr_thickness*/; } - //init and add item objects - for (size_t i= 0; i< v_icons.size(); i++){ - frameBuffer->getIconSize(v_icons[i].c_str(), &ccp_w, &ccp_h); + //set xpos of first icon with right alignment, icon must positionized on the right border reduced with icon width + if (ccif_icon_align == CC_ICONS_FRM_ALIGN_RIGHT) + ccp_x -= ccp_w; + //init and add item objects + + for (size_t i= 0; i< i_cnt; i++){ + //create new cc-picture item object CComponentsPicture *ccp = NULL; ccp = new CComponentsPicture(ccp_x, ccp_y, ccp_w, h, v_icons[i]); ccp->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER); - ccp->doPaintBg(false); - + ccp->doPaintBg(false); + //add item to form addCCItem(ccp); - - ccp_x += ccif_offset + ccp_w; + + //reset current width for next object + ccp_w = 0; + //get next icon size if available + size_t next_i = i+1; + if (next_i < i_cnt) + frameBuffer->getIconSize(v_icons[next_i].c_str(), &ccp_w, &ccp_h); + + //set next icon position + int tmp_offset = ( igetWidth() + tmp_offset); + if (ccif_icon_align == CC_ICONS_FRM_ALIGN_RIGHT) + ccp_x -= (ccp_w + tmp_offset); } - //calculate form width and height + //calculate width and height of form int w_tmp = 0; int h_tmp = 0; - for (size_t i= 0; i< v_cc_items.size(); i++){ + for (size_t i= 0; i< i_cnt; i++){ w_tmp += v_cc_items[i]->getWidth()+ccif_offset+fr_thickness; h_tmp = max(h_tmp, v_cc_items[i]->getHeight()+2*fr_thickness); } - width = max(w_tmp, width)-ccif_offset; //terminate last offset + width = max(w_tmp, width); height = max(h_tmp, height); } diff --git a/src/gui/test_menu.cpp b/src/gui/test_menu.cpp index c9992a55b..5214ffe2a 100644 --- a/src/gui/test_menu.cpp +++ b/src/gui/test_menu.cpp @@ -421,9 +421,15 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) else if (actionKey == "header"){ if (header == NULL) header = new CComponentsHeader (100, 50, 480, g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(), "Test-Header", NEUTRINO_ICON_INFO); -// header->setFrameThickness(5); -// header->setColorFrame(COL_WHITE); -// header->setCornerType(CORNER_TOP); +// header->setFrameThickness(5); +// header->setColorFrame(COL_WHITE); +// header->setCornerType(CORNER_TOP); + //For existing instances it's recommended + //to remove old button icons before add new buttons, otherwise icons will be appended. + header->removeHeaderButtons(); + header->addHeaderButton(NEUTRINO_ICON_BUTTON_RED); + header->addHeaderButton(NEUTRINO_ICON_BUTTON_HELP); + header->addHeaderButton(NEUTRINO_ICON_BUTTON_MENU); if (!header->isPainted()) header->paint(); @@ -435,10 +441,11 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) if (iconform == NULL) iconform = new CComponentsIconForm(); iconform->setColorBody(COL_LIGHT_GRAY); - iconform->setDimensionsAll(100, 100, 0, 60); + iconform->setDimensionsAll(100, 100, 480, 60); iconform->setFrameThickness(2); iconform->setColorFrame(COL_WHITE); iconform->setIconOffset(5); + iconform->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_LEFT); //For existing instances it's recommended //to remove old items before add new icons, otherwise icons will be appended. iconform->removeAllIcons(); @@ -455,9 +462,9 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) v_icons.push_back(NEUTRINO_ICON_HINT_AUDIO); iconform->addIcon(v_icons); - //insert any icon, here as first (index = 0) + //insert any icon, here as first (index = 0...n) iconform->insertIcon(0, NEUTRINO_ICON_HINT_APLAY); - +// iconform->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_RIGHT); if (iconform->isPainted()) iconform->hide();