From e45e92e0ff294e6a1899b01b8cfdd8ab25d8dcdc Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Tue, 13 Dec 2022 19:35:48 +0100 Subject: Make a better text rendering system and a simple example in titlestate --- src/graphics/textureFont.cpp | 48 +++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'src/graphics/textureFont.cpp') diff --git a/src/graphics/textureFont.cpp b/src/graphics/textureFont.cpp index 29f9c71..3be2444 100644 --- a/src/graphics/textureFont.cpp +++ b/src/graphics/textureFont.cpp @@ -8,37 +8,35 @@ TextureFont::TextureFont(const sf::Texture &texture, , description_(description) { sf::Vector2u totalSize = tex_.getSize(); - sf::Vector2f totalSize_f (totalSize.x, totalSize.y); - glyphSize_ = sf::Vector2f( totalSize.x / description_.numcols, + glyphSize_ = sf::Vector2i( totalSize.x / description_.numcols, totalSize.y / description_.numrows ); -} -std::array TextureFont::getGlyphMapping(const char ch){ - unsigned int pos = static_cast( description_.mapping.find_first_of(ch)); - if (pos == std::string::npos){ - // TODO: Error handling! - pos = 0; + for(unsigned int i=0; i { - basePos, - basePos + sf::Vector2f( glyphSize_.x, 0 ), - basePos + glyphSize_, - basePos + sf::Vector2f( 0, glyphSize_.y ), - }; } -sf::Vector2f TextureFont::getGlyphSize(){ - return glyphSize_; +const sf::Glyph & TextureFont::getGlyph(char ch) const{ + auto pair = glyphTable_.find(ch); + return pair->second; } -const sf::Texture * TextureFont::getTexture(){ +const sf::Texture * TextureFont::getTexture(unsigned int _){ return &tex_; } -- cgit v1.2.3