diff --git a/src/gui/components/cc_item_text.cpp b/src/gui/components/cc_item_text.cpp index c851a49fa..bf52a4f33 100644 --- a/src/gui/components/cc_item_text.cpp +++ b/src/gui/components/cc_item_text.cpp @@ -86,10 +86,11 @@ void CComponentsText::initVarText( const int x_pos, const int y_pos, const int w ct_text_mode = mode; ct_text_style = font_style; - iX = x = x_old = x_pos; //TODO: equalize inhertited member names - iY = y = y_old = y_pos; - iWidth = width_old = width = w; - iHeight = height_old = height = h; + fr_thickness = 0; + x = x_old = x_pos; + y = y_old = y_pos; + width = width_old = w; + height = height_old = h; /* we need a minimal borderwith of 1px because the edge-smoothing (or fontrenderer?) otherwise will paint single pixels outside the @@ -103,7 +104,7 @@ void CComponentsText::initVarText( const int x_pos, const int y_pos, const int w col_frame = color_frame; col_body = color_body; col_shadow = color_shadow; - fr_thickness = 0; + ct_text_sent = false; ct_paint_textbg = false; ct_force_text_paint = false; @@ -114,6 +115,27 @@ void CComponentsText::initVarText( const int x_pos, const int y_pos, const int w } +void CComponentsText::initCBox() +{ + x = max(0, x); + y = max(0, y); + + int x_box = x + fr_thickness; + int y_box = y + fr_thickness; + + if (cc_parent){ + ct_box.iX = cc_xr; + ct_box.iY = cc_yr; + }else{ + ct_box.iX = x_box; + ct_box.iY = y_box; + } + + ct_box.iWidth = width - 2*fr_thickness; + ct_box.iHeight = height - 2*fr_thickness; +} + + void CComponentsText::initCCText() { //set default font, if is no font definied @@ -121,41 +143,32 @@ void CComponentsText::initCCText() ct_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]; //define height from font size - height = max(height, ct_font->getHeight()); - - //init CBox dimensions - iWidth = width-2*fr_thickness; - iHeight = height-2*fr_thickness; - - //using of real x/y values to paint textbox if this text object is bound in a parent form - if (cc_parent){ - int th_parent_fr = cc_parent->getFrameThickness(); - iX = cc_xr + (x <= th_parent_fr ? th_parent_fr : 0); - iY = cc_yr - (y <= th_parent_fr ? th_parent_fr : 0); - }else{ - iX = x; - iY = y; - } - iX += fr_thickness; - iY += fr_thickness; + int h_tmp = ct_font->getHeight(); + height = max(height, h_tmp-2*fr_thickness); + if (width == 0) + width = max(width, CTextBox::getMaxLineWidth(ct_text, ct_font)-2*fr_thickness); //init textbox + initCBox(); + if (ct_textbox == NULL) ct_textbox = new CTextBox(); - //set text box properties + //set text properties ct_textbox->setTextFont(ct_font); ct_textbox->setTextMode(ct_text_mode); - ct_textbox->setWindowPos(this); + ct_textbox->setTextColor(ct_col_text); + ct_textbox->enableUTF8(ct_utf8_encoded); + + //set text box properties + ct_textbox->setWindowPos(&ct_box); + ct_textbox->setWindowMaxDimensions(ct_box.iWidth, ct_box.iHeight); + ct_textbox->setWindowMinDimensions(ct_box.iWidth, ct_box.iHeight); ct_textbox->setTextBorderWidth(ct_text_Hborder, ct_text_Vborder); ct_textbox->enableBackgroundPaint(ct_paint_textbg && !cc_txt_save_screen); ct_textbox->setBackGroundColor(col_body); - ct_textbox->setBackGroundRadius(corner_rad-fr_thickness, corner_type); - ct_textbox->setTextColor(ct_col_text); - ct_textbox->setWindowMaxDimensions(iWidth, iHeight); - ct_textbox->setWindowMinDimensions(iWidth, iHeight); + ct_textbox->setBackGroundRadius(0/*(corner_type ? corner_rad-fr_thickness : 0), corner_type*/); ct_textbox->enableSaveScreen(cc_txt_save_screen && !ct_paint_textbg); - ct_textbox->enableUTF8(ct_utf8_encoded); //observe behavior of parent form if available bool force_text_paint = ct_force_text_paint; @@ -169,7 +182,7 @@ void CComponentsText::initCCText() #endif //send text to CTextBox object, but force text paint text if force_text_paint option is enabled //this is managed by CTextBox object itself - ct_text_sent = ct_textbox->setText(&ct_text, this->iWidth, force_text_paint); + ct_text_sent = ct_textbox->setText(&ct_text, ct_box.iWidth, force_text_paint); //set current text status, needed by textChanged() if (ct_text_sent){ @@ -180,7 +193,7 @@ void CComponentsText::initCCText() //ensure clean font rendering on transparency background ct_textbox->setTextRenderModeFullBG(!paint_bg); -// dprintf(DEBUG_NORMAL, "[CComponentsText] [%s - %d] init text: %s [x %d x_old %d, y %d y_old %d, w %d, h %d]\n", __func__, __LINE__, ct_text.c_str(), this->x, x_old, this->y, y_old, this->iWidth, this->iHeight); +// dprintf(DEBUG_NORMAL, "[CComponentsText] [%s - %d] ct_text = %s, x = %d , x_old = %d , y = %d , y_old = %d , \nct_box.iWidth = %d , ct_box.iHeight = %d , width = %d , height = %d, corner_rad = %d\n", __func__, __LINE__, ct_text.c_str(), x, x_old, y, y_old, ct_box.iWidth, ct_box.iHeight, width, height, corner_rad); } void CComponentsText::clearCCText() @@ -287,25 +300,25 @@ void CComponentsText::hide() void CComponentsText::setXPos(const int& xpos) { CCDraw::setXPos(xpos); - iX = x; + initCBox(); } void CComponentsText::setYPos(const int& ypos) { CCDraw::setYPos(ypos); - iY = y; + initCBox(); } void CComponentsText::setHeight(const int& h) { CCDraw::setHeight(h); - iHeight = height; + initCBox(); } void CComponentsText::setWidth(const int& w) { CCDraw::setWidth(w); - iWidth = width; + initCBox(); } //small helper to remove excessiv linbreaks diff --git a/src/gui/components/cc_item_text.h b/src/gui/components/cc_item_text.h index dd26f02ad..7bd5f6372 100644 --- a/src/gui/components/cc_item_text.h +++ b/src/gui/components/cc_item_text.h @@ -40,11 +40,12 @@ Handling of text parts based up CTextBox attributes and methodes. CComponentsText provides a interface to the embedded CTextBox object. */ -class CComponentsText : public CCTextScreen, public CComponentsItem, public CBox +class CComponentsText : public CCTextScreen, public CComponentsItem { protected: ///object: CTextBox object CTextBox * ct_textbox; + CBox ct_box; ///object: Fontrenderer object Font * ct_font; ///property: font style @@ -96,6 +97,9 @@ class CComponentsText : public CCTextScreen, public CComponentsItem, public CBox ///initialize all required attributes for text and send to the CTextBox object void initCCText(); + ///init internal CBox object required by CTextBox object + void initCBox(); + ///paint CCItem backckrond (if paint_bg=true), apply initCCText() and send paint() to the CTextBox object void paintText(bool do_save_bg = CC_SAVE_SCREEN_YES); public: @@ -105,7 +109,7 @@ class CComponentsText : public CCTextScreen, public CComponentsItem, public CBox FONT_STYLE_ITALIC = 2 }; - CComponentsText( const int x_pos = 10, const int y_pos = 10, const int w = 150, const int h = 50, + CComponentsText( const int x_pos = 10, const int y_pos = 10, const int w = 0, const int h = 0, std::string text = "", const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL,