diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2012-08-06 20:20:50 +0200 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2012-08-06 20:20:50 +0200 |
commit | f7e78b21e9655604ba6fba1d068a9bf7f00b85a5 (patch) | |
tree | 51c54103d52ea420ea21608cdc9f9163959eb7bd /src/graphics/engine/text.h | |
parent | 61bfb22f27f5216f989c023a5e39fad7e356d2d6 (diff) | |
download | colobot-f7e78b21e9655604ba6fba1d068a9bf7f00b85a5.tar.gz colobot-f7e78b21e9655604ba6fba1d068a9bf7f00b85a5.tar.bz2 colobot-f7e78b21e9655604ba6fba1d068a9bf7f00b85a5.zip |
Font rendering
- implemented rest of CText interface excluding some minor features
Diffstat (limited to 'src/graphics/engine/text.h')
-rw-r--r-- | src/graphics/engine/text.h | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 19d9882..6209c39 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -38,9 +38,9 @@ const float FONT_SIZE_SMALL = 10.0f; const float FONT_SIZE_BIG = 15.0f; /** - \enum TextAlignType + \enum TextAlign \brief Type of text alignment */ -enum JustifyType +enum TextAlign { TEXT_ALIGN_RIGHT, TEXT_ALIGN_LEFT, @@ -86,6 +86,8 @@ enum FontType \enum FontTitle \brief Size of font title + Used internally by CEdit + Bitmask in 2 bits left shifted 4 (mask 0x030) */ enum FontTitle { @@ -95,19 +97,20 @@ enum FontTitle }; /** - \enum FontColor - \brief Font color type (?) + \enum FontHighlight + \brief Type of color highlight for text Bitmask in 3 bits left shifted 6 (mask 0x1c0) */ -enum FontColor +enum FontHighlight { - FONT_COLOR_LINK = 0x01 << 6, - FONT_COLOR_TOKEN = 0x02 << 6, - FONT_COLOR_TYPE = 0x03 << 6, - FONT_COLOR_CONST = 0x04 << 6, - FONT_COLOR_REM = 0x05 << 6, - FONT_COLOR_KEY = 0x06 << 6, - FONT_COLOR_TABLE = 0x07 << 6, + FONT_HIGHLIGHT_NONE = 0x00 << 6, + FONT_HIGHLIGHT_LINK = 0x01 << 6, + FONT_HIGHLIGHT_TOKEN = 0x02 << 6, + FONT_HIGHLIGHT_TYPE = 0x03 << 6, + FONT_HIGHLIGHT_CONST = 0x04 << 6, + FONT_HIGHLIGHT_REM = 0x05 << 6, + FONT_HIGHLIGHT_KEY = 0x06 << 6, + FONT_HIGHLIGHT_TABLE = 0x07 << 6, }; /** @@ -119,9 +122,9 @@ enum FontMask FONT_MASK_FONT = 0x00f, //! Mask for FontTitle FONT_MASK_TITLE = 0x030, - //! Mask for FontColor - FONT_MASK_COLOR = 0x1c0, - //! Mask for image bit + //! Mask for FontHighlight + FONT_MASK_HIGHLIGHT = 0x1c0, + //! Mask for image bit (TODO: not used?) FONT_MASK_IMAGE = 0x200 }; @@ -190,7 +193,17 @@ struct MultisizeFont \class CText \brief 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: + - single font - function takes a single Gfx::FontType argument that (along with size) + determines the font to be used for all characters, + - multi-font - function takes the text as one argument and a std::vector of FontMetaChar + with per-character formatting information (font, highlights and some other info used by CEdit) + + All font rendering is done in UTF-8. +*/ class CText { public: @@ -213,20 +226,20 @@ public: //! Draws text (multi-format) void DrawText(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, - Math::Point pos, float width, Gfx::JustifyType justify, float size, - float stretch, int eol); + float size, Math::Point pos, float width, Gfx::TextAlign align, + int eol); //! Draws text (one font) void DrawText(const std::string &text, Gfx::FontType font, - Math::Point pos, float width, Gfx::JustifyType justify, float size, - float stretch, int eol); + float size, Math::Point pos, float width, Gfx::TextAlign align, + int eol); //! Calculates dimensions for text (multi-format) void SizeText(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, - Math::Point pos, Gfx::JustifyType justify, float size, + float size, Math::Point pos, Gfx::TextAlign align, Math::Point &start, Math::Point &end); //! Calculates dimensions for text (one font) void SizeText(const std::string &text, Gfx::FontType font, - Math::Point pos, Gfx::JustifyType justify, float size, + float size, Math::Point pos, Gfx::TextAlign align, Math::Point &start, Math::Point &end); //! Returns the ascent font metric @@ -242,7 +255,7 @@ public: //! Returns width of string (single font) float GetStringWidth(const std::string &text, Gfx::FontType font, float size); //! Returns width of single character - float GetCharWidth(int character, Gfx::FontType font, float size, float offset); + float GetCharWidth(Gfx::UTF8Char ch, Gfx::FontType font, float size, float offset); //! Justifies a line of text (multi-format) int Justify(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, @@ -256,16 +269,16 @@ public: //! Returns the most suitable position to a given offset (one font) int Detect(const std::string &text, Gfx::FontType font, float size, float offset); -public: // for testing! +protected: Gfx::CachedFont* GetOrOpenFont(Gfx::FontType type, float size); - Gfx::CharTexture CreateCharTexture(const char* utf8Char, Gfx::CachedFont* font); + Gfx::CharTexture CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont* font); void DrawString(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, float size, Math::Point pos, float width, int eol); void DrawString(const std::string &text, Gfx::FontType font, float size, Math::Point pos, float width, int eol); - void DrawColor(int color, float size, Math::Point pos, float width); - void DrawChar(UTF8Char character, Gfx::FontType font, float size, Math::Point &pos); + void DrawHighlight(Gfx::FontHighlight hl, Math::Point pos, Math::Size size); + void DrawChar(Gfx::UTF8Char ch, Gfx::FontType font, float size, Math::Point &pos); protected: CInstanceManager* m_iMan; |