CComponentsHeader: add parameter buttons onto constructors

This adds default buttons to header
This commit is contained in:
2012-11-21 22:27:24 +01:00
parent 562b091e66
commit 3644abec66
3 changed files with 75 additions and 30 deletions

View File

@@ -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<std::string> 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();};
};

View File

@@ -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;
@@ -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()
@@ -1829,11 +1853,13 @@ void CComponentsHeader::initCCHeaderText()
//corner of text item
cch_text_obj->setCornerRadius(corner_rad-fr_thickness);
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();

View File

@@ -397,6 +397,10 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
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();
delete form;
@@ -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->setHeaderText("Test");
header->addHeaderButton(NEUTRINO_ICON_BUTTON_RED);
header->addHeaderButton(NEUTRINO_ICON_BUTTON_HELP);
header->addHeaderButton(NEUTRINO_ICON_BUTTON_MENU);
// 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();