CComponentsHeader: rework constructors, add CComponentsHeaderLocalized

Member initVarHeader() now used with parameters, so it's possible
to remove multiple code in constructors, but some class must be
renamed to CComponentsHeaderLocalized.


Origin commit data
------------------
Branch: ni/coolstream
Commit: 5ea7ec48df
Author: Thilo Graf <dbt@novatux.de>
Date: 2014-01-18 (Sat, 18 Jan 2014)

Origin message was:
------------------
CComponentsHeader: rework constructors, add CComponentsHeaderLocalized

Member initVarHeader() now used with parameters, so it's possible
to remove multiple code in constructors, but some class must be
renamed to CComponentsHeaderLocalized.


------------------
This commit was generated by Migit
This commit is contained in:
2014-01-18 20:41:55 +01:00
parent c0a8841ab4
commit 9585b49365
18 changed files with 271 additions and 140 deletions

View File

@@ -37,80 +37,79 @@ using namespace std;
CComponentsHeader::CComponentsHeader()
{
//CComponentsHeader
initVarHeader();
initVarHeader(1, 1, 0, 0, "", "", 0);
}
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::CComponentsHeader( const int& x_pos, const int& y_pos, const int& w, const int& h,
const std::string& caption,
const std::string& icon_name,
const int& buttons,
bool has_shadow,
fb_pixel_t color_frame,
fb_pixel_t color_body,
fb_pixel_t color_shadow)
{
//CComponentsHeader
initVarHeader();
x = x_pos;
y = y_pos;
width = w;
if (h > 0) {
userHeight = true;
height = h;
}
shadow = has_shadow;
col_frame = color_frame;
col_body = color_body;
col_shadow = color_shadow;
cch_text = caption;
cch_icon_name = icon_name;
cch_buttons = buttons;
initDefaultButtons();
initCCItems();
initVarHeader(x_pos, y_pos, w, h, caption, icon_name, buttons, has_shadow, color_frame, color_body, color_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
initVarHeader();
x = x_pos;
y = y_pos;
width = w;
if (h > 0) {
userHeight = true;
height = h;
}
shadow = has_shadow;
col_frame = color_frame;
col_body = color_body;
col_shadow = color_shadow;
cch_text = g_Locale->getText(caption_locale);
cch_icon_name = icon_name;
cch_buttons = buttons;
CComponentsHeaderLocalized::CComponentsHeaderLocalized( const int& x_pos, const int& y_pos, const int& w, const int& h,
neutrino_locale_t caption_locale,
const std::string& icon_name,
const int& buttons,
bool has_shadow,
fb_pixel_t color_frame,
fb_pixel_t color_body,
fb_pixel_t color_shadow)
:CComponentsHeader( x_pos, y_pos, w, h,
g_Locale->getText(caption_locale),
icon_name, buttons,
has_shadow,
color_frame, color_body, color_shadow){};
initDefaultButtons();
initCCItems();
}
void CComponentsHeader::initVarHeader()
void CComponentsHeader::initVarHeader( const int& x_pos, const int& y_pos, const int& w, const int& h,
const std::string& caption,
const std::string& icon_name,
const int& buttons,
bool has_shadow,
fb_pixel_t color_frame,
fb_pixel_t color_body,
fb_pixel_t color_shadow)
{
cc_item_type = CC_ITEMTYPE_FRM_HEADER;
col_body = COL_MENUHEAD_PLUS_0;
corner_rad = RADIUS_LARGE,
corner_type = CORNER_TOP;
x = x_pos;
y = y_pos;
//init header width
width = w == 0 ? frameBuffer->getScreenWidth(true) : w;
//init header height
cch_size_mode = CC_HEADER_SIZE_LARGE;
cch_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE];
height = cch_font->getHeight();
userHeight = false;
//CComponentsHeader
if (h > 0) {
userHeight = true;
height = h;
}
else{
userHeight = false;
height = cch_font->getHeight();
}
shadow = has_shadow;
col_frame = color_frame;
col_body = color_body;
col_shadow = color_shadow;
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;
cch_icon_obj = NULL;
cch_text_obj = NULL;
cch_icon_name = NULL;
cch_btn_obj = NULL;
cch_text = "";
cch_col_text = COL_MENUHEAD_TEXT;
cch_caption_align = CTextBox::NO_AUTO_LINEBREAK;
cch_items_y = 0;
@@ -118,11 +117,12 @@ void CComponentsHeader::initVarHeader()
cch_icon_x = cch_offset;
cch_icon_w = 0;
cch_text_x = cch_offset;
cch_buttons = 0;
cch_buttons_w = 0;
cch_buttons_h = 0;
cch_buttons_space = cch_offset;
v_cch_btn.clear();
initDefaultButtons();
initCCItems();
}
CComponentsHeader::~CComponentsHeader()
@@ -152,6 +152,16 @@ void CComponentsHeader::setCaptionFont(Font* font_name)
}
void CComponentsHeader::setIcon(const char* icon_name)
{
if (icon_name){
string s_icon = static_cast<string>(icon_name);
setIcon(s_icon);
}
else
setIcon("");
}
void CComponentsHeader::setIcon(const std::string& icon_name)
{
cch_icon_name = icon_name;
}
@@ -159,18 +169,19 @@ void CComponentsHeader::setIcon(const char* icon_name)
void CComponentsHeader::initIcon()
{
//init cch_icon_obj only if an icon available
if (cch_icon_name == NULL) {
if (cch_icon_name.empty()) {
cch_icon_w = 0;
if (cch_icon_obj)
if (cch_icon_obj){
delete cch_icon_obj;
cch_icon_obj = NULL;
cch_icon_obj = NULL;
}
return;
}
//create instance for cch_icon_obj
if (cch_icon_obj == NULL){
#ifdef DEBUG_CC
printf(" [CComponentsHeader]\n [%s - %d] init header icon: %s\n", __func__, __LINE__, cch_icon_name);
printf(" [CComponentsHeader]\n [%s - %d] init header icon: %s\n", __func__, __LINE__, cch_icon_name.c_str());
#endif
cch_icon_obj = new CComponentsPicture(cch_icon_x, cch_items_y, 0, 0, cch_icon_name);
}
@@ -179,12 +190,14 @@ void CComponentsHeader::initIcon()
if (!cch_icon_obj->isAdded())
addCCItem(cch_icon_obj); //icon
//get dimensions of header icon
int iw, ih;
frameBuffer->getIconSize(cch_icon_name, &iw, &ih);
//set properties for icon object
if (cch_icon_obj){
//get dimensions of header icon
int iw = 0;
int ih = 0;
cch_icon_obj->getPictureSize(&iw, &ih);
cch_icon_obj->setWidth(iw);
cch_icon_obj->setHeight(ih);
cch_icon_obj->doPaintBg(false);
@@ -318,7 +331,7 @@ void CComponentsHeader::initCaption()
{
//recalc header text position if header icon is defined
int cc_text_w = 0;
if (cch_icon_name != NULL){
if (!cch_icon_name.empty()){
cch_text_x = cch_icon_x+cch_icon_w+cch_offset;
}