CComponentsHeader: rework context button handling

CComponentsHeader uses now CComponentsIconForm, which is now derived
from CComponentsFrmChain. Some methods should be now simplified and
allow to handle some modifications easier.
This commit is contained in:
2014-03-22 00:21:30 +01:00
parent a573b02b85
commit 6fe7b452c1
13 changed files with 164 additions and 281 deletions

View File

@@ -100,7 +100,6 @@ void CComponentsHeader::initVarHeader( const int& x_pos, const int& y_pos, const
col_body = COL_MENUHEAD_PLUS_0;
cch_text = caption;
cch_icon_name = icon_name;
cch_buttons = buttons;
corner_rad = RADIUS_LARGE,
corner_type = CORNER_TOP;
@@ -115,11 +114,9 @@ void CComponentsHeader::initVarHeader( const int& x_pos, const int& y_pos, const
cch_icon_x = cch_offset;
cch_icon_w = 0;
cch_text_x = cch_offset;
cch_buttons_w = 0;
cch_buttons_h = 0;
cch_buttons_space = cch_offset;
initDefaultButtons();
addContextButton(buttons);
initCCItems();
initParent(parent);
}
@@ -170,7 +167,7 @@ void CComponentsHeader::initCaptionFont(Font* font)
void CComponentsHeader::setIcon(const char* icon_name)
{
if (icon_name){
string s_icon = static_cast<string>(icon_name);
string s_icon = string(icon_name);
setIcon(s_icon);
}
else
@@ -194,18 +191,12 @@ void CComponentsHeader::initIcon()
return;
}
//create instance for cch_icon_obj
//create instance for cch_icon_obj and add to container at once
if (cch_icon_obj == NULL){
dprintf(DEBUG_DEBUG, "[CComponentsHeader]\n [%s - %d] init header icon: %s\n", __func__, __LINE__, cch_icon_name.c_str());
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, CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER, this);
}
//add item only one time
if (!cch_icon_obj->isAdded())
addCCItem(cch_icon_obj); //icon
//set properties for icon object
if (cch_icon_obj){
//get dimensions of header icon
@@ -215,7 +206,6 @@ void CComponentsHeader::initIcon()
cch_icon_obj->setWidth(iw);
cch_icon_obj->setHeight(ih);
cch_icon_obj->doPaintBg(false);
cch_icon_obj->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER);
//set corner mode of icon item
int cc_icon_corner_type = corner_type;
@@ -236,56 +226,36 @@ void CComponentsHeader::initIcon()
}
}
void CComponentsHeader::addButtonIcon(const std::string& button_name)
void CComponentsHeader::addContextButton(const std::string& button_name)
{
v_cch_btn.push_back(button_name);
initButtons();
}
void CComponentsHeader::removeButtonIcons()
{
v_cch_btn.clear();
cch_btn_obj->removeAllIcons();
initButtons();
}
void CComponentsHeader::initDefaultButtons()
{
if (cch_buttons & CC_BTN_EXIT)
v_cch_btn.push_back(NEUTRINO_ICON_BUTTON_HOME);
if (cch_buttons & CC_BTN_HELP)
v_cch_btn.push_back(NEUTRINO_ICON_BUTTON_HELP);
if (cch_buttons & CC_BTN_INFO)
v_cch_btn.push_back(NEUTRINO_ICON_BUTTON_INFO);
if (cch_buttons & CC_BTN_MENU)
v_cch_btn.push_back(NEUTRINO_ICON_BUTTON_MENU);
dprintf(DEBUG_DEBUG, "[CComponentsHeader] %s added %d default buttons...\n", __func__, (int)v_cch_btn.size());
}
void CComponentsHeader::setDefaultButtons(const int buttons)
void CComponentsHeader::addContextButton(const std::vector<std::string>& v_button_names)
{
cch_buttons = buttons;
v_cch_btn.clear();
initDefaultButtons();
for (size_t i= 0; i< v_button_names.size(); i++)
addContextButton(v_button_names[i]);
}
// calculate minimal width of icon form
void CComponentsHeader::initButtonFormSize()
void CComponentsHeader::addContextButton(const int& buttons)
{
cch_buttons_w = 0;
cch_buttons_h = 0;
if (buttons & CC_BTN_EXIT)
addContextButton(NEUTRINO_ICON_BUTTON_HOME);
if (buttons & CC_BTN_HELP)
addContextButton(NEUTRINO_ICON_BUTTON_HELP);
if (buttons & CC_BTN_INFO)
addContextButton(NEUTRINO_ICON_BUTTON_INFO);
if (buttons & CC_BTN_MENU)
addContextButton(NEUTRINO_ICON_BUTTON_MENU);
}
if (cch_btn_obj == NULL)
return;
for(size_t i=0; i<v_cch_btn.size(); i++){
int bw, bh;
frameBuffer->getIconSize(v_cch_btn[i].c_str(), &bw, &bh);
cch_buttons_w += (bw + cch_buttons_space);
cch_buttons_h = std::max(cch_buttons_h, bh);
}
cch_buttons_w -= cch_buttons_space;
void CComponentsHeader::removeContextButtons()
{
dprintf(DEBUG_DEBUG, "[CComponentsHeader]\t [%s - %d] removing %u context buttons...\n", __func__, __LINE__, v_cch_btn.size());
v_cch_btn.clear();
if (cch_btn_obj)
cch_btn_obj->clear();;
}
void CComponentsHeader::initButtons()
@@ -293,28 +263,21 @@ void CComponentsHeader::initButtons()
//exit if no button defined
if (v_cch_btn.empty()){
if (cch_btn_obj)
delete cch_btn_obj;
cch_btn_obj = NULL;
cch_btn_obj->clear(); //clean up, but hold instance
return;
}
initButtonFormSize();
//create instance for header buttons chain object and add to container
if (cch_btn_obj == NULL){
cch_btn_obj = new CComponentsIconForm();
dprintf(DEBUG_DEBUG, "[CComponentsHeader]\n [%s - %d] init header buttons...\n", __func__, __LINE__);
cch_btn_obj = new CComponentsIconForm(this);
}
//add button form only one time
if (!cch_btn_obj->isAdded())
addCCItem(cch_btn_obj); //buttons
//set button form properties
if (cch_btn_obj){
cch_btn_obj->setDimensionsAll(width-cch_offset-cch_buttons_w, cch_items_y, cch_buttons_w, cch_buttons_h);
cch_btn_obj->setDimensionsAll(0, cch_items_y, 0, 0);
cch_btn_obj->doPaintBg(false);
cch_btn_obj->setIconOffset(cch_buttons_space);
cch_btn_obj->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_RIGHT);
cch_btn_obj->setAppendOffset(cch_buttons_space, 0);
cch_btn_obj->removeAllIcons();
cch_btn_obj->addIcon(v_cch_btn);
@@ -348,8 +311,15 @@ void CComponentsHeader::initCaption()
//calc width of text object in header
cc_text_w = width-cch_text_x-cch_offset;
if (cch_buttons_w)
cc_text_w -= cch_buttons_w-cch_offset;
int buttons_w = 0;
if (cch_btn_obj){
//get width of buttons object
buttons_w = cch_btn_obj->getWidth();
//set x position of buttons
cch_btn_obj->setXPos(width - buttons_w);
}
//set required width of caption object
cc_text_w -= buttons_w-cch_offset;
//create cch_text_obj and add to collection
if (cch_text_obj == NULL){
@@ -367,7 +337,7 @@ void CComponentsHeader::initCaption()
if (cch_caption_align == CTextBox::CENTER)
cch_text_x = CC_CENTERED;
cch_text_obj->setDimensionsAll(cch_text_x, cch_items_y, cc_text_w, height);
cch_text_obj->doPaintBg(false);
cch_text_obj->doPaintBg(true);
cch_text_obj->setText(cch_text, cch_caption_align, cch_font);
cch_text_obj->forceTextPaint(); //here required
cch_text_obj->setTextColor(cch_col_text);