Colobot
|
Text rendering engine. More...
#include <text.h>
Public Member Functions | |
CText (CEngine *engine) | |
void | SetDevice (CDevice *device) |
Sets the device to be used. | |
std::string | GetError () |
Returns the last encountered error. | |
bool | Create () |
Initializes the font engine; must be called after SetDevice() | |
void | Destroy () |
Frees resources before exit. | |
void | FlushCache () |
Flushes cached textures. | |
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) | |
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) | |
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) | |
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) | |
float | GetAscent (FontType font, float size) |
Returns the ascent font metric. | |
float | GetDescent (FontType font, float size) |
Returns the descent font metric. | |
float | GetHeight (FontType font, float size) |
Returns the height font metric. | |
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) | |
TEST_VIRTUAL float | GetStringWidth (std::string text, FontType font, float size) |
Returns width of string (single font) | |
TEST_VIRTUAL float | GetCharWidth (UTF8Char ch, FontType font, float size, float offset) |
Returns width of single character. | |
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) | |
int | Justify (const std::string &text, FontType font, float size, float width) |
Justifies a line of text (one font) | |
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) | |
int | Detect (const std::string &text, FontType font, float size, float offset) |
Returns the most suitable position to a given offset (one font) | |
UTF8Char | TranslateSpecialChar (int specialChar) |
CharTexture | GetCharTexture (UTF8Char ch, FontType font, float size) |
void | SetTabSize (int tabSize) |
Tab size management. | |
int | GetTabSize () |
Protected Member Functions | |
CachedFont * | GetOrOpenFont (FontType type, float size) |
CharTexture | CreateCharTexture (UTF8Char ch, CachedFont *font) |
void | DrawString (const std::string &text, std::vector< FontMetaChar >::iterator format, std::vector< FontMetaChar >::iterator end, float size, Math::Point pos, float width, int eol, Color color) |
void | DrawString (const std::string &text, FontType font, float size, Math::Point pos, float width, int eol, Color color) |
void | DrawHighlight (FontHighlight hl, Math::Point pos, Math::Point size) |
void | DrawCharAndAdjustPos (UTF8Char ch, FontType font, float size, Math::Point &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 |
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.