mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
CComponentsHeader: add header buttons to header form
Use addHeaderButton() to add any button icon ont header form. The buttons have a right alignment, this means, the first button is on the right boarder of header. For existing instances it's recommended to remove old button icons before add new buttons, otherwise icons will be append. See also sample code in CTestMenu.
This commit is contained in:
@@ -445,45 +445,11 @@ class CComponentsForm : public CComponentsItem
|
|||||||
virtual void paintCCItems();
|
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
|
class CComponentsIconForm : public CComponentsForm
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> v_icons;
|
std::vector<std::string> v_icons;
|
||||||
int ccif_offset;
|
int ccif_offset, ccif_icon_align;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initVarIconForm();
|
void initVarIconForm();
|
||||||
@@ -502,9 +468,56 @@ class CComponentsIconForm : public CComponentsForm
|
|||||||
void removeIcon(const uint& icon_id);
|
void removeIcon(const uint& icon_id);
|
||||||
void removeIcon(const std::string& icon_name);
|
void removeIcon(const std::string& icon_name);
|
||||||
void removeAllIcons();
|
void removeAllIcons();
|
||||||
int getIconId(const std::string& icon_name);
|
|
||||||
|
|
||||||
void setIconOffset(const int offset){ccif_offset = offset;};
|
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<std::string> 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
|
#endif
|
||||||
|
@@ -1691,12 +1691,16 @@ void CComponentsHeader::initVarHeader()
|
|||||||
cch_icon_obj = NULL;
|
cch_icon_obj = NULL;
|
||||||
cch_text_obj = NULL;
|
cch_text_obj = NULL;
|
||||||
cch_icon_name = NULL;
|
cch_icon_name = NULL;
|
||||||
|
cch_btn_obj = NULL;
|
||||||
cch_text = "header";
|
cch_text = "header";
|
||||||
cch_locale_text = NONEXISTANT_LOCALE;
|
cch_locale_text = NONEXISTANT_LOCALE;
|
||||||
cch_col_text = COL_MENUHEAD;
|
cch_col_text = COL_MENUHEAD;
|
||||||
cch_items_y = 0;
|
cch_items_y = 0;
|
||||||
cch_icon_x = 0;
|
cch_icon_x = 0;
|
||||||
|
cch_icon_w = 5;
|
||||||
cch_text_x = 0;
|
cch_text_x = 0;
|
||||||
|
ccif_width = 5;
|
||||||
|
v_cch_btn.clear();
|
||||||
|
|
||||||
//CComponentsForm
|
//CComponentsForm
|
||||||
initVarForm();
|
initVarForm();
|
||||||
@@ -1724,6 +1728,11 @@ void CComponentsHeader::setHeaderIcon(const char* icon_name)
|
|||||||
|
|
||||||
void CComponentsHeader::initCCHeaderIcon()
|
void CComponentsHeader::initCCHeaderIcon()
|
||||||
{
|
{
|
||||||
|
if (cch_icon_name == NULL) {
|
||||||
|
// cch_icon_w = 5;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (cch_icon_name)
|
if (cch_icon_name)
|
||||||
cch_icon_obj = new CComponentsPicture(cch_icon_x, cch_items_y, 0, 0, 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);
|
cch_icon_obj->setWidth(height-2*fr_thickness);
|
||||||
@@ -1739,12 +1748,50 @@ void CComponentsHeader::initCCHeaderIcon()
|
|||||||
else
|
else
|
||||||
cc_icon_corner_type = CORNER_LEFT;
|
cc_icon_corner_type = CORNER_LEFT;
|
||||||
cch_icon_obj->setCornerType(cc_icon_corner_type);
|
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; i<btncnt; i++){
|
||||||
|
int bw, bh;
|
||||||
|
frameBuffer->getIconSize(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()
|
void CComponentsHeader::initCCHeaderText()
|
||||||
{
|
{
|
||||||
cch_text_x = cch_icon_x+cch_icon_obj->getWidth();
|
cch_text_x = cch_icon_x+cch_icon_w;
|
||||||
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_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->setTextFont(cch_font);
|
||||||
cch_text_obj->setTextColor(cch_col_text);
|
cch_text_obj->setTextColor(cch_col_text);
|
||||||
cch_text_obj->doPaintBg(false);
|
cch_text_obj->doPaintBg(false);
|
||||||
@@ -1752,6 +1799,7 @@ void CComponentsHeader::initCCHeaderText()
|
|||||||
//corner of text item
|
//corner of text item
|
||||||
cch_text_obj->setCornerRadius(corner_rad-fr_thickness);
|
cch_text_obj->setCornerRadius(corner_rad-fr_thickness);
|
||||||
cch_text_obj->setCornerType(corner_type);
|
cch_text_obj->setCornerType(corner_type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CComponentsHeader::paint(bool do_save_bg)
|
void CComponentsHeader::paint(bool do_save_bg)
|
||||||
@@ -1768,9 +1816,16 @@ void CComponentsHeader::paint(bool do_save_bg)
|
|||||||
//init text
|
//init text
|
||||||
initCCHeaderText();
|
initCCHeaderText();
|
||||||
|
|
||||||
|
//init buttons
|
||||||
|
initCCHeaderButtons();
|
||||||
|
|
||||||
//add elements
|
//add elements
|
||||||
addCCItem(cch_icon_obj);
|
if (cch_icon_obj)
|
||||||
addCCItem(cch_text_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
|
//paint
|
||||||
paintCCItems();
|
paintCCItems();
|
||||||
@@ -1812,6 +1867,7 @@ void CComponentsIconForm::initVarIconForm()
|
|||||||
|
|
||||||
v_icons.clear();
|
v_icons.clear();
|
||||||
ccif_offset = 2;
|
ccif_offset = 2;
|
||||||
|
ccif_icon_align = CC_ICONS_FRM_ALIGN_LEFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CComponentsIconForm::addIcon(const std::string& icon_name)
|
void CComponentsIconForm::addIcon(const std::string& icon_name)
|
||||||
@@ -1863,40 +1919,70 @@ void CComponentsIconForm::initCCIcons()
|
|||||||
//clean up first possible old item objects, includes delete and clean up vector and icons
|
//clean up first possible old item objects, includes delete and clean up vector and icons
|
||||||
clearCCItems();
|
clearCCItems();
|
||||||
|
|
||||||
int ccp_x = 0+fr_thickness;
|
//icon count
|
||||||
int ccp_y = 0;
|
size_t i_cnt = v_icons.size();
|
||||||
int ccp_w = 0;
|
|
||||||
int ccp_h = 0;
|
|
||||||
|
|
||||||
//detect maximal form height
|
//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;
|
int h = height;
|
||||||
for (size_t i= 0; i< v_icons.size(); i++){
|
for (size_t i= 0; i< i_cnt; i++){
|
||||||
frameBuffer->getIconSize(v_icons[i].c_str(), &ccp_w, &ccp_h);
|
int dummy;
|
||||||
|
frameBuffer->getIconSize(v_icons[i].c_str(), &dummy, &ccp_h);
|
||||||
h = max(ccp_h, h)/*+2*fr_thickness*/;
|
h = max(ccp_h, h)/*+2*fr_thickness*/;
|
||||||
}
|
}
|
||||||
|
|
||||||
//init and add item objects
|
//set xpos of first icon with right alignment, icon must positionized on the right border reduced with icon width
|
||||||
for (size_t i= 0; i< v_icons.size(); i++){
|
if (ccif_icon_align == CC_ICONS_FRM_ALIGN_RIGHT)
|
||||||
frameBuffer->getIconSize(v_icons[i].c_str(), &ccp_w, &ccp_h);
|
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;
|
CComponentsPicture *ccp = NULL;
|
||||||
ccp = new CComponentsPicture(ccp_x, ccp_y, ccp_w, h, v_icons[i]);
|
ccp = new CComponentsPicture(ccp_x, ccp_y, ccp_w, h, v_icons[i]);
|
||||||
ccp->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER);
|
ccp->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER);
|
||||||
ccp->doPaintBg(false);
|
ccp->doPaintBg(false);
|
||||||
|
//add item to form
|
||||||
addCCItem(ccp);
|
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 = ( i<i_cnt ? ccif_offset : 0 );
|
||||||
|
|
||||||
|
if (ccif_icon_align == CC_ICONS_FRM_ALIGN_LEFT)
|
||||||
|
ccp_x += (ccp->getWidth() + 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 w_tmp = 0;
|
||||||
int h_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;
|
w_tmp += v_cc_items[i]->getWidth()+ccif_offset+fr_thickness;
|
||||||
h_tmp = max(h_tmp, v_cc_items[i]->getHeight()+2*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);
|
height = max(h_tmp, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -424,6 +424,12 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
|
|||||||
// header->setFrameThickness(5);
|
// header->setFrameThickness(5);
|
||||||
// header->setColorFrame(COL_WHITE);
|
// header->setColorFrame(COL_WHITE);
|
||||||
// header->setCornerType(CORNER_TOP);
|
// 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())
|
if (!header->isPainted())
|
||||||
header->paint();
|
header->paint();
|
||||||
@@ -435,10 +441,11 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
|
|||||||
if (iconform == NULL)
|
if (iconform == NULL)
|
||||||
iconform = new CComponentsIconForm();
|
iconform = new CComponentsIconForm();
|
||||||
iconform->setColorBody(COL_LIGHT_GRAY);
|
iconform->setColorBody(COL_LIGHT_GRAY);
|
||||||
iconform->setDimensionsAll(100, 100, 0, 60);
|
iconform->setDimensionsAll(100, 100, 480, 60);
|
||||||
iconform->setFrameThickness(2);
|
iconform->setFrameThickness(2);
|
||||||
iconform->setColorFrame(COL_WHITE);
|
iconform->setColorFrame(COL_WHITE);
|
||||||
iconform->setIconOffset(5);
|
iconform->setIconOffset(5);
|
||||||
|
iconform->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_LEFT);
|
||||||
//For existing instances it's recommended
|
//For existing instances it's recommended
|
||||||
//to remove old items before add new icons, otherwise icons will be appended.
|
//to remove old items before add new icons, otherwise icons will be appended.
|
||||||
iconform->removeAllIcons();
|
iconform->removeAllIcons();
|
||||||
@@ -455,9 +462,9 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
|
|||||||
v_icons.push_back(NEUTRINO_ICON_HINT_AUDIO);
|
v_icons.push_back(NEUTRINO_ICON_HINT_AUDIO);
|
||||||
iconform->addIcon(v_icons);
|
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->insertIcon(0, NEUTRINO_ICON_HINT_APLAY);
|
||||||
|
// iconform->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_RIGHT);
|
||||||
|
|
||||||
if (iconform->isPainted())
|
if (iconform->isPainted())
|
||||||
iconform->hide();
|
iconform->hide();
|
||||||
|
Reference in New Issue
Block a user