diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2022-12-14 15:57:48 +0100 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2022-12-14 15:57:48 +0100 |
commit | df44f9344616e9d6e7009fcfedb6620087c1ff22 (patch) | |
tree | bf02c2a76b49dba9562f033137888d206f2be5e0 /src/graphics | |
parent | 02fe1199884d1056a3282268a8c75b3f086bfc9d (diff) |
Diffstat (limited to 'src/graphics')
-rw-r--r-- | src/graphics/text.cpp | 10 | ||||
-rw-r--r-- | src/graphics/text.h | 8 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/graphics/text.cpp b/src/graphics/text.cpp index 7b135d6..51b71ae 100644 --- a/src/graphics/text.cpp +++ b/src/graphics/text.cpp @@ -20,24 +20,26 @@ void Text<TextureFont>::arrange(TextureFont &font){ if(text_[i] == '\n') continue; } + // Position the character in the text vertices_[4*i+0].position = sf::Vector2f( col*glyph.advance + glyph.bounds.left, - (glyph.bounds.top) + row * glyph.bounds.height + (glyph.bounds.top) + row * font.getLineSpacing() * lineHeightRatio_ ); vertices_[4*i+1].position = sf::Vector2f( col*glyph.advance + glyph.bounds.left+glyph.bounds.width, - (glyph.bounds.top) + row * glyph.bounds.height + (glyph.bounds.top) + row * font.getLineSpacing() * lineHeightRatio_ ); vertices_[4*i+2].position = sf::Vector2f( col*glyph.advance + glyph.bounds.left+glyph.bounds.width, - (glyph.bounds.top+glyph.bounds.height) + row * glyph.bounds.height + (glyph.bounds.top+glyph.bounds.height) + row * font.getLineSpacing() * lineHeightRatio_ ); vertices_[4*i+3].position = sf::Vector2f( col*glyph.advance + glyph.bounds.left, - (glyph.bounds.top+glyph.bounds.height) + row * glyph.bounds.height + (glyph.bounds.top+glyph.bounds.height) + row * font.getLineSpacing() * lineHeightRatio_ ); col++; + // Choose the texture rectangle for this character vertices_[4*i+0].texCoords = sf::Vector2f( glyph.textureRect.left, glyph.textureRect.top diff --git a/src/graphics/text.h b/src/graphics/text.h index f60980c..a390e8a 100644 --- a/src/graphics/text.h +++ b/src/graphics/text.h @@ -10,13 +10,14 @@ namespace Graphics { Font &font_; const std::string text_; sf::VertexArray vertices_; + float lineHeightRatio_; unsigned int size_, maxWidth_, maxHeight_; void arrange(Font &font); // Specialize for sf::Font and TextureFont public: - Text(Font &font, const std::string &text, unsigned int maxWidth=0, - unsigned int maxHeight=0); + Text(Font &font, const std::string &text, float lineHeightRatio=1., + unsigned int maxWidth=0, unsigned int maxHeight=0); void setFont(Font &font); void setText(const std::string &text); @@ -26,11 +27,12 @@ namespace Graphics { }; template <typename Font> - Text<Font>::Text(Font &font, const std::string &text, + Text<Font>::Text(Font &font, const std::string &text, float lineHeightRatio, unsigned int maxWidth, unsigned int maxHeight) : font_(font) , text_(text) , vertices_(sf::Quads, text.size()*4) + , lineHeightRatio_(lineHeightRatio) , size_(0) , maxWidth_(maxWidth) , maxHeight_(maxHeight) |