diff --git a/examples/text/Game.cpp b/examples/text/Game.cpp index 99d34b4..5a65a4b 100644 --- a/examples/text/Game.cpp +++ b/examples/text/Game.cpp @@ -25,9 +25,9 @@ void TextExample::init() g->setClearColor(52.0f / 255.0f, 58.0f / 255.0f, 80.0f / 255.0f); - smallFont.loadFromFile("assets/fonts/RobotoCondensed-Regular.ttf", 14); - myFont.loadFromFile("assets/fonts/RobotoCondensed-Regular.ttf", 20); - fntLarge.loadFromFile("assets/fonts/OPTIBelwe-Medium.otf", 48); + smallFont.loadFromFile("assets/fonts/RobotoCondensed-Regular.ttf"); + myFont.loadFromFile("assets/fonts/RobotoCondensed-Regular.ttf"); + fntLarge.loadFromFile("assets/fonts/OPTIBelwe-Medium.otf"); myText.setFont(myFont); myText.setColor(Color::Green); diff --git a/include/Spectre/Graphics/Font.h b/include/Spectre/Graphics/Font.h index aa03649..eda5026 100644 --- a/include/Spectre/Graphics/Font.h +++ b/include/Spectre/Graphics/Font.h @@ -35,9 +35,9 @@ public : Font(); ~Font(); - bool loadFromFile(const std::string& filename, unsigned int size = 22); + bool loadFromFile(const std::string& filename); - bool loadFromMemory(const void *data, unsigned int size); + bool loadFromMemory(const void *data); Glyph getGlyph(unsigned int code) const; @@ -67,8 +67,6 @@ protected : mutable std::map m_charset; - unsigned int m_size; // font size, in pixels. not points. - // Alpha Cache texture. mutable CacheTexture m_cacheTextureA; diff --git a/include/Spectre/Graphics/Text.h b/include/Spectre/Graphics/Text.h index 19dfffa..b02202f 100644 --- a/include/Spectre/Graphics/Text.h +++ b/include/Spectre/Graphics/Text.h @@ -30,11 +30,14 @@ public : Text(); - Text(const std::string text, const Font& font); + Text(const std::string text, unsigned int size, const Font& font); void setString(const std::string& string); const std::string& getString() const; + void setCharacterSize(unsigned int size); + unsigned int getCharacteSize() const; + void setFont(const Font& font); const Font* getFont() const; @@ -66,6 +69,9 @@ private : // String containing the text. std::string m_string; + // Character size (in pixels, not points). + unsigned int m_size; + const Font* m_font; Color m_color; diff --git a/source/Graphics/Font.cpp b/source/Graphics/Font.cpp index 71ffe64..1aa5019 100644 --- a/source/Graphics/Font.cpp +++ b/source/Graphics/Font.cpp @@ -8,7 +8,6 @@ #include "Font/FreeTypeDriver.h" Font::Font() : -m_size (22), m_driver (new FreeTypeDriver()) { } @@ -18,17 +17,16 @@ Font::~Font() delete m_driver; } -bool Font::loadFromFile(const std::string& filename, unsigned int size) +bool Font::loadFromFile(const std::string& filename) { if (!m_driver->loadFromFile(filename)) { return false; } - if (!m_driver->setCharacterSize(size)) { + if (!m_driver->setCharacterSize(22)) { return false; } - m_size = size; m_cacheTextureA.shelf = 0; m_cacheTextureA.texpos = vec2u(0, 0); @@ -37,7 +35,7 @@ bool Font::loadFromFile(const std::string& filename, unsigned int size) return true; } -bool Font::loadFromMemory(const void *data, unsigned int size) +bool Font::loadFromMemory(const void *data) { return false; } diff --git a/source/Graphics/Text.cpp b/source/Graphics/Text.cpp index e277d68..e1ab6cd 100644 --- a/source/Graphics/Text.cpp +++ b/source/Graphics/Text.cpp @@ -4,16 +4,18 @@ Text::Text() : m_font (NULL), +m_size (22), m_color (255, 255, 255, 255), m_outlineColor (0, 0, 0, 255), m_outlineWidth (0) { } -Text::Text(const std::string text, const Font& font) : -m_font (&font), +Text::Text(const std::string text, unsigned int size, const Font& font) : +m_font (&font), +m_size (size), m_string (text), -m_color (255, 255, 255, 255), +m_color (255, 255, 255, 255), m_outlineColor (0, 0, 0, 255), m_outlineWidth (0), m_geometryNeedsUpdate (true) @@ -31,6 +33,17 @@ const std::string& Text::getString() const return m_string; } +void Text::setCharacterSize(unsigned int size) +{ + m_size = size; + m_geometryNeedsUpdate = true; +} + +unsigned int Text::getCharacteSize() const +{ + return m_size; +} + void Text::setFont(const Font& font) { m_font = &font;