From 2b6cd04c1fcf9807b6da9aa03e9920c28780db2c Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Fri, 9 Dec 2022 19:43:16 +0100 Subject: Add basic bitmap font/text support --- src/graphics/font.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/graphics/font.h (limited to 'src/graphics/font.h') diff --git a/src/graphics/font.h b/src/graphics/font.h new file mode 100644 index 0000000..9a8e919 --- /dev/null +++ b/src/graphics/font.h @@ -0,0 +1,35 @@ +#ifndef GRAPHICS_FONT_H +#define GRAPHICS_FONT_H + +#include +#include +#include"SFML/Graphics.hpp" + +namespace Graphics { + class Font { + private: + const sf::Texture &tex_; + const std::string mapping_; + const unsigned int numrows_, numcols_; + sf::Vector2f glyphSize_; + public: + Font(const sf::Texture &texture, const std::string &mapping, + unsigned int numrows, unsigned int numcols); + std::array getGlyphMapping(const char ch); + sf::Vector2f getGlyphSize(); + const sf::Texture *getTexture(); + }; + + class Text : public sf::Drawable, public sf::Transformable { + private: + Font &font_; + const std::string text_; + sf::VertexArray vertices_; + public: + Text(Font &font, const std::string &text); + virtual void draw(sf::RenderTarget& target, + sf::RenderStates states) const override; + }; +} + +#endif // GRAPHICS_FONT_H -- cgit v1.2.3