|
Colobot
|
Text rendering engine. More...
#include <src/graphics/engine/text.h>
Classes | |
| class | CQuadBatch |
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. | |
| bool | ReloadFonts () |
| Try to load new font files. | |
| void | SetTabSize (int tabSize) |
| Tab size management. | |
| int | GetTabSize () |
| 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. | |
| 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). | |
| 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 | 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). | |
| 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) |
| Math::IntPoint | GetFontTextureSize () |
Protected Member Functions | |
| int | GetFontPointSize (float size) const |
| CachedFont * | GetOrOpenFont (FontType type, 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) |
| int | GetCharSizeAt (Gfx::FontType font, const std::string &text, unsigned int index) const |
Protected Attributes | |
| CEngine * | m_engine |
| CDevice * | m_device |
| std::string | m_error |
| float | m_defaultSize |
| int | m_tabSize |
| std::unique_ptr< FontsCache > | m_fontsCache |
| std::vector< FontTexture > | m_fontTextures |
| std::unique_ptr< CQuadBatch > | m_quadBatch |
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.
| bool Gfx::CText::ReloadFonts | ( | ) |
Try to load new font files.
| 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).