From ddff0f1b7ea84f6a1321b8eb8a4d47317873d955 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 23 Apr 2018 09:53:31 +0200 Subject: Add word wrap for message board & TODO TODO: Message board is now redrawn every frame. Text should be modified to render on static & dynamic texture -> text & static images on static texture, gif & video on dynamic texture --- include/Text.hpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 include/Text.hpp (limited to 'include/Text.hpp') diff --git a/include/Text.hpp b/include/Text.hpp new file mode 100644 index 0000000..53db93b --- /dev/null +++ b/include/Text.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include "StringView.hpp" +#include "Cache.hpp" +#include +#include +#include +#include +#include + +namespace dchat +{ + class Text + { + public: + Text(const sf::Font &font); + Text(const sf::String &str, const sf::Font &font, unsigned int characterSize, float maxWidth, bool plainText = true); + + void setString(const sf::String &str); + void setPosition(float x, float y); + void setPosition(const sf::Vector2f &position); + void setMaxWidth(float maxWidth); + void setCharacterSize(unsigned int characterSize); + void setFillColor(sf::Color color); + + // Warning: won't update until @draw is called + float getHeight() const; + + void draw(sf::RenderTarget &target, Cache &cache); + private: + void stringSplitElements(); + void updateGeometry(); + private: + struct TextElement + { + enum class Type + { + TEXT, + EMOJI + }; + + TextElement() {} + TextElement(const StringViewUtf32 &_text, Type _type) : text(_text), type(_type) {} + + StringViewUtf32 text; + sf::Vector2f position; + Type type; + }; + + sf::String str; + sf::Font font; + unsigned int characterSize; + sf::VertexArray vertices; + float maxWidth; + sf::Vector2f position; + sf::Color color; + bool dirty; + bool plainText; + float totalHeight; + std::vector textElements; + }; +} -- cgit v1.2.3