diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/BodyItem.hpp | 20 | ||||
-rw-r--r-- | include/Config.hpp | 1 | ||||
-rw-r--r-- | include/ResourceLoader.hpp | 1 | ||||
-rw-r--r-- | include/Text.hpp | 43 |
4 files changed, 45 insertions, 20 deletions
diff --git a/include/BodyItem.hpp b/include/BodyItem.hpp index 819b730..b7dc48a 100644 --- a/include/BodyItem.hpp +++ b/include/BodyItem.hpp @@ -96,25 +96,28 @@ namespace QuickMedia { dirty_timestamp = true; } - void set_title_color(mgl::Color new_color) { - if(new_color == title_color) + void set_title_color(mgl::Color new_color, bool new_force_color = false) { + if(new_color == title_color && new_force_color == force_description_color) return; title_color = new_color; dirty = true; + force_title_color = new_force_color; } - void set_description_color(mgl::Color new_color) { - if(new_color == description_color) + void set_description_color(mgl::Color new_color, bool new_force_color = false) { + if(new_color == description_color && new_force_color == force_description_color) return; description_color = new_color; dirty_description = true; + force_description_color = new_force_color; } - void set_author_color(mgl::Color new_color) { - if(new_color == author_color) + void set_author_color(mgl::Color new_color, bool new_force_color = false) { + if(new_color == author_color && new_force_color == force_description_color) return; author_color = new_color; dirty_author = true; + force_author_color = new_force_color; } void add_reaction(std::string text, void *userdata, mgl::Color text_color); @@ -145,6 +148,8 @@ namespace QuickMedia { void draw_list(Body *body, mgl::Window &render_target); + // TODO: Bits for bools + // TODO: Use a list of strings instead, not all plugins need all of these fields std::string url; std::string thumbnail_url; @@ -156,6 +161,9 @@ namespace QuickMedia { bool dirty_reactions; // TODO: Remove this and instead if |thumbnail_url| starts with file://, then its a local file bool thumbnail_is_local; + bool force_title_color = false; + bool force_description_color = false; + bool force_author_color = false; std::unique_ptr<Text> title_text; std::unique_ptr<Text> description_text; std::unique_ptr<Text> author_text; diff --git a/include/Config.hpp b/include/Config.hpp index bd80021..9edc44b 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -65,6 +65,7 @@ namespace QuickMedia { struct FontConfig { std::string latin; std::string latin_bold; + std::string latin_monospace; std::string cjk; std::string symbols; }; diff --git a/include/ResourceLoader.hpp b/include/ResourceLoader.hpp index c60f1f3..746208a 100644 --- a/include/ResourceLoader.hpp +++ b/include/ResourceLoader.hpp @@ -14,6 +14,7 @@ namespace QuickMedia::FontLoader { enum class FontType { LATIN, LATIN_BOLD, + LATIN_MONOSPACE, CJK, SYMBOLS }; diff --git a/include/Text.hpp b/include/Text.hpp index 1533380..73dd565 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -21,17 +21,26 @@ namespace mgl { namespace QuickMedia { + static constexpr size_t FONT_ARRAY_SIZE = 6; + + enum FormattedTextFlag : uint8_t { + FORMATTED_TEXT_FLAG_NONE = 0, + //FORMATTED_TEXT_FLAG_BOLD = 1 << 0, + FORMATTED_TEXT_FLAG_MONOSPACE = 1 << 1, + FORMATTED_TEXT_FLAG_COLOR = 1 << 2 + }; + struct TextElement { enum class Type { TEXT, + FORMAT_START, + FORMAT_END, IMAGE }; enum class TextType { - LATIN, - CJK, - SYMBOL, + TEXT, EMOJI }; @@ -39,7 +48,7 @@ namespace QuickMedia void create_text(std::string_view text) { this->text = text; - text_type = TextType::LATIN; + text_type = TextType::TEXT; type = Type::TEXT; } @@ -50,10 +59,14 @@ namespace QuickMedia this->size = size; type = Type::IMAGE; } + + // TODO: Remove some fields // TODO: union grouped std::string_view text; - TextType text_type = TextType::LATIN; + TextType text_type = TextType::TEXT; + mgl::Color color = mgl::Color(255, 255, 255, 255); + uint8_t text_flags = FORMATTED_TEXT_FLAG_NONE; // FormattedTextFlag // TODO: Remove these std::string url; @@ -78,17 +91,17 @@ namespace QuickMedia { public: Text(std::string str, bool bold_font, unsigned int characterSize, float maxWidth, bool highlight_urls = false); - Text(const Text &other); - Text& operator=(const Text&); 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); + // text_flags is bit-or of FormattedTextFlag + static std::string formatted_text(const std::string &text, mgl::Color color, uint8_t text_flags); void insert_text_at_caret_position(const std::string &str); + + static std::string to_printable_string(const std::string &str); void set_position(float x, float y); void set_position(const mgl::vec2f &position); @@ -104,7 +117,7 @@ namespace QuickMedia int getCaretIndex() const; int getNumLines() const; - void set_color(mgl::Color color); + void set_color(mgl::Color color, bool force_color = false); void setLineSpacing(float lineSpacing); void setCharacterSpacing(float characterSpacing); void setEditable(bool editable); @@ -151,7 +164,8 @@ namespace QuickMedia int getPreviousLineClosestPosition(int startIndex) const; int getNextLineClosestPosition(int startIndex) const; - void split_text_by_type(std::vector<TextElement> &text_elements, const std::string &str); + static void split_text_by_type(std::vector<TextElement> &text_elements, std::string_view str, float vspace); + void split_text_by_type(); float font_get_real_height(mgl::Font *font); float get_text_quad_left_side(const VertexRef &vertex_ref) const; @@ -164,14 +178,15 @@ namespace QuickMedia uint32_t get_vertex_codepoint(int index) const; size_t get_string_index_from_caret_index(size_t caret_index) const; private: - std::string str; // TODO: Remove this for non-editable text??? also replace with std::string? then we get more efficient editing of text + std::string str; // TODO: Remove this for non-editable text??? bool bold_font; unsigned int characterSize; - std::array<std::vector<mgl::Vertex>, 5> vertices; - std::array<mgl::VertexBuffer, 5> vertex_buffers; + std::array<std::vector<mgl::Vertex>, FONT_ARRAY_SIZE> vertices; + std::array<mgl::VertexBuffer, FONT_ARRAY_SIZE> vertex_buffers; float maxWidth; mgl::vec2f position; mgl::Color color; + bool force_color; bool dirty; bool dirtyText; bool dirtyCaret; |