From ca42d9ba747a79fddaead3ed28f407d84391446d Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Fri, 15 Mar 2013 22:55:45 +0100 Subject: [PATCH] CComponentsHeader/Window: add possibility to return header height --- src/gui/components/cc.h | 9 ++++-- src/gui/components/cc_frm_header.cpp | 45 ++++++++++++++++++---------- src/gui/components/cc_frm_window.cpp | 17 ++++++++--- 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index 20dee898b..595037e5a 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -198,8 +198,8 @@ class CComponentsText : public CComponentsItem virtual inline void setTextFont(Font* font_text){ct_font = font_text;}; virtual inline void setTextColor(fb_pixel_t color_text){ ct_col_text = color_text;}; virtual inline void setTextMode(const int mode){ct_text_mode = mode;};//see textbox.h for possible modes - virtual inline void setText(const char* ctext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL){ct_text = ctext; ct_text_mode = mode, ct_font = font_text;}; - virtual inline void setText(const std::string& stext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL){ct_text = stext.c_str(); ct_text_mode = mode, ct_font = font_text;}; + virtual void setText(const char* ctext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); + virtual void setText(const std::string& stext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); virtual void setText(neutrino_locale_t locale_text, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL); virtual void removeLineBreaks(std::string& str); }; @@ -454,7 +454,6 @@ class CComponentsHeader : public CComponentsForm void initCCHeaderIcon(); void initCCHeaderText(); void initCCHeaderButtons(); - void initCCHItems(); void initCCHDefaultButtons(); void initCCButtonFormSize(); @@ -493,6 +492,7 @@ class CComponentsHeader : public CComponentsForm void addHeaderButton(const std::string& button_name); void removeHeaderButtons(); void setHeaderButtons(const int buttons){cch_buttons = buttons;}; + void initCCHeaderItems(); }; class CComponentsWindow : public CComponentsForm @@ -501,6 +501,7 @@ class CComponentsWindow : public CComponentsForm CComponentsHeader * ccw_head; std::string ccw_caption; const char* ccw_icon_name; + int ccw_start_y; void initHeader(); void initCCWItems(); @@ -522,6 +523,8 @@ class CComponentsWindow : public CComponentsForm void setWindowCaption(const std::string& text){ccw_caption = text;}; void setWindowCaption(neutrino_locale_t locale_text); void setWindowIcon(const char* iconname){ccw_icon_name = iconname;}; + + int getStartY(); //y value for start of the area below header }; #endif diff --git a/src/gui/components/cc_frm_header.cpp b/src/gui/components/cc_frm_header.cpp index 4b6460885..ef2f38639 100644 --- a/src/gui/components/cc_frm_header.cpp +++ b/src/gui/components/cc_frm_header.cpp @@ -61,7 +61,7 @@ CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const in cch_icon_name = icon_name; cch_buttons = buttons; initCCHDefaultButtons(); - initCCHItems(); + initCCHeaderItems(); } 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, @@ -84,13 +84,23 @@ CComponentsHeader::CComponentsHeader( const int x_pos, const int y_pos, const in cch_buttons = buttons; initCCHDefaultButtons(); - initCCHItems(); + initCCHeaderItems(); } void CComponentsHeader::initVarHeader() { - //CComponentsHeader + //CComponentsForm + initVarForm(); + cc_item_type = CC_ITEMTYPE_FRM_HEADER; + col_body = COL_MENUHEAD_PLUS_0; + corner_rad = RADIUS_LARGE, + corner_type = CORNER_TOP; + + //init header height cch_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]; + height = cch_font->getHeight(); + + //CComponentsHeader cch_icon_obj = NULL; cch_text_obj = NULL; cch_icon_name = NULL; @@ -107,13 +117,7 @@ void CComponentsHeader::initVarHeader() cch_btn_offset = 8; v_cch_btn.clear(); - //CComponentsForm - initVarForm(); - cc_item_type = CC_ITEMTYPE_FRM_HEADER; - height = cch_font->getHeight(); - col_body = COL_MENUHEAD_PLUS_0; - corner_rad = RADIUS_LARGE, - corner_type = CORNER_TOP; + } CComponentsHeader::~CComponentsHeader() @@ -182,6 +186,9 @@ void CComponentsHeader::initCCHeaderIcon() //set width of icon object cch_icon_w = cch_icon_obj->getWidth(); + + //adapt height + height = max(height, cch_icon_obj->getHeight()); } } @@ -250,6 +257,7 @@ void CComponentsHeader::initCCHeaderButtons() cch_btn_obj->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_RIGHT); cch_btn_obj->removeAllIcons(); cch_btn_obj->addIcon(v_cch_btn); + height = max(height, cch_btn_obj->getHeight()); } } @@ -263,27 +271,32 @@ void CComponentsHeader::initCCHeaderText() #ifdef DEBUG_CC printf(" [CComponentsHeader]\n [%s - %d] init header text: %s\n", __FUNCTION__, __LINE__, cch_text.c_str()); #endif - 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 = new CComponentsText(); //add text item addCCItem(cch_text_obj); //text } //set header text properties if (cch_text_obj){ - cch_text_obj->setText(cch_text); - cch_text_obj->setTextMode(CTextBox::AUTO_WIDTH); - cch_text_obj->setTextFont(cch_font); + cch_text_obj->setText(cch_text, CTextBox::AUTO_WIDTH, cch_font); + cch_text_obj->setDimensionsAll(cch_text_x, cch_items_y, width-cch_icon_w-fr_thickness, height-2*fr_thickness); +// cch_text_obj->setTextFont(cch_font) cch_text_obj->setTextColor(cch_col_text); +// cch_text_obj->setTextMode(CTextBox::AUTO_WIDTH); + cch_text_obj->setColorBody(col_body); cch_text_obj->doPaintBg(false); //corner of text item cch_text_obj->setCornerRadius(corner_rad-fr_thickness); cch_text_obj->setCornerType(corner_type); + + //get height + height = max(height, cch_text_obj->getHeight()); } } -void CComponentsHeader::initCCHItems() +void CComponentsHeader::initCCHeaderItems() { //init icon initCCHeaderIcon(); @@ -298,7 +311,7 @@ void CComponentsHeader::initCCHItems() void CComponentsHeader::paint(bool do_save_bg) { //prepare items - initCCHItems(); + initCCHeaderItems(); //paint form contents paintForm(do_save_bg); diff --git a/src/gui/components/cc_frm_window.cpp b/src/gui/components/cc_frm_window.cpp index dad85cff5..d62deecd5 100644 --- a/src/gui/components/cc_frm_window.cpp +++ b/src/gui/components/cc_frm_window.cpp @@ -71,16 +71,17 @@ void CComponentsWindow::initVarWindow() //CComponentsForm initVarForm(); cc_item_type = CC_ITEMTYPE_FRM_WINDOW; - - ccw_head = NULL; - ccw_caption = ""; - ccw_icon_name = NULL; //using current screen settings for default dimensions width = frameBuffer->getScreenWidth(); height = frameBuffer->getScreenHeight(); x=getScreenStartX(width); y=getScreenStartY(height); + + ccw_head = NULL; + ccw_caption = ""; + ccw_icon_name = NULL; + ccw_start_y = 0; setShadowOnOff(true); } @@ -106,9 +107,17 @@ void CComponentsWindow::initHeader() ccw_head->setWidth(width); ccw_head->setHeaderIcon(ccw_icon_name); ccw_head->setHeaderText(ccw_caption); + ccw_head->initCCHeaderItems(); + ccw_start_y = ccw_head->getHeight(); } } +int CComponentsWindow::getStartY() +{ + initHeader(); + return ccw_start_y; +} + void CComponentsWindow::initCCWItems() { #ifdef DEBUG_CC