CComponentsText: fix paint text into Textbox

This commit is contained in:
2012-10-26 23:53:05 +02:00
parent ed5aac229b
commit 80ffab8999
2 changed files with 62 additions and 63 deletions

View File

@@ -226,28 +226,25 @@ class CComponentsText : public CComponentsItem
fb_pixel_t ct_col_text;
int ct_text_mode; //see textbox.h for possible modes
const char* ct_text;
bool ct_text_sent;
void initVarText();
void clearCCText();
private:
bool ct_text_sended;
void initCCText();
void paintText(bool do_save_bg = CC_SAVE_SCREEN_YES);
public:
CComponentsText();
~CComponentsText();
// inline void setText(const char* text, const int text_mode=~CTextBox::AUTO_WIDTH, Font* font_text=NULL){ct_text = text; ct_text_mode = text_mode, ct_font = font_text;};
void hide(bool no_restore = false);
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
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(neutrino_locale_t locale_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL);
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(neutrino_locale_t locale_text, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL);
};
#define INFO_BOX_Y_OFFSET 2
@@ -260,7 +257,7 @@ class CComponentsInfoBox : public CComponentsText
std::string pic_default_name;
void paintPicture();
void paintText();
// void paintText();
void initVarInfobox();
std::string pic_name;
@@ -273,12 +270,6 @@ class CComponentsInfoBox : public CComponentsText
~CComponentsInfoBox();
// inline void setText(const char* info_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL){text = info_text; ct_text_mode = mode, ct_font = font_text;};
// inline void setText(const std::string& info_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL){text = info_text.c_str(); ct_text_mode = mode, ct_font = font_text;};
// void setText(neutrino_locale_t locale_text, const int mode = CTextBox::AUTO_WIDTH, Font* font_text = NULL);
// inline void setTextMode(const int mode){text_mode = mode;};//see textbox.h for possible modes
// inline void setTextFont(Font* font_text){ct_font = font_text;};
// inline void setTextColor(fb_pixel_t color_text){ ibox_col_text = color_text;};
inline void setSpaceOffset(const int offset){x_offset = offset;};
inline void setPicture(const std::string& picture_name){pic_name = picture_name;};

View File

@@ -289,9 +289,9 @@ void CComponentsText::initVarText()
ct_box = NULL;
ct_textbox = NULL;
ct_text = NULL;
ct_text_mode = CTextBox::SCROLL;
ct_text_mode = CTextBox::AUTO_WIDTH;
ct_col_text = COL_MENUCONTENT;
ct_text_sended = false;
ct_text_sent = false;
}
@@ -301,9 +301,8 @@ void CComponentsText::initCCText()
if (ct_font == NULL)
ct_font = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL];
//define height and width from font size
height = max(height, ct_font->getHeight() );
width = max(width, ct_font->getRenderWidth(ct_text, true) );
//define height from font size
height = max(height, ct_font->getHeight());
//text box dimensions
if (ct_box == NULL)
@@ -315,19 +314,24 @@ void CComponentsText::initCCText()
//init textbox
if (ct_textbox == NULL)
ct_textbox = new CTextBox(ct_text);
ct_textbox = new CTextBox();
//set text box properties
ct_textbox->setTextBorderWidth(0);
ct_textbox->enableBackgroundPaint(false);
ct_textbox->setTextFont(ct_font);
ct_textbox->setTextMode(ct_text_mode);
ct_textbox->movePosition(ct_box->iX, ct_box->iY);
ct_textbox->setWindowPos(ct_box);
ct_textbox->setTextBorderWidth(0);
ct_textbox->enableBackgroundPaint(false);
//ct_textbox->setBackGroundColor(COL_RED);
ct_textbox->setBackGroundRadius(corner_rad-fr_thickness, corner_type);
//ct_textbox->movePosition(ct_box->iX, ct_box->iY);
ct_textbox->setTextColor(ct_col_text);
ct_textbox->setWindowMaxDimensions(ct_box->iWidth, ct_box->iHeight);
ct_textbox->setWindowMinDimensions(ct_box->iWidth, ct_box->iHeight);
//set text
string new_text = static_cast <string> (ct_text);
ct_text_sended = ct_textbox->setText(&new_text, width);
ct_text_sent = ct_textbox->setText(&new_text, ct_box->iWidth);
}
void CComponentsText::clearCCText()
@@ -348,13 +352,18 @@ void CComponentsText::setText(neutrino_locale_t locale_text, int mode, Font* fon
ct_font = font_text;
}
void CComponentsText::paintText(bool do_save_bg)
{
paintInit(do_save_bg);
initCCText();
if (ct_text_sent)
ct_textbox->paint();
ct_text_sent = false;
}
void CComponentsText::paint(bool do_save_bg)
{
initCCText();
paintInit(do_save_bg);
if (ct_text_sended)
ct_textbox->paint();
ct_text_sended = false;
paintText(do_save_bg);
}
void CComponentsText::hide(bool no_restore)
@@ -408,7 +417,6 @@ void CComponentsInfoBox::initVarInfobox()
{
//CComponents, CComponentsItem, CComponentsText
initVarText();
ct_text_mode = CTextBox::AUTO_WIDTH;
//CComponentsInfoBox
pic = NULL;
@@ -433,38 +441,38 @@ void CComponentsInfoBox::paintPicture()
pic->setHeight(height-2*fr_thickness);
pic->setColorBody(col_body);
pic->paint();
pic->paint(CC_SAVE_SCREEN_NO);
}
void CComponentsInfoBox::paintText()
{
if (ct_box == NULL)
ct_box = new CBox();
ct_box->iX = x_text;
ct_box->iY = y+fr_thickness;
//text width and height
ct_box->iWidth = width-2*fr_thickness-(x_text-x);
ct_box->iHeight = height-2*fr_thickness;
//init textbox
if (ct_textbox == NULL) {
ct_textbox = new CTextBox(ct_text, ct_font, ct_text_mode, ct_box, col_body);
ct_textbox->setTextBorderWidth(0);
ct_textbox->enableBackgroundPaint(false);
}
//set properties
ct_textbox->setTextFont(ct_font);
ct_textbox->setWindowPos(ct_box);
ct_textbox->setTextColor(ct_col_text);
//set text
string new_text = static_cast <string> (ct_text);
if (ct_textbox->setText(&new_text))
ct_textbox->paint();
}
// void CComponentsInfoBox::paintText()
// {
// if (ct_box == NULL)
// ct_box = new CBox();
//
// ct_box->iX = x_text;
// ct_box->iY = y+fr_thickness;
//
// //text width and height
// ct_box->iWidth = width-2*fr_thickness-(x_text-x);
// ct_box->iHeight = height-2*fr_thickness;
//
// //init textbox
// if (ct_textbox == NULL) {
// ct_textbox = new CTextBox(ct_text, ct_font, ct_text_mode, ct_box, col_body);
// ct_textbox->setTextBorderWidth(0);
// ct_textbox->enableBackgroundPaint(false);
// }
//
// //set properties
// ct_textbox->setTextFont(ct_font);
// ct_textbox->setWindowPos(ct_box);
// ct_textbox->setTextColor(ct_col_text);
//
// //set text
// string new_text = static_cast <string> (ct_text);
// if (ct_textbox->setText(&new_text))
// ct_textbox->paint();
// }
void CComponentsInfoBox::paint(bool do_save_bg)
{
@@ -481,7 +489,7 @@ void CComponentsInfoBox::paint(bool do_save_bg)
}
if (ct_text)
paintText();
paintText(CC_SAVE_SCREEN_NO);
ct_text = NULL;
}