diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Text.hpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/include/Text.hpp b/include/Text.hpp index daea7ca..9df973d 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -5,6 +5,7 @@ #include <SFML/Graphics/VertexArray.hpp> #include <SFML/Graphics/Font.hpp> #include <SFML/Graphics/RenderTarget.hpp> +#include <SFML/Window/Event.hpp> #include <SFML/System/String.hpp> #include <vector> @@ -35,7 +36,6 @@ 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); @@ -43,16 +43,36 @@ namespace dchat void setCharacterSize(unsigned int characterSize); void setFillColor(sf::Color color); void setLineSpacing(float lineSpacing); + void setEditable(bool editable); // Warning: won't update until @draw is called float getHeight() const; + void processEvent(const sf::Event &event); + // 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: + enum class CaretMoveDirection : u8 + { + NONE, + UP, + DOWN, + HOME, + END + }; + void stringSplitElements(sf::String &stringToSplit, usize startIndex); void updateGeometry(); - private: + void updateCaret(); + bool isCaretAtEnd() const; + int getStartOfLine(int startIndex) const; + int getEndOfLine(int startIndex) const; + int getRowByPosition(const sf::Vector2f &position) const; + + int getPreviousLineClosestPosition(int startIndex) const; + int getNextLineClosestPosition(int startIndex) const; + private: sf::String str; const sf::Font *font; unsigned int characterSize; @@ -62,9 +82,16 @@ namespace dchat sf::Color color; sf::Color urlColor; bool dirty; + bool dirtyText; + bool dirtyCaret; bool plainText; + bool editable; + CaretMoveDirection caretMoveDirection; float totalHeight; float lineSpacing; std::vector<TextElement> textElements; + + int caretIndex; + sf::Vector2f caretPosition; }; } |