Colobot
|
Text rendering engine. More...
#include <text.h>
Public Member Functions | |
CText (CEngine *engine) | |
void | SetDevice (CDevice *device) |
Sets the device to be used. More... | |
std::string | GetError () |
Returns the last encountered error. More... | |
bool | Create () |
Initializes the font engine; must be called after SetDevice() More... | |
void | Destroy () |
Frees resources before exit. More... | |
void | FlushCache () |
Flushes cached textures. More... | |
void | DrawText (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size, Math::Point pos, float width, TextAlign align, int eol, Color color=Color(0.0f, 0.0f, 0.0f, 1.0f)) |
Draws text (multi-format) More... | |
void | DrawText (const std::string &text, FontType font, float size, Math::Point pos, float width, TextAlign align, int eol, Color color=Color(0.0f, 0.0f, 0.0f, 1.0f)) |
Draws text (one font) More... | |
void | SizeText (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator endFormat, float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end) |
Calculates dimensions for text (multi-format) More... | |
void | SizeText (const std::string &text, FontType font, float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end) |
Calculates dimensions for text (one font) More... | |
float | GetAscent (FontType font, float size) |
Returns the ascent font metric. More... | |
float | GetDescent (FontType font, float size) |
Returns the descent font metric. More... | |
float | GetHeight (FontType font, float size) |
Returns the height font metric. More... | |
int | GetHeightInt (FontType font, float size) |
TEST_VIRTUAL float | GetStringWidth (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size) |
Returns width of string (multi-format) More... | |
TEST_VIRTUAL float | GetStringWidth (std::string text, FontType font, float size) |
Returns width of string (single font) More... | |
TEST_VIRTUAL float | GetCharWidth (UTF8Char ch, FontType font, float size, float offset) |
Returns width of single character. More... | |
int | GetCharWidthInt (UTF8Char ch, FontType font, float size, float offset) |
int | Justify (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size, float width) |
Justifies a line of text (multi-format) More... | |
int | Justify (const std::string &text, FontType font, float size, float width) |
Justifies a line of text (one font) More... | |
int | Detect (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size, float offset) |
Returns the most suitable position to a given offset (multi-format) More... | |
int | Detect (const std::string &text, FontType font, float size, float offset) |
Returns the most suitable position to a given offset (one font) More... | |
UTF8Char | TranslateSpecialChar (int specialChar) |
CharTexture | GetCharTexture (UTF8Char ch, FontType font, float size) |
Math::IntPoint | GetFontTextureSize () |
void | SetTabSize (int tabSize) |
Tab size management. More... | |
int | GetTabSize () |
Protected Member Functions | |
CachedFont * | GetOrOpenFont (FontType font, float size) |
CharTexture | CreateCharTexture (UTF8Char ch, CachedFont *font) |
FontTexture * | GetOrCreateFontTexture (Math::IntPoint tileSize) |
FontTexture | CreateFontTexture (Math::IntPoint tileSize) |
Math::IntPoint | GetNextTilePos (const FontTexture &fontTexture) |
void | DrawString (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size, Math::IntPoint pos, int width, int eol, Color color) |
void | DrawString (const std::string &text, FontType font, float size, Math::IntPoint pos, int width, int eol, Color color) |
void | DrawHighlight (FontMetaChar hl, Math::IntPoint pos, Math::IntPoint size) |
void | DrawCharAndAdjustPos (UTF8Char ch, FontType font, float size, Math::IntPoint &pos, Color color) |
void | StringToUTFCharList (const std::string &text, std::vector< UTF8Char > &chars) |
void | StringToUTFCharList (const std::string &text, std::vector< UTF8Char > &chars, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end) |
Protected Attributes | |
CEngine * | m_engine |
CDevice * | m_device |
std::string | m_error |
float | m_defaultSize |
int | m_tabSize |
std::map< FontType, std::unique_ptr< MultisizeFont > > | m_fonts |
std::vector< FontTexture > | m_fontTextures |
FontType | m_lastFontType |
int | m_lastFontSize |
CachedFont * | m_lastCachedFont |
Text rendering engine.
CText is responsible for drawing text in 2D interface. Font rendering is done using textures generated by SDL_ttf from TTF font files.
All functions rendering text are divided into two types:
All font rendering is done in UTF-8.
void Gfx::CText::SetDevice | ( | CDevice * | device | ) |
Sets the device to be used.
std::string Gfx::CText::GetError | ( | ) |
Returns the last encountered error.
bool Gfx::CText::Create | ( | ) |
Initializes the font engine; must be called after SetDevice()
void Gfx::CText::Destroy | ( | ) |
Frees resources before exit.
void Gfx::CText::FlushCache | ( | ) |
Flushes cached textures.
void Gfx::CText::SetTabSize | ( | int | tabSize | ) |
Tab size management.
void Gfx::CText::DrawText | ( | const std::string & | text, |
std::vector< FontMetaChar >::iterator | format, | ||
std::vector< FontMetaChar >::iterator | end, | ||
float | size, | ||
Math::Point | pos, | ||
float | width, | ||
TextAlign | align, | ||
int | eol, | ||
Color | color = Color(0.0f, 0.0f, 0.0f, 1.0f) |
||
) |
Draws text (multi-format)
void Gfx::CText::DrawText | ( | const std::string & | text, |
FontType | font, | ||
float | size, | ||
Math::Point | pos, | ||
float | width, | ||
TextAlign | align, | ||
int | eol, | ||
Color | color = Color(0.0f, 0.0f, 0.0f, 1.0f) |
||
) |
Draws text (one font)
void Gfx::CText::SizeText | ( | const std::string & | text, |
std::vector< FontMetaChar >::iterator | format, | ||
std::vector< FontMetaChar >::iterator | endFormat, | ||
float | size, | ||
Math::Point | pos, | ||
TextAlign | align, | ||
Math::Point & | start, | ||
Math::Point & | end | ||
) |
Calculates dimensions for text (multi-format)
void Gfx::CText::SizeText | ( | const std::string & | text, |
FontType | font, | ||
float | size, | ||
Math::Point | pos, | ||
TextAlign | align, | ||
Math::Point & | start, | ||
Math::Point & | end | ||
) |
Calculates dimensions for text (one font)
float Gfx::CText::GetAscent | ( | FontType | font, |
float | size | ||
) |
Returns the ascent font metric.
float Gfx::CText::GetDescent | ( | FontType | font, |
float | size | ||
) |
Returns the descent font metric.
float Gfx::CText::GetHeight | ( | FontType | font, |
float | size | ||
) |
Returns the height font metric.
float Gfx::CText::GetStringWidth | ( | const std::string & | text, |
std::vector< FontMetaChar >::iterator | format, | ||
std::vector< FontMetaChar >::iterator | end, | ||
float | size | ||
) |
Returns width of string (multi-format)
float Gfx::CText::GetStringWidth | ( | std::string | text, |
FontType | font, | ||
float | size | ||
) |
Returns width of string (single font)
Returns width of single character.
int Gfx::CText::Justify | ( | const std::string & | text, |
std::vector< FontMetaChar >::iterator | format, | ||
std::vector< FontMetaChar >::iterator | end, | ||
float | size, | ||
float | width | ||
) |
Justifies a line of text (multi-format)
int Gfx::CText::Justify | ( | const std::string & | text, |
FontType | font, | ||
float | size, | ||
float | width | ||
) |
Justifies a line of text (one font)
int Gfx::CText::Detect | ( | const std::string & | text, |
std::vector< FontMetaChar >::iterator | format, | ||
std::vector< FontMetaChar >::iterator | end, | ||
float | size, | ||
float | offset | ||
) |
Returns the most suitable position to a given offset (multi-format)
int Gfx::CText::Detect | ( | const std::string & | text, |
FontType | font, | ||
float | size, | ||
float | offset | ||
) |
Returns the most suitable position to a given offset (one font)