summaryrefslogtreecommitdiffstats
path: root/src/graphics/engine/text.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics/engine/text.h')
-rw-r--r--src/graphics/engine/text.h159
1 files changed, 86 insertions, 73 deletions
diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h
index 24251ab..61996b8 100644
--- a/src/graphics/engine/text.h
+++ b/src/graphics/engine/text.h
@@ -17,18 +17,22 @@
/**
* \file graphics/engine/text.h
- * \brief Text rendering - Gfx::CText class
+ * \brief Text rendering - CText class
*/
#pragma once
+
#include "math/point.h"
#include <vector>
#include <map>
+
class CInstanceManager;
+
+// Graphics module namespace
namespace Gfx {
class CEngine;
@@ -40,8 +44,9 @@ const float FONT_SIZE_SMALL = 10.0f;
const float FONT_SIZE_BIG = 15.0f;
/**
- \enum TextAlign
- \brief Type of text alignment */
+ * \enum TextAlign
+ * \brief Type of text alignment
+ */
enum TextAlign
{
TEXT_ALIGN_RIGHT,
@@ -55,10 +60,11 @@ enum TextAlign
typedef short FontMetaChar;
/**
- \enum FontType
- \brief Type of font
-
- Bitmask in lower 4 bits (mask 0x00f) */
+ * \enum FontType
+ * \brief Type of font
+ *
+ * Bitmask in lower 4 bits (mask 0x00f)
+ */
enum FontType
{
//! Flag for bold font subtype
@@ -85,12 +91,13 @@ enum FontType
};
/**
- \enum FontTitle
- \brief Size of font title
-
- Used internally by CEdit
-
- Bitmask in 2 bits left shifted 4 (mask 0x030) */
+ * \enum FontTitle
+ * \brief Size of font title
+ *
+ * Used internally by CEdit
+ *
+ * Bitmask in 2 bits left shifted 4 (mask 0x030)
+ */
enum FontTitle
{
FONT_TITLE_BIG = 0x01 << 4,
@@ -99,10 +106,11 @@ enum FontTitle
};
/**
- \enum FontHighlight
- \brief Type of color highlight for text
-
- Bitmask in 3 bits left shifted 6 (mask 0x1c0) */
+ * \enum FontHighlight
+ * \brief Type of color highlight for text
+ *
+ * Bitmask in 3 bits left shifted 6 (mask 0x1c0)
+ */
enum FontHighlight
{
FONT_HIGHLIGHT_NONE = 0x00 << 6,
@@ -116,8 +124,9 @@ enum FontHighlight
};
/**
- \enum FontMask
- \brief Masks in FontMetaChar for different attributes */
+ * \enum FontMask
+ * \brief Masks in FontMetaChar for different attributes
+ */
enum FontMask
{
//! Mask for FontType
@@ -132,10 +141,11 @@ enum FontMask
/**
- \struct UTF8Char
- \brief UTF-8 character in font cache
-
- Only 3-byte chars are supported */
+ * \struct UTF8Char
+ * \brief UTF-8 character in font cache
+ *
+ * Only 3-byte chars are supported
+ */
struct UTF8Char
{
char c1, c2, c3;
@@ -165,8 +175,9 @@ struct UTF8Char
};
/**
- \struct CharTexture
- \brief Texture of font character */
+ * \struct CharTexture
+ * \brief Texture of font character
+ */
struct CharTexture
{
unsigned int id;
@@ -180,8 +191,9 @@ struct CharTexture
struct CachedFont;
/**
- \struct MultisizeFont
- \brief Font with multiple possible sizes */
+ * \struct MultisizeFont
+ * \brief Font with multiple possible sizes
+ */
struct MultisizeFont
{
std::string fileName;
@@ -192,28 +204,28 @@ 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
+ * \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 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:
- CText(CInstanceManager *iMan, Gfx::CEngine* engine);
+ CText(CInstanceManager *iMan, CEngine* engine);
~CText();
//! Sets the device to be used
- void SetDevice(Gfx::CDevice *device);
+ void SetDevice(CDevice *device);
//! Returns the last encountered error
std::string GetError();
@@ -227,75 +239,76 @@ public:
void FlushCache();
//! Draws text (multi-format)
- void DrawText(const std::string &text, const std::vector<Gfx::FontMetaChar> &format,
- float size, Math::Point pos, float width, Gfx::TextAlign align,
+ void DrawText(const std::string &text, const std::vector<FontMetaChar> &format,
+ float size, Math::Point pos, float width, TextAlign align,
int eol);
//! Draws text (one font)
- void DrawText(const std::string &text, Gfx::FontType font,
- float size, Math::Point pos, float width, Gfx::TextAlign align,
+ void DrawText(const std::string &text, FontType font,
+ float size, Math::Point pos, float width, TextAlign align,
int eol);
//! Calculates dimensions for text (multi-format)
- void SizeText(const std::string &text, const std::vector<Gfx::FontMetaChar> &format,
- float size, Math::Point pos, Gfx::TextAlign align,
+ void SizeText(const std::string &text, const std::vector<FontMetaChar> &format,
+ float size, Math::Point pos, TextAlign align,
Math::Point &start, Math::Point &end);
//! Calculates dimensions for text (one font)
- void SizeText(const std::string &text, Gfx::FontType font,
- float size, Math::Point pos, Gfx::TextAlign align,
+ void SizeText(const std::string &text, FontType font,
+ float size, Math::Point pos, TextAlign align,
Math::Point &start, Math::Point &end);
//! Returns the ascent font metric
- float GetAscent(Gfx::FontType font, float size);
+ float GetAscent(FontType font, float size);
//! Returns the descent font metric
- float GetDescent(Gfx::FontType font, float size);
+ float GetDescent(FontType font, float size);
//! Returns the height font metric
- float GetHeight(Gfx::FontType font, float size);
+ float GetHeight(FontType font, float size);
//! Returns width of string (multi-format)
float GetStringWidth(const std::string &text,
- const std::vector<Gfx::FontMetaChar> &format, float size);
+ const std::vector<FontMetaChar> &format, float size);
//! Returns width of string (single font)
- float GetStringWidth(const std::string &text, Gfx::FontType font, float size);
+ float GetStringWidth(const std::string &text, FontType font, float size);
//! Returns width of single character
- float GetCharWidth(Gfx::UTF8Char ch, Gfx::FontType font, float size, float offset);
+ float GetCharWidth(UTF8Char ch, 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,
+ int Justify(const std::string &text, const std::vector<FontMetaChar> &format,
float size, float width);
//! Justifies a line of text (one font)
- int Justify(const std::string &text, Gfx::FontType font, float size, float width);
+ int Justify(const std::string &text, FontType font, float size, float width);
//! Returns the most suitable position to a given offset (multi-format)
- int Detect(const std::string &text, const std::vector<Gfx::FontMetaChar> &format,
+ int Detect(const std::string &text, const std::vector<FontMetaChar> &format,
float size, float offset);
//! Returns the most suitable position to a given offset (one font)
- int Detect(const std::string &text, Gfx::FontType font, float size, float offset);
+ int Detect(const std::string &text, FontType font, float size, float offset);
protected:
- Gfx::CachedFont* GetOrOpenFont(Gfx::FontType type, float size);
- Gfx::CharTexture CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont* font);
+ CachedFont* GetOrOpenFont(FontType type, float size);
+ CharTexture CreateCharTexture(UTF8Char ch, CachedFont* font);
- void DrawString(const std::string &text, const std::vector<Gfx::FontMetaChar> &format,
+ void DrawString(const std::string &text, const std::vector<FontMetaChar> &format,
float size, Math::Point pos, float width, int eol);
- void DrawString(const std::string &text, Gfx::FontType font,
+ void DrawString(const std::string &text, FontType font,
float size, Math::Point pos, float width, int eol);
- void DrawHighlight(Gfx::FontHighlight hl, Math::Point pos, Math::Point size);
- void DrawChar(Gfx::UTF8Char ch, Gfx::FontType font, float size, Math::Point &pos);
+ void DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size);
+ void DrawChar(UTF8Char ch, FontType font, float size, Math::Point &pos);
protected:
CInstanceManager* m_iMan;
- Gfx::CEngine* m_engine;
- Gfx::CDevice* m_device;
+ CEngine* m_engine;
+ CDevice* m_device;
std::string m_error;
float m_defaultSize;
std::string m_fontPath;
- std::map<Gfx::FontType, Gfx::MultisizeFont*> m_fonts;
+ std::map<FontType, MultisizeFont*> m_fonts;
- Gfx::FontType m_lastFontType;
+ FontType m_lastFontType;
int m_lastFontSize;
- Gfx::CachedFont* m_lastCachedFont;
+ CachedFont* m_lastCachedFont;
};
-}; // namespace Gfx
+
+} // namespace Gfx