From 4daa57f6d139f51a62ea4bcffa738bd5035df33a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 5 Nov 2022 15:53:28 +0100 Subject: Support as many emoji as possible, using separate emoji images in text --- include/Text.hpp | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'include/Text.hpp') diff --git a/include/Text.hpp b/include/Text.hpp index fd1277f..1533380 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -23,9 +23,9 @@ namespace QuickMedia { struct TextElement { - enum class Type - { - TEXT + enum class Type { + TEXT, + IMAGE }; enum class TextType { @@ -36,18 +36,41 @@ namespace QuickMedia }; TextElement() {} - TextElement(std::string_view text, Type type) : text(text), type(type), text_type(TextType::LATIN) {} + + void create_text(std::string_view text) { + this->text = text; + text_type = TextType::LATIN; + type = Type::TEXT; + } + + // If size is {0, 0} then the image is drawn at its original size + void create_image(std::string url, bool local, mgl::vec2i size) { + this->url = std::move(url); + this->local = local; + this->size = size; + type = Type::IMAGE; + } + // TODO: union grouped std::string_view text; + TextType text_type = TextType::LATIN; + + // TODO: Remove these + std::string url; + bool local = false; + mgl::vec2i pos; + mgl::vec2i size; + int vertex_ref_index = 0; // Note: only used temporary within updateGeometry + int text_num_bytes = 0; // Note: only used temporary within updateGeometry + Type type; - //bool ownLine; // Currently only used for emoji, to make emoji bigger when it's the only thing on a line - TextType text_type; }; struct VertexRef { int vertices_index; // index to |vertices| VertexArray int index; // index within vertices[vertices_index] int line; + int text_num_bytes; uint32_t codepoint; }; @@ -61,6 +84,10 @@ namespace QuickMedia void setString(std::string str); const std::string& getString() const; void appendText(const std::string &str); + // size = {0, 0} = keep original image size + void append_image(const std::string &url, bool local, mgl::vec2i size); + static std::string formatted_image(const std::string &url, bool local, mgl::vec2i size); + static std::string formatted_text(const std::string &text, mgl::Color color, bool bold); void insert_text_at_caret_position(const std::string &str); void set_position(float x, float y); @@ -124,7 +151,7 @@ namespace QuickMedia int getPreviousLineClosestPosition(int startIndex) const; int getNextLineClosestPosition(int startIndex) const; - void splitTextByFont(); + void split_text_by_type(std::vector &text_elements, const std::string &str); float font_get_real_height(mgl::Font *font); float get_text_quad_left_side(const VertexRef &vertex_ref) const; @@ -140,8 +167,8 @@ namespace QuickMedia std::string str; // TODO: Remove this for non-editable text??? also replace with std::string? then we get more efficient editing of text bool bold_font; unsigned int characterSize; - std::array, 4> vertices; - std::array vertex_buffers; + std::array, 5> vertices; + std::array vertex_buffers; float maxWidth; mgl::vec2f position; mgl::Color color; -- cgit v1.2.3