mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-30 00:41:09 +02:00
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.
Origin commit data
------------------
Branch: ni/coolstream
Commit: 6fe7b452c1
Author: Thilo Graf <dbt@novatux.de>
Date: 2014-03-22 (Sat, 22 Mar 2014)
------------------
This commit was generated by Migit
This commit is contained in:
@@ -1587,7 +1587,7 @@ void CAudioPlayerGui::paintHead()
|
||||
|
||||
#ifdef ENABLE_GUI_MOUNT
|
||||
if (!m_inetmode)
|
||||
header.addButtonIcon(NEUTRINO_ICON_BUTTON_MENU);
|
||||
header.setContextButton(NEUTRINO_ICON_BUTTON_MENU);
|
||||
#endif
|
||||
|
||||
header.paint(CC_SAVE_SCREEN_NO);
|
||||
|
@@ -196,10 +196,11 @@ void CComponentsForm::removeCCItem(const uint& cc_item_id)
|
||||
delete v_cc_items[cc_item_id];
|
||||
v_cc_items[cc_item_id] = NULL;
|
||||
v_cc_items.erase(v_cc_items.begin()+cc_item_id);
|
||||
dprintf(DEBUG_DEBUG, "[CComponentsForm] %s removing cc_Item [id=%u]...\n", __func__, cc_item_id);
|
||||
}
|
||||
}
|
||||
else
|
||||
dprintf(DEBUG_NORMAL, "[CComponentsForm] %s removing cc_Item not possible, v_cc_items is empty...\n", __func__);
|
||||
dprintf(DEBUG_NORMAL, "[CComponentsForm] %s removing of cc_Item [id=%u] not possible, v_cc_items is empty...\n", __func__, cc_item_id);
|
||||
}
|
||||
|
||||
void CComponentsForm::removeCCItem(CComponentsItem* cc_Item)
|
||||
|
@@ -31,24 +31,20 @@ using namespace std;
|
||||
//sub class CComponentsFrmChain
|
||||
CComponentsFrmChain::CComponentsFrmChain( const int& x_pos, const int& y_pos, const int& w, const int& h,
|
||||
const std::vector<CComponentsItem*> *v_items,
|
||||
bool horizontal,
|
||||
bool dynamic_width,
|
||||
bool dynamic_height,
|
||||
int direction,
|
||||
CComponentsForm* parent,
|
||||
bool has_shadow,
|
||||
fb_pixel_t& color_frame,
|
||||
fb_pixel_t& color_body,
|
||||
fb_pixel_t& color_shadow)
|
||||
{
|
||||
initVarChain(x_pos, y_pos, w, h, v_items, horizontal, dynamic_width, dynamic_height, parent, has_shadow, color_frame, color_body, color_shadow);
|
||||
initVarChain(x_pos, y_pos, w, h, v_items, direction, parent, has_shadow, color_frame, color_body, color_shadow);
|
||||
}
|
||||
|
||||
|
||||
void CComponentsFrmChain::initVarChain( const int& x_pos, const int& y_pos, const int& w, const int& h,
|
||||
const std::vector<CComponentsItem*> *v_items,
|
||||
bool horizontal,
|
||||
bool dynamic_width,
|
||||
bool dynamic_height,
|
||||
int direction,
|
||||
CComponentsForm* parent,
|
||||
bool has_shadow,
|
||||
fb_pixel_t& color_frame,
|
||||
@@ -68,62 +64,49 @@ void CComponentsFrmChain::initVarChain( const int& x_pos, const int& y_pos, cons
|
||||
col_body = color_body;
|
||||
col_shadow = color_shadow;
|
||||
|
||||
chn_horizontal = horizontal;
|
||||
chn_dyn_height = dynamic_height;
|
||||
chn_dyn_width = dynamic_width;
|
||||
chn_direction = direction;
|
||||
|
||||
if (v_items){
|
||||
if (v_items)
|
||||
addCCItem(*v_items);
|
||||
initCChainItems();
|
||||
}
|
||||
|
||||
initChainItems();
|
||||
initParent(parent);
|
||||
}
|
||||
|
||||
void CComponentsFrmChain::initCChainItems()
|
||||
void CComponentsFrmChain::setDirection(int direction)
|
||||
{
|
||||
if (!v_cc_items.empty()){
|
||||
if (chn_dyn_height)
|
||||
height = 0;
|
||||
if (chn_dyn_width)
|
||||
width = 0;
|
||||
}
|
||||
chn_direction = direction;
|
||||
initChainItems();
|
||||
};
|
||||
|
||||
void CComponentsFrmChain::initChainItems()
|
||||
{
|
||||
//init required dimensions, preferred are current width and height
|
||||
int w_tmp = width;
|
||||
int h_tmp = height;
|
||||
|
||||
//exit if no item available
|
||||
if (v_cc_items.empty())
|
||||
return;
|
||||
|
||||
//set new values
|
||||
w_tmp = append_x_offset;
|
||||
h_tmp = append_y_offset;
|
||||
|
||||
for (size_t i= 0; i< v_cc_items.size(); i++){
|
||||
//set general start position for all items
|
||||
if (i == 0)
|
||||
v_cc_items[i]->setPos(0, 0);
|
||||
|
||||
//set arrangement with required direction
|
||||
if (chn_horizontal){
|
||||
if (i > 0)
|
||||
v_cc_items[i]->setPos(CC_APPEND, 0);
|
||||
}
|
||||
else{
|
||||
if (i > 0)
|
||||
v_cc_items[i]->setPos(0, CC_APPEND);
|
||||
if (chn_direction & CC_DIR_X){
|
||||
w_tmp += v_cc_items[i]->getWidth();
|
||||
w_tmp += append_x_offset;
|
||||
v_cc_items[i]->setPos(CC_APPEND, CC_CENTERED);
|
||||
}
|
||||
|
||||
//assign size
|
||||
if (chn_horizontal){
|
||||
//assign dynamic width
|
||||
if (chn_dyn_width)
|
||||
width += v_cc_items[i]->getWidth();
|
||||
//assign dynamic height
|
||||
if (chn_dyn_height)
|
||||
height = max(v_cc_items[i]->getHeight(), height);
|
||||
else
|
||||
v_cc_items[i]->setHeight(height);
|
||||
}
|
||||
else{
|
||||
//assign dynamic height
|
||||
if (chn_dyn_height)
|
||||
height += v_cc_items[i]->getHeight();
|
||||
//assign dynamic width
|
||||
if (chn_dyn_width)
|
||||
width = max(v_cc_items[i]->getWidth(), width);
|
||||
else
|
||||
v_cc_items[i]->setWidth(width);
|
||||
if (chn_direction & CC_DIR_Y){
|
||||
h_tmp += v_cc_items[i]->getHeight();
|
||||
h_tmp += append_y_offset;
|
||||
v_cc_items[i]->setPos(CC_CENTERED, CC_APPEND);
|
||||
}
|
||||
}
|
||||
width = max (w_tmp, width);
|
||||
height = max (h_tmp, height);
|
||||
}
|
||||
|
||||
|
@@ -36,45 +36,46 @@ You can set default form parameters like position, size, colors etc. and additi
|
||||
to display with defined direction.
|
||||
*/
|
||||
|
||||
//direction types
|
||||
enum
|
||||
{
|
||||
CC_DIR_X = 0x1,
|
||||
CC_DIR_Y = 0x2
|
||||
};
|
||||
|
||||
class CComponentsFrmChain : public CComponentsForm
|
||||
{
|
||||
private:
|
||||
///property: defined arrangement mode of items, can be vertical or horizontal
|
||||
int chn_horizontal;
|
||||
|
||||
///property: defines height from sum of all contained items
|
||||
bool chn_dyn_height;
|
||||
///property: defines width from sum of all contained items
|
||||
bool chn_dyn_width;
|
||||
|
||||
///init all required variables
|
||||
void initVarChain( const int& x_pos, const int& y_pos, const int& w, const int& h,
|
||||
const std::vector<CComponentsItem*> *v_items,
|
||||
bool horizontal,
|
||||
bool dynamic_width,
|
||||
bool dynamic_height,
|
||||
int direction,
|
||||
CComponentsForm* parent,
|
||||
bool has_shadow,
|
||||
fb_pixel_t& color_frame,
|
||||
fb_pixel_t& color_body,
|
||||
fb_pixel_t& color_shadow);
|
||||
|
||||
void initCChainItems();
|
||||
protected:
|
||||
///property: mode for arrangement direction of items, see also setDirection(), getDirection()
|
||||
int chn_direction;
|
||||
|
||||
void initChainItems();
|
||||
|
||||
public:
|
||||
CComponentsFrmChain( const int& x_pos = 1, const int& y_pos = 1, const int& w = 720, const int& h = 32,
|
||||
const std::vector<CComponentsItem*> *v_items = NULL,
|
||||
bool horizontal = true,
|
||||
bool dynamic_width = false,
|
||||
bool dynamic_height = false,
|
||||
int direction = CC_DIR_X,
|
||||
CComponentsForm* parent = 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);
|
||||
// ~CComponentsSlider(); //inherited from CComponentsForm
|
||||
|
||||
///defines mode for arrangement direction of items, see also chn_direction
|
||||
virtual void setDirection(int direction);
|
||||
///gets the mode of arrangment direction
|
||||
virtual int getDirection(){return chn_direction;};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -73,7 +73,6 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
|
||||
else
|
||||
height = cch_font->getHeight();
|
||||
|
||||
cch_buttons = buttons;
|
||||
shadow = has_shadow;
|
||||
col_frame = color_frame;
|
||||
col_body = color_body;
|
||||
@@ -82,7 +81,7 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
|
||||
corner_rad = RADIUS_LARGE;
|
||||
corner_type = CORNER_BOTTOM;
|
||||
|
||||
initDefaultButtons();
|
||||
addContextButton(buttons);
|
||||
initCCItems();
|
||||
initParent(parent);
|
||||
}
|
||||
|
@@ -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;
|
||||
for (size_t i= 0; i< v_button_names.size(); i++)
|
||||
addContextButton(v_button_names[i]);
|
||||
}
|
||||
|
||||
void CComponentsHeader::addContextButton(const int& buttons)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
initDefaultButtons();
|
||||
}
|
||||
|
||||
// calculate minimal width of icon form
|
||||
void CComponentsHeader::initButtonFormSize()
|
||||
{
|
||||
cch_buttons_w = 0;
|
||||
cch_buttons_h = 0;
|
||||
|
||||
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;
|
||||
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);
|
||||
|
@@ -53,7 +53,7 @@ class CComponentsHeader : public CComponentsForm
|
||||
CComponentsPicture * cch_icon_obj;
|
||||
///object: caption object, see also setCaption()
|
||||
CComponentsText * cch_text_obj;
|
||||
///object: context button object, see also addButtonIcon(), removeButtonIcons()
|
||||
///object: context button object, see also addContextButton(), removeContextButtons()
|
||||
CComponentsIconForm * cch_btn_obj;
|
||||
|
||||
///property: caption text, see also setCaption()
|
||||
@@ -73,17 +73,11 @@ class CComponentsHeader : public CComponentsForm
|
||||
int cch_icon_w;
|
||||
///property: internal x-position for caption object
|
||||
int cch_text_x;
|
||||
///property: internal context button definition button icons, see modes CC_BTN_HELP, CC_BTN_INFO, CC_BTN_MENU, CC_BTN_EXIT
|
||||
int cch_buttons;
|
||||
///property: internal width for context button object
|
||||
int cch_buttons_w;
|
||||
///property: internal height for context button object
|
||||
int cch_buttons_h;
|
||||
///property: internal offset of context button icons within context button object
|
||||
int cch_buttons_space;
|
||||
///property: internal offset for header items
|
||||
int cch_offset;
|
||||
///property: internal container of icon names for context button object, see also addButtonIcon()
|
||||
///property: internal container of icon names for context button object, see also addContextButton()
|
||||
std::vector<std::string> v_cch_btn;
|
||||
///property: size of header, possible values are CC_HEADER_SIZE_LARGE, CC_HEADER_SIZE_SMALL
|
||||
int cch_size_mode;
|
||||
@@ -98,10 +92,6 @@ class CComponentsHeader : public CComponentsForm
|
||||
void initCaption();
|
||||
///sub: init context button object
|
||||
void initButtons();
|
||||
///sub: init default buttons for context button object
|
||||
void initDefaultButtons();
|
||||
///sub: init default buttons for context button object
|
||||
void initButtonFormSize();
|
||||
|
||||
public:
|
||||
enum
|
||||
@@ -143,10 +133,23 @@ class CComponentsHeader : public CComponentsForm
|
||||
///set name of icon
|
||||
virtual void setIcon(const std::string& icon_name);
|
||||
|
||||
///add separate button icons to context button object
|
||||
virtual void addButtonIcon(const std::string& button_name);
|
||||
///remove button icons from context button object
|
||||
virtual void removeButtonIcons();
|
||||
///context buttons are to find on the right part of header
|
||||
///add a single context button icon to the header object, arg as string, icon will just add, existing icons are preserved
|
||||
virtual void addContextButton(const std::string& button_name);
|
||||
///add a group of context button icons to the header object, arg as string vector, icons will just add, existing icons are preserved
|
||||
virtual void addContextButton(const std::vector<std::string>& v_button_names);
|
||||
///add a single context button icon or combined button icons to the header object, possible types are for example: CC_BTN_HELP, CC_BTN_INFO, CC_BTN_MENU, CC_BTN_EXIT
|
||||
///icons will just add, existing icons are preserved
|
||||
virtual void addContextButton(const int& buttons);
|
||||
///remove context buttons from context button object
|
||||
virtual void removeContextButtons();
|
||||
///sets a single context button icon to the header object, arg as string, existing buttons are removed
|
||||
virtual void setContextButton(const std::string& button_name){removeContextButtons(); addContextButton(button_name);};
|
||||
///sets a group of context button icons to the header object, arg as string vector, existing buttons are removed
|
||||
virtual void setContextButton(const std::vector<std::string>& v_button_names){removeContextButtons(); addContextButton(v_button_names);};
|
||||
///sets a single context button icon or combined button icons to the header object, possible types are for example: CC_BTN_HELP, CC_BTN_INFO, CC_BTN_MENU, CC_BTN_EXIT
|
||||
///existing buttons are removed
|
||||
virtual void setContextButton(const int& buttons){removeContextButtons(); addContextButton(buttons);};
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -156,8 +159,6 @@ class CComponentsHeader : public CComponentsForm
|
||||
CC_BTN_EXIT = 0x80
|
||||
|
||||
};
|
||||
///set internal context button icons, possible modes CC_BTN_HELP, CC_BTN_INFO, CC_BTN_MENU, CC_BTN_EXIT
|
||||
virtual void setDefaultButtons(const int buttons);
|
||||
///set offset between icons within context button object
|
||||
virtual void setButtonsSpace(const int buttons_space){cch_buttons_space = buttons_space;};
|
||||
|
||||
|
@@ -65,52 +65,52 @@ void CComponentsIconForm::initVarIconForm( const int &x_pos, const int &y_pos, c
|
||||
col_body = color_body;
|
||||
col_shadow = color_shadow;
|
||||
|
||||
ccif_offset = 2;
|
||||
ccif_icon_align = CC_ICONS_FRM_ALIGN_LEFT;
|
||||
chn_direction = CC_DIR_X;
|
||||
|
||||
append_y_offset = 2;
|
||||
|
||||
initChainItems();
|
||||
initParent(parent);
|
||||
}
|
||||
|
||||
void CComponentsIconForm::addIcon(const std::string& icon_name)
|
||||
{
|
||||
v_icons.push_back(icon_name);
|
||||
//create new cc-picture item object
|
||||
CComponentsPicture *ccp = new CComponentsPicture(0, 0, 0, 0, icon_name, CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER, this);
|
||||
ccp->doPaintBg(false);
|
||||
|
||||
initChainItems();
|
||||
}
|
||||
|
||||
void CComponentsIconForm::addIcon(std::vector<std::string> icon_name)
|
||||
{
|
||||
for (size_t i= 0; i< icon_name.size(); i++)
|
||||
v_icons.push_back(icon_name[i]);
|
||||
addIcon(icon_name[i]);
|
||||
}
|
||||
|
||||
void CComponentsIconForm::insertIcon(const uint& icon_id, const std::string& icon_name)
|
||||
{
|
||||
v_icons.insert(v_icons.begin()+icon_id, icon_name);
|
||||
//create new cc-picture item object
|
||||
CComponentsPicture *ccp = new CComponentsPicture(0, 0, 0, 0, icon_name, CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER);
|
||||
ccp->doPaintBg(false);
|
||||
|
||||
insertCCItem(icon_id, ccp);
|
||||
initChainItems();
|
||||
}
|
||||
|
||||
void CComponentsIconForm::removeIcon(const uint& icon_id)
|
||||
{
|
||||
v_icons.erase(v_icons.begin()+icon_id);
|
||||
}
|
||||
|
||||
void CComponentsIconForm::removeIcon(const std::string& icon_name)
|
||||
{
|
||||
int id = getIconId(icon_name);
|
||||
removeIcon(id);
|
||||
}
|
||||
|
||||
int CComponentsIconForm::getIconId(const std::string& icon_name)
|
||||
{
|
||||
for (size_t i= 0; i< v_icons.size(); i++)
|
||||
if (v_icons[i] == icon_name)
|
||||
return i;
|
||||
return -1;
|
||||
removeCCItem(icon_id);
|
||||
initChainItems();
|
||||
}
|
||||
|
||||
//For existing instances it's recommended
|
||||
//to remove old items before add new icons, otherwise icons will be appended.
|
||||
void CComponentsIconForm::removeAllIcons()
|
||||
void CComponentsIconForm::removeAllIcons()//TODO
|
||||
{
|
||||
clear();
|
||||
v_icons.clear();
|
||||
initChainItems();
|
||||
}
|
||||
|
||||
//get maximal form height depends of biggest icon height, but don't touch defined form height
|
||||
@@ -123,72 +123,3 @@ void CComponentsIconForm::initMaxHeight(int *pheight)
|
||||
}
|
||||
}
|
||||
|
||||
void CComponentsIconForm::initCCIcons()
|
||||
{
|
||||
int ccp_y = 0;
|
||||
int ccp_h = 0;
|
||||
int ccp_w = 0;
|
||||
//calculate start pos of first icon
|
||||
int ccp_x = 0 + fr_thickness; //CC_ICONS_FRM_ALIGN_LEFT;
|
||||
|
||||
if (ccif_icon_align == CC_ICONS_FRM_ALIGN_RIGHT)
|
||||
ccp_x += (width - fr_thickness);
|
||||
|
||||
//get width of first icon
|
||||
frameBuffer->getIconSize(v_icons[0].c_str(), &ccp_w, &ccp_h);
|
||||
|
||||
//get maximal form height
|
||||
int h = 0;
|
||||
initMaxHeight(&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
|
||||
size_t i_cnt = v_icons.size(); //icon count
|
||||
|
||||
for (size_t i= 0; i< i_cnt; i++){
|
||||
//create new cc-picture item object
|
||||
CComponentsPicture *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);
|
||||
//add item to form
|
||||
addCCItem(ccp);
|
||||
|
||||
//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 width and height of form
|
||||
int w_tmp = 0;
|
||||
int h_tmp = 0;
|
||||
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);
|
||||
height = max(h_tmp, height);
|
||||
}
|
||||
|
||||
void CComponentsIconForm::paint(bool do_save_bg)
|
||||
{
|
||||
//init and add icons
|
||||
initCCIcons();
|
||||
|
||||
//paint form contents
|
||||
paintForm(do_save_bg);
|
||||
}
|
||||
|
@@ -24,13 +24,12 @@
|
||||
#ifndef __CC_FORM_ICONS_H__
|
||||
#define __CC_FORM_ICONS_H__
|
||||
|
||||
#include "cc_frm.h"
|
||||
#include "cc_frm_chain.h"
|
||||
|
||||
class CComponentsIconForm : public CComponentsForm
|
||||
class CComponentsIconForm : public CComponentsFrmChain
|
||||
{
|
||||
private:
|
||||
std::vector<std::string> v_icons;
|
||||
int ccif_offset, ccif_icon_align;
|
||||
void initMaxHeight(int *pheight);
|
||||
|
||||
protected:
|
||||
@@ -52,25 +51,12 @@ class CComponentsIconForm : public CComponentsForm
|
||||
fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
|
||||
// ~CComponentsIconForm(); //inherited from CComponentsForm
|
||||
|
||||
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
|
||||
void initCCIcons();
|
||||
void addIcon(const std::string& icon_name);
|
||||
void addIcon(std::vector<std::string> icon_name);
|
||||
void removeIcons(){v_icons.clear();};
|
||||
void insertIcon(const uint& icon_id, const std::string& icon_name);
|
||||
void removeIcon(const uint& icon_id);
|
||||
void removeIcon(const std::string& icon_name);
|
||||
void removeAllIcons();
|
||||
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);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -168,7 +168,7 @@ void CComponentsWindow::initHeader()
|
||||
ccw_head->setPos(0, 0);
|
||||
ccw_head->setIcon(ccw_icon_name);
|
||||
ccw_head->setCaption(ccw_caption, ccw_align_mode);
|
||||
ccw_head->setDefaultButtons(ccw_buttons);
|
||||
ccw_head->setContextButton(ccw_buttons);
|
||||
ccw_head->setCorner(corner_rad, CORNER_TOP);
|
||||
}
|
||||
}
|
||||
|
@@ -709,7 +709,7 @@ void CPictureViewerGui::paintHead()
|
||||
CComponentsHeaderLocalized header(x, y, width, theight, LOCALE_PICTUREVIEWER_HEAD, NEUTRINO_ICON_MP3, CComponentsHeaderLocalized::CC_BTN_HELP);
|
||||
|
||||
#ifdef ENABLE_GUI_MOUNT
|
||||
header.addButtonIcon(NEUTRINO_ICON_BUTTON_MENU);
|
||||
header.setContextButton(NEUTRINO_ICON_BUTTON_MENU);
|
||||
#endif
|
||||
|
||||
header.paint(CC_SAVE_SCREEN_NO);
|
||||
|
@@ -482,12 +482,12 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
|
||||
int hh = 30;//g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight();
|
||||
if (header == NULL){
|
||||
header = new CComponentsHeader (100, 50, 500, hh, "Test-Header"/*, NEUTRINO_ICON_INFO, CComponentsHeader::CC_BTN_HELP | CComponentsHeader::CC_BTN_EXIT | CComponentsHeader::CC_BTN_MENU*/);
|
||||
// header->addHeaderButton(NEUTRINO_ICON_BUTTON_RED);
|
||||
header->setDefaultButtons(CComponentsHeader::CC_BTN_HELP | CComponentsHeader::CC_BTN_EXIT | CComponentsHeader::CC_BTN_MENU);
|
||||
header->addContextButton(NEUTRINO_ICON_BUTTON_RED);
|
||||
header->addContextButton(CComponentsHeader::CC_BTN_HELP | CComponentsHeader::CC_BTN_EXIT | CComponentsHeader::CC_BTN_MENU);
|
||||
}
|
||||
// else //For existing instances it's recommended
|
||||
// //to remove old button icons before add new buttons, otherwise icons will be appended.
|
||||
// header->removeHeaderButtons();
|
||||
else //For existing instances it's recommended to remove old button icons before add new buttons,
|
||||
//otherwise icons will be appended to already existant icons, alternatively use the setContextButton() methode
|
||||
header->removeContextButtons();
|
||||
|
||||
// example to manipulate header items
|
||||
// header->setFrameThickness(5);
|
||||
@@ -497,9 +497,19 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
|
||||
// change text of header
|
||||
header->setCaption("Test");
|
||||
|
||||
// add any other button icon
|
||||
// header->addButton(NEUTRINO_ICON_BUTTON_BLUE);
|
||||
// header->addButton(NEUTRINO_ICON_BUTTON_GREEN);
|
||||
//add context buttons via vector
|
||||
// vector<string> v_buttons;
|
||||
// v_buttons.push_back(NEUTRINO_ICON_BUTTON_YELLOW);
|
||||
// v_buttons.push_back(NEUTRINO_ICON_BUTTON_RED);
|
||||
// header->addContextButton(v_buttons);
|
||||
//
|
||||
// // add any other button icon via string
|
||||
// header->addContextButton(NEUTRINO_ICON_BUTTON_BLUE);
|
||||
// header->addContextButton(NEUTRINO_ICON_BUTTON_GREEN);
|
||||
// header->addContextButton(CComponentsHeader::CC_BTN_HELP | CComponentsHeader::CC_BTN_EXIT | CComponentsHeader::CC_BTN_MENU);
|
||||
|
||||
// set a single button, this will also remove all existant context button icons from header
|
||||
// header->setContextButton(NEUTRINO_ICON_HINT_AUDIO);
|
||||
|
||||
// example to replace the text item with an image item
|
||||
// get text x position
|
||||
@@ -540,11 +550,12 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
|
||||
if (iconform == NULL)
|
||||
iconform = new CComponentsIconForm();
|
||||
iconform->setColorBody(COL_LIGHT_GRAY);
|
||||
iconform->setDimensionsAll(100, 100, 480, 60);
|
||||
iconform->setDimensionsAll(100, 100,80/*480*/, 80);
|
||||
iconform->setFrameThickness(2);
|
||||
iconform->setColorFrame(COL_WHITE);
|
||||
iconform->setIconOffset(5);
|
||||
iconform->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_RIGHT);
|
||||
iconform->setDirection(CC_DIR_X);
|
||||
iconform->setAppendOffset(5, 5);
|
||||
|
||||
//For existing instances it's recommended
|
||||
//to remove old items before add new icons, otherwise icons will be appended.
|
||||
iconform->removeAllIcons();
|
||||
|
@@ -956,7 +956,7 @@ void CUpnpBrowserGui::paintDevices()
|
||||
// Head
|
||||
CComponentsHeaderLocalized header(m_x, m_y + m_title_height, m_width, m_theight, LOCALE_UPNPBROWSER_HEAD, NEUTRINO_ICON_UPNP);
|
||||
if (CNeutrinoApp::getInstance()->isMuted())
|
||||
header.addButtonIcon(NEUTRINO_ICON_BUTTON_MUTE_SMALL);
|
||||
header.addContextButton(NEUTRINO_ICON_BUTTON_MUTE_SMALL);
|
||||
header.paint(CC_SAVE_SCREEN_NO);
|
||||
|
||||
// Items
|
||||
@@ -1130,7 +1130,7 @@ printf("CUpnpBrowserGui::paintItem:s selected %d max %d offset %d\n", selected,
|
||||
name += m_devices[m_selecteddevice].friendlyname;
|
||||
CComponentsHeader header(m_x, m_y + m_title_height, m_width, m_theight, name, NEUTRINO_ICON_UPNP);
|
||||
if (CNeutrinoApp::getInstance()->isMuted())
|
||||
header.addButtonIcon(NEUTRINO_ICON_BUTTON_MUTE_SMALL);
|
||||
header.setContextButton(NEUTRINO_ICON_BUTTON_MUTE_SMALL);
|
||||
header.paint(CC_SAVE_SCREEN_NO);
|
||||
|
||||
// Items
|
||||
|
Reference in New Issue
Block a user