From 3ab4127ae3fc3b837f5350509c78db03467500cd Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 23 Apr 2018 13:30:03 +0200 Subject: Add support for big emoji if it's the only thing on a line TODO: Currently message board renders directly to window, it should render to render target for optimization purpose --- include/MessageBoard.hpp | 3 +++ include/StringView.hpp | 15 ++++++++------- include/Text.hpp | 8 ++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp index 06a7cd1..ca1405f 100644 --- a/include/MessageBoard.hpp +++ b/include/MessageBoard.hpp @@ -29,5 +29,8 @@ namespace dchat sf::Vector2f mousePos; sf::Vector2f selectingTextStart; std::vector messages; + double scroll; + double scrollSpeed; + sf::Clock frameTimer; }; } diff --git a/include/StringView.hpp b/include/StringView.hpp index 4e9066b..9eea387 100644 --- a/include/StringView.hpp +++ b/include/StringView.hpp @@ -15,7 +15,7 @@ namespace dchat } - BasicStringView(const BasicStringView &other) : data(other.data), size(other.size) + BasicStringView(const BasicStringView &other) : data(other.data), size(other.size) { } @@ -30,13 +30,14 @@ namespace dchat } - BasicStringView operator = (const BasicStringView &other) + BasicStringView& operator = (const BasicStringView &other) { - BasicStringView result(other.data, other.size); - return result; + data = other.data; + size = other.size; + return *this; } - BasicStringView( BasicStringView &&other) + BasicStringView(BasicStringView &&other) { data = other.data; size = other.size; @@ -45,10 +46,10 @@ namespace dchat other.size = 0; } - bool equals(const BasicStringView &other) const + bool equals(const BasicStringView &other) const { if(size != other.size) return false; - return memcmp(data, other.data, size) == 0; + return memcmp(data, other.data, size * sizeof(CharType)) == 0; } CharType operator [] (usize index) const diff --git a/include/Text.hpp b/include/Text.hpp index 53db93b..93ec0c1 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -17,6 +17,8 @@ namespace dchat Text(const sf::String &str, const sf::Font &font, unsigned int characterSize, float maxWidth, bool plainText = true); void setString(const sf::String &str); + void appendStringNewLine(const sf::String &str); + void setPosition(float x, float y); void setPosition(const sf::Vector2f &position); void setMaxWidth(float maxWidth); @@ -26,9 +28,10 @@ namespace dchat // Warning: won't update until @draw is called float getHeight() const; + // Performs culling. @updateGeometry is called even if text is not visible if text is dirty, because updateGeometry might change the dimension of the text and make is visible void draw(sf::RenderTarget &target, Cache &cache); private: - void stringSplitElements(); + void stringSplitElements(sf::String &stringToSplit, usize startIndex); void updateGeometry(); private: struct TextElement @@ -40,11 +43,12 @@ namespace dchat }; TextElement() {} - TextElement(const StringViewUtf32 &_text, Type _type) : text(_text), type(_type) {} + TextElement(const StringViewUtf32 &_text, Type _type) : text(_text), type(_type), ownLine(false) {} StringViewUtf32 text; sf::Vector2f position; Type type; + bool ownLine; // Currently only used for emoji, to make emoji bigger when it's the only thing on a line }; sf::String str; -- cgit v1.2.3