aboutsummaryrefslogtreecommitdiff
path: root/include/Text.hpp
diff options
context:
space:
mode:
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;
+ };
+}