CComponentsText: add possibilty to set font style

Usable with methode setText() and parameter 'style'

provided enums are:
	FONT_STYLE_REGULAR
	FONT_STYLE_BOLD
	FONT_STYLE_ITALIC
This commit is contained in:
2015-02-22 14:47:43 +01:00
parent d2ae57e5b6
commit 341b142aa0
2 changed files with 26 additions and 15 deletions

View File

@@ -81,6 +81,7 @@ void CComponentsText::initVarText( const int x_pos, const int y_pos, const int w
ct_text = text; ct_text = text;
ct_old_text = ct_text; ct_old_text = ct_text;
ct_text_mode = mode; ct_text_mode = mode;
ct_text_style = FONT_STYLE_REGULAR;
iX = x = x_pos; iX = x = x_pos;
iY = y = y_pos; iY = y = y_pos;
@@ -113,7 +114,7 @@ void CComponentsText::initCCText()
{ {
//set default font, if is no font definied //set default font, if is no font definied
if (ct_font == NULL) if (ct_font == NULL)
ct_font = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]; ct_font = *CNeutrinoFonts::getInstance()->getDynFont(width, height, ct_text, ct_text_style)/*g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]*/;
//define height from font size //define height from font size
height = max(height, ct_font->getHeight()); height = max(height, ct_font->getHeight());
@@ -180,7 +181,7 @@ void CComponentsText::clearCCText()
ct_textbox = NULL; ct_textbox = NULL;
} }
void CComponentsText::setText(const std::string& stext, const int mode, Font* font_text, const fb_pixel_t& color_text) void CComponentsText::setText(const std::string& stext, const int mode, Font* font_text, const fb_pixel_t& color_text, const int& style)
{ {
ct_old_text = ct_text; ct_old_text = ct_text;
ct_text = stext; ct_text = stext;
@@ -190,25 +191,27 @@ void CComponentsText::setText(const std::string& stext, const int mode, Font* fo
ct_font = font_text; ct_font = font_text;
if (color_text != 0) if (color_text != 0)
setTextColor(color_text); setTextColor(color_text);
if (style != FONT_STYLE_REGULAR)
ct_text_style = style;
dprintf(DEBUG_DEBUG, "[CComponentsText] [%s - %d] ct_text: %s \n", __func__, __LINE__, ct_text.c_str()); dprintf(DEBUG_DEBUG, "[CComponentsText] [%s - %d] ct_text: %s \n", __func__, __LINE__, ct_text.c_str());
} }
void CComponentsText::setText(neutrino_locale_t locale_text, int mode, Font* font_text, const fb_pixel_t& color_text) void CComponentsText::setText(neutrino_locale_t locale_text, int mode, Font* font_text, const fb_pixel_t& color_text, const int& style)
{ {
string stext = g_Locale->getText(locale_text); string stext = g_Locale->getText(locale_text);
setText(stext, mode, font_text, color_text); setText(stext, mode, font_text, color_text, style);
} }
void CComponentsText::setText(const char* ctext, const int mode, Font* font_text, const fb_pixel_t& color_text) void CComponentsText::setText(const char* ctext, const int mode, Font* font_text, const fb_pixel_t& color_text, const int& style)
{ {
setText((string)ctext, mode, font_text, color_text); setText((string)ctext, mode, font_text, color_text, style);
} }
void CComponentsText::setText(const int digit, const int mode, Font* font_text, const fb_pixel_t& color_text) void CComponentsText::setText(const int digit, const int mode, Font* font_text, const fb_pixel_t& color_text, const int& style)
{ {
string s_digit = iToString(digit); string s_digit = iToString(digit);
setText(s_digit, mode, font_text, color_text); setText(s_digit, mode, font_text, color_text, style);
} }
string CComponentsText::getTextFromFile(const string& path_to_textfile) string CComponentsText::getTextFromFile(const string& path_to_textfile)
@@ -232,14 +235,14 @@ string CComponentsText::getTextFromFile(const string& path_to_textfile)
} }
//set text lines directly from a file, returns true on succsess //set text lines directly from a file, returns true on succsess
bool CComponentsText::setTextFromFile(const string& path_to_textfile, const int mode, Font* font_text, const fb_pixel_t& color_text) bool CComponentsText::setTextFromFile(const string& path_to_textfile, const int mode, Font* font_text, const fb_pixel_t& color_text, const int& style)
{ {
string txt = getTextFromFile(path_to_textfile); string txt = getTextFromFile(path_to_textfile);
if (txt.empty()) if (txt.empty())
return false; return false;
setText(txt, mode, font_text, color_text); setText(txt, mode, font_text, color_text, style);
return true; return true;
} }

View File

@@ -45,6 +45,8 @@ class CComponentsText : public CComponentsItem, public CBox
CTextBox * ct_textbox; CTextBox * ct_textbox;
///object: Fontrenderer object ///object: Fontrenderer object
Font * ct_font; Font * ct_font;
///property: font style
int ct_text_style;
///property: text color ///property: text color
fb_pixel_t ct_col_text; fb_pixel_t ct_col_text;
@@ -89,6 +91,12 @@ class CComponentsText : public CComponentsItem, public CBox
///paint CCItem backckrond (if paint_bg=true), apply initCCText() and send paint() to the CTextBox object ///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); void paintText(bool do_save_bg = CC_SAVE_SCREEN_YES);
public: public:
enum {
FONT_STYLE_REGULAR = 0,
FONT_STYLE_BOLD = 1,
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 = 150, const int h = 50,
std::string text = "", std::string text = "",
const int mode = CTextBox::AUTO_WIDTH, const int mode = CTextBox::AUTO_WIDTH,
@@ -128,15 +136,15 @@ class CComponentsText : public CComponentsItem, public CBox
virtual inline void doPaintTextBoxBg(bool do_paintbox_bg){ ct_paint_textbg = do_paintbox_bg;}; virtual inline void doPaintTextBoxBg(bool do_paintbox_bg){ ct_paint_textbg = do_paintbox_bg;};
///set text as string also possible with overloades members for loacales, const char and text file ///set text as string also possible with overloades members for loacales, const char and text file
virtual void setText(const std::string& stext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL, const fb_pixel_t& color_text = 0); virtual void setText(const std::string& stext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL, const fb_pixel_t& color_text = 0, const int& style = FONT_STYLE_REGULAR);
///set text with const char* ///set text with const char*
virtual void setText(const char* ctext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL, const fb_pixel_t& color_text = 0); virtual void setText(const char* ctext, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL, const fb_pixel_t& color_text = 0, const int& style = FONT_STYLE_REGULAR);
///set text from locale ///set text from locale
virtual void setText(neutrino_locale_t locale_text, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL, const fb_pixel_t& color_text = 0); virtual void setText(neutrino_locale_t locale_text, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL, const fb_pixel_t& color_text = 0, const int& style = FONT_STYLE_REGULAR);
///set text from digit, digit is integer ///set text from digit, digit is integer
virtual void setText(const int digit, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL, const fb_pixel_t& color_text = 0); virtual void setText(const int digit, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL, const fb_pixel_t& color_text = 0, const int& style = FONT_STYLE_REGULAR);
///set text directly from a textfile, path as string is required ///set text directly from a textfile, path as string is required
virtual bool setTextFromFile(const std::string& path_to_textfile, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL, const fb_pixel_t& color_text = 0); virtual bool setTextFromFile(const std::string& path_to_textfile, const int mode = ~CTextBox::AUTO_WIDTH, Font* font_text = NULL, const fb_pixel_t& color_text = 0, const int& style = FONT_STYLE_REGULAR);
///get text directly from a textfile, path as string is required ///get text directly from a textfile, path as string is required
virtual std::string getTextFromFile(const std::string& path_to_textfile); virtual std::string getTextFromFile(const std::string& path_to_textfile);
///returns current text content of text/label object as std::string ///returns current text content of text/label object as std::string