1
0
Fork 0

Font: moving text size from font to Text object.

This commit is contained in:
Henrik Hautakoski 2016-05-05 11:04:54 +02:00
parent c74dda1200
commit b2dbee33fb
5 changed files with 31 additions and 16 deletions

View file

@ -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);

View file

@ -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<unsigned char, Glyph> m_charset;
unsigned int m_size; // font size, in pixels. not points.
// Alpha Cache texture.
mutable CacheTexture m_cacheTextureA;

View file

@ -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;

View file

@ -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;
}

View file

@ -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;