aboutsummaryrefslogtreecommitdiff
path: root/include/Text.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-23 09:53:31 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-23 09:55:12 +0200
commitddff0f1b7ea84f6a1321b8eb8a4d47317873d955 (patch)
tree28565c3a3d336559fcf149e1552ae237cc3d855d /include/Text.hpp
parent1e0e68f9cda51c881b32a54d9eece71c1428f7ac (diff)
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
Diffstat (limited to 'include/Text.hpp')
-rw-r--r--include/Text.hpp62
1 files changed, 62 insertions, 0 deletions
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 <SFML/Graphics/VertexArray.hpp>
+#include <SFML/Graphics/Font.hpp>
+#include <SFML/Graphics/RenderTarget.hpp>
+#include <SFML/System/String.hpp>
+#include <vector>
+
+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<TextElement> textElements;
+ };
+}