From 4277763df5c1dac8ff389d3bfd138f03acc7f1e2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 28 Sep 2020 13:32:34 +0200 Subject: Implement text editing with navigation and multilingual fonts --- include/Text.hpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'include/Text.hpp') diff --git a/include/Text.hpp b/include/Text.hpp index bc6f7ab..d34fd47 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -1,15 +1,18 @@ #pragma once #include -#include -#include -#include #include #include #include #include "types.hpp" #include +namespace sf { + class Font; + class Event; + class RenderTarget; +} + namespace QuickMedia { struct StringViewUtf32 { @@ -69,6 +72,7 @@ namespace QuickMedia void setLineSpacing(float lineSpacing); void setCharacterSpacing(float characterSpacing); void setEditable(bool editable); + bool isEditable() const; // Note: won't update until @draw is called float getWidth() const; @@ -92,21 +96,27 @@ namespace QuickMedia HOME, END }; - -#if 0 + + struct VertexRef { + int vertices_index; // index to |vertices| VertexArray + int index; // index within vertices[vertices_index] + int line; + sf::Uint32 codepoint; + }; + 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; -#endif void splitTextByFont(); + + float get_text_quad_left_side(const VertexRef &vertex_ref) const; + float get_text_quad_right_side(const VertexRef &vertex_ref) const; private: - sf::String str; + sf::String str; // TODO: Remove this for non-editable text??? const sf::Font *font; const sf::Font *cjk_font; unsigned int characterSize; @@ -131,5 +141,7 @@ namespace QuickMedia sf::Vector2f caretPosition; sf::Clock lastSeenTimer; sf::Vector2u renderTargetSize; + + std::vector vertices_linear; // TODO: Use textElements instead }; } -- cgit v1.2.3