diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-11-05 15:53:28 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-11-05 15:53:28 +0100 |
commit | 4daa57f6d139f51a62ea4bcffa738bd5035df33a (patch) | |
tree | ba767bbbf1c7153a12e3d9e866a079c30d1c69e0 /include | |
parent | f89117b5cf36797b04291942b2f2494895fc58dd (diff) |
Support as many emoji as possible, using separate emoji images in text
Diffstat (limited to 'include')
-rw-r--r-- | include/Text.hpp | 45 |
1 files changed, 36 insertions, 9 deletions
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<TextElement> &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<std::vector<mgl::Vertex>, 4> vertices; - std::array<mgl::VertexBuffer, 4> vertex_buffers; + std::array<std::vector<mgl::Vertex>, 5> vertices; + std::array<mgl::VertexBuffer, 5> vertex_buffers; float maxWidth; mgl::vec2f position; mgl::Color color; |