CComponents: add sub class CComponentsText

Origin commit data
------------------
Branch: ni/coolstream
Commit: d8447b9110
Author: Thilo Graf <dbt@novatux.de>
Date: 2012-09-24 (Mon, 24 Sep 2012)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
2012-09-24 20:21:11 +02:00
parent dd48917b6d
commit 20b0197244
2 changed files with 113 additions and 0 deletions

View File

@@ -410,4 +410,30 @@ class CComponentsForm : public CComponentsContainer
void setIcon(const std::string& icon_name){tb_icon = icon_name;};
};
class CComponentsText : public CComponentsContainer
{
private:
Font* ct_font;
CBox * ct_box;
CTextBox * ct_textbox;
const char* ct_text;
int ct_text_mode; //see textbox.h for possible modes
fb_pixel_t ct_col_text;
bool ct_text_sended;
void initVarText();
void initText();
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);
void setTextFont(Font* font_text){ct_font = font_text;};
};
#endif

View File

@@ -1456,3 +1456,90 @@ void CComponentsForm::hide(bool no_restore)
hideContainer(no_restore);
}
//sub class CComponentsText from CComponentsContainer
CComponentsText::CComponentsText()
{
//CComponentsText
initVarText();
}
CComponentsText::~CComponentsText()
{
hide();
clearSavedScreen();
delete ct_font;
delete ct_box;
delete ct_textbox;
clear();
}
void CComponentsText::initVarText()
{
//CComponents, CComponentsContainer
initVarContainer();
//CComponentsText
ct_font = NULL;
ct_box = NULL;
ct_textbox = NULL;
ct_text = NULL;
ct_text_mode = CTextBox::SCROLL;
ct_col_text = COL_MENUCONTENT;
ct_text_sended = false;
}
void CComponentsText::initText()
{
//set default font, if is no font definied
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) );
//text box dimensions
if (ct_box == NULL)
ct_box = new CBox();
ct_box->iX = x+fr_thickness;
ct_box->iY = y+fr_thickness;
ct_box->iWidth = width-2*fr_thickness;
ct_box->iHeight = height-2*fr_thickness;
//init textbox
if (ct_textbox == NULL)
ct_textbox = new CTextBox(ct_text);
//set text box properties
ct_textbox->setTextBorderWidth(0);
ct_textbox->enableBackgroundPaint(true);
ct_textbox->setBackGroundColor(COL_RED);
ct_textbox->setTextFont(ct_font);
ct_textbox->setTextMode(ct_text_mode);
ct_textbox->movePosition(ct_box->iX, ct_box->iY);
ct_textbox->setTextColor(ct_col_text);
//set text
string new_text = static_cast <string> (ct_text);
ct_text_sended = ct_textbox->setText(&new_text, width);
}
void CComponentsText::paint(bool do_save_bg)
{
initText();
paintInit(do_save_bg);
if (ct_text_sended)
ct_textbox->paint();
ct_text_sended = false;
}
void CComponentsText::hide(bool no_restore)
{
ct_textbox->hide();
hideContainer(no_restore);
}