From 068cb4c6a21890b55740c8861df2ee2145cd5664 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Wed, 21 Nov 2012 22:27:24 +0100 Subject: [PATCH] CComponentsHeader: add parameter buttons onto constructors This adds default buttons to header Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/3644abec665570009c3bec45efb8de97f49ae275 Author: Thilo Graf Date: 2012-11-21 (Wed, 21 Nov 2012) --- src/gui/components/cc.h | 17 +++++++-- src/gui/components/components.cpp | 62 +++++++++++++++++++++---------- src/gui/test_menu.cpp | 26 +++++++++---- 3 files changed, 75 insertions(+), 30 deletions(-) diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index 9bc7776d0..9e8b7fa2c 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -484,6 +484,8 @@ class CComponentsIconForm : public CComponentsForm int getIconId(const std::string& icon_name); }; + + class CComponentsHeader : public CComponentsForm { private: @@ -495,7 +497,7 @@ class CComponentsHeader : public CComponentsForm 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; + int cch_icon_x, cch_items_y, cch_text_x, ccif_width, cch_icon_w, cch_buttons; std::vector v_cch_btn; void initCCHeaderIcon(); @@ -507,10 +509,18 @@ class CComponentsHeader : public CComponentsForm void initVarHeader(); public: + enum + { + CC_BTN_HELP = 0x02, + CC_BTN_INFO = 0x04, + CC_BTN_MENU = 0x40, + CC_BTN_EXIT = 0x80 + + }; 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, + 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, const int buttons = 0, 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, + 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, const int buttons = 0,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(); @@ -520,7 +530,6 @@ class CComponentsHeader : public CComponentsForm 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();}; }; diff --git a/src/gui/components/components.cpp b/src/gui/components/components.cpp index a1087eb49..ae9745c4d 100644 --- a/src/gui/components/components.cpp +++ b/src/gui/components/components.cpp @@ -1570,11 +1570,6 @@ void CComponentsForm::addCCItem(CComponentsItem* cc_Item) v_cc_items.push_back(cc_Item); } -void CComponentsForm::insertCCItem(const uint& cc_item_id, CComponentsItem* cc_Item) -{ - v_cc_items.insert(v_cc_items.begin()+cc_item_id, cc_Item); -} - int CComponentsForm::getCCItemId(CComponentsItem* cc_Item) { for (size_t i= 0; i< v_cc_items.size(); i++) @@ -1590,6 +1585,17 @@ CComponentsItem* CComponentsForm::getCCItem(const uint& cc_item_id) return NULL; } +void CComponentsForm::insertCCItem(const uint& cc_item_id, CComponentsItem* cc_Item) +{ +#ifdef DEBUG_CC + if (cc_Item == NULL){ + printf("CComponentsForm: %s parameter: cc_Item = %d...\n", __FUNCTION__, (int)cc_Item); + return; + } +#endif + v_cc_items.insert(v_cc_items.begin()+cc_item_id, cc_Item); +} + void CComponentsForm::removeCCItem(const uint& cc_item_id) { if (v_cc_items[cc_item_id]) { @@ -1597,7 +1603,6 @@ void CComponentsForm::removeCCItem(const uint& cc_item_id) v_cc_items[cc_item_id] = NULL; v_cc_items.erase(v_cc_items.begin()+cc_item_id); } - } void CComponentsForm::paint(bool do_save_bg) @@ -1666,7 +1671,7 @@ CComponentsHeader::CComponentsHeader() initVarHeader(); } -CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const int w, const int h, const std::string& caption, const char* icon_name, bool has_shadow, +CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const int w, const int h, const std::string& caption, const char* icon_name, const int buttons, bool has_shadow, fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) { //CComponentsHeader @@ -1683,9 +1688,12 @@ CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const in cch_text = caption; cch_icon_name = icon_name; + cch_buttons = buttons; + + initCCHItems(); } -CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const int w, const int h, neutrino_locale_t caption_locale, const char* icon_name, bool has_shadow, +CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const int w, const int h, neutrino_locale_t caption_locale, const char* icon_name, const int buttons, bool has_shadow, fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) { //CComponentsHeader @@ -1702,6 +1710,9 @@ CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const in cch_locale_text = caption_locale; cch_icon_name = icon_name; + cch_buttons = buttons; + + initCCHItems(); } #if 0 @@ -1730,6 +1741,7 @@ void CComponentsHeader::initVarHeader() cch_icon_w = 5; cch_text_x = 0; ccif_width = 5; + cch_buttons = 0; v_cch_btn.clear(); //CComponentsForm @@ -1739,6 +1751,8 @@ void CComponentsHeader::initVarHeader() col_body = COL_MENUHEAD_PLUS_0; corner_rad = RADIUS_LARGE, corner_type = CORNER_TOP; + + initCCHItems(); } void CComponentsHeader::setHeaderText(const std::string& caption) @@ -1756,6 +1770,8 @@ void CComponentsHeader::setHeaderIcon(const char* icon_name) cch_icon_name = icon_name; } + + void CComponentsHeader::initCCHeaderIcon() { if (cch_icon_name == NULL) { @@ -1790,7 +1806,16 @@ void CComponentsHeader::addHeaderButton(const std::string& button_name) void CComponentsHeader::initCCHeaderButtons() { - //exit here, if no icons added + if (cch_buttons & CC_BTN_EXIT) + addHeaderButton(NEUTRINO_ICON_BUTTON_HOME); + if (cch_buttons & CC_BTN_HELP) + addHeaderButton(NEUTRINO_ICON_BUTTON_HELP); + if (cch_buttons & CC_BTN_INFO) + addHeaderButton(NEUTRINO_ICON_BUTTON_INFO); + if (cch_buttons & CC_BTN_MENU) + addHeaderButton(NEUTRINO_ICON_BUTTON_MENU); + + //exit if no button defined if (v_cch_btn.empty()) return; @@ -1807,7 +1832,7 @@ void CComponentsHeader::initCCHeaderButtons() 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); @@ -1815,7 +1840,6 @@ void CComponentsHeader::initCCHeaderButtons() cch_btn_obj->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_RIGHT); cch_btn_obj->removeAllIcons(); cch_btn_obj->addIcon(v_cch_btn); - } void CComponentsHeader::initCCHeaderText() @@ -1825,15 +1849,17 @@ void CComponentsHeader::initCCHeaderText() cch_text_obj->setTextFont(cch_font); cch_text_obj->setTextColor(cch_col_text); cch_text_obj->doPaintBg(false); - + //corner of text item cch_text_obj->setCornerRadius(corner_rad-fr_thickness); - cch_text_obj->setCornerType(corner_type); - + cch_text_obj->setCornerType(corner_type); } void CComponentsHeader::initCCHItems() { + //clean up first possible old item objects, includes delete and clean up vector + clearCCItems(); + //init icon initCCHeaderIcon(); @@ -1850,6 +1876,7 @@ void CComponentsHeader::initCCHItems() addCCItem(cch_text_obj); //text if (cch_btn_obj) addCCItem(cch_btn_obj); //buttons + } void CComponentsHeader::paint(bool do_save_bg) @@ -1857,11 +1884,8 @@ void CComponentsHeader::paint(bool do_save_bg) //paint body paintInit(do_save_bg); - //clean up first possible old item objects, includes delete and clean up vector - clearCCItems(); - - //init default header ccitems - initCCHItems(); + /*//init default header ccitems + */initCCHItems(); //paint paintCCItems(); diff --git a/src/gui/test_menu.cpp b/src/gui/test_menu.cpp index 5214ffe2a..f202bf8e2 100644 --- a/src/gui/test_menu.cpp +++ b/src/gui/test_menu.cpp @@ -396,6 +396,10 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) CComponentsShapeCircle *c1 = new CComponentsShapeCircle(28, 40, 28); c1->setColorBody(COL_RED); form->addCCItem(c1); + +// form->removeCCItem(form->getCCItemId(t1)); +// form->insertCCItem(1, new CComponentsPicture(28, 0, 0, 0, NEUTRINO_ICON_BUTTON_RED)); + if (form->isPainted()) { form->hide(); @@ -419,17 +423,25 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) return res; } else if (actionKey == "header"){ + int hh = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); if (header == NULL) - header = new CComponentsHeader (100, 50, 480, g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(), "Test-Header", NEUTRINO_ICON_INFO); + header = new CComponentsHeader (100, 50, 480, hh, "Test-Header", NEUTRINO_ICON_INFO/*, CComponentsHeader::CC_BTN_HELP | CComponentsHeader::CC_BTN_EXIT */); + else //For existing instances it's recommended + //to remove old button icons before add new buttons, otherwise icons will be appended. + header->removeHeaderButtons(); // 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); +// header->setHeaderText("Test"); + header->addHeaderButton(NEUTRINO_ICON_BUTTON_RED); +// header->addHeaderButton(NEUTRINO_ICON_BUTTON_HELP); +// header->addHeaderButton(NEUTRINO_ICON_BUTTON_MENU); + +// header->removeCCItem(2); //remove text +// CComponentsPicture *logo = new CComponentsPicture(5, 0, 100, g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(), "/tmp/media/sda1/var/share/tuxbox/neutrino/icons/logo/100850010.png"); +// logo->doPaintBg(false); +// header->insertCCItem(0, logo); //replace text with logo + if (!header->isPainted()) header->paint();