#ifndef GRAPHICS_TEXT_H #define GRAPHICS_TEXT_H #include"textureFont.h" namespace Graphics { template class Text : public sf::Drawable, public sf::Transformable { private: Font &font_; const std::string text_; sf::VertexArray vertices_; 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); void setFont(Font &font); void setText(const std::string &text); virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override; }; template Text::Text(Font &font, const std::string &text, unsigned int maxWidth, unsigned int maxHeight) : font_(font) , text_(text) , vertices_(sf::Quads, text.size()*4) , size_(0) , maxWidth_(maxWidth) , maxHeight_(maxHeight) { arrange(font); } template void Text::draw(sf::RenderTarget& target, sf::RenderStates states) const { // TODO: only repaint if needed: when repainting is needed // vertices_.clear() and fun states.transform *= getTransform(); states.texture = font_.getTexture(size_); // you may also override states.shader or states.blendMode if you want target.draw(vertices_, states); } template void Text::setFont(Font &font){ font_ = font; arrange(font); } } #endif // GRAPHICS_TEXT_H