#include "text.h" using namespace Graphics; template <> void Text::arrange(TextureFont &font){ // TODO: this is really awful rendering but works a little bit unsigned int filledX = 0; unsigned int row = 0; unsigned int col = 0; for(unsigned int i=0; i < text_.length(); i++){ sf::Glyph glyph = font.getGlyph( text_[i] ); filledX += glyph.advance; if (maxWidth_ != 0 && ( text_[i] == '\n' || filledX > maxWidth_)){ row++; filledX = 0; col = 0; if(text_[i] == '\n') continue; } vertices_[4*i+0].position = sf::Vector2f( col*glyph.advance + glyph.bounds.left, (glyph.bounds.top) + row * glyph.bounds.height ); vertices_[4*i+1].position = sf::Vector2f( col*glyph.advance + glyph.bounds.left+glyph.bounds.width, (glyph.bounds.top) + row * glyph.bounds.height ); 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 ); vertices_[4*i+3].position = sf::Vector2f( col*glyph.advance + glyph.bounds.left, (glyph.bounds.top+glyph.bounds.height) + row * glyph.bounds.height ); col++; vertices_[4*i+0].texCoords = sf::Vector2f( glyph.textureRect.left, glyph.textureRect.top ); vertices_[4*i+1].texCoords = sf::Vector2f( glyph.textureRect.left+glyph.textureRect.width, glyph.textureRect.top ); vertices_[4*i+2].texCoords = sf::Vector2f( glyph.textureRect.left+glyph.textureRect.width, glyph.textureRect.top+glyph.textureRect.height ); vertices_[4*i+3].texCoords = sf::Vector2f( glyph.textureRect.left, glyph.textureRect.top+glyph.textureRect.height ); } } template <> void Text::arrange(sf::Font &font){ // TODO: Implement this function for a generic sf::Font }