diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-31 09:46:32 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-31 09:46:32 +0100 |
commit | d638a6092bd6291c983490ba3f966162c7ca06c2 (patch) | |
tree | 45b9421e0f3dd22265b33be8ecdcd974e12b0346 /include | |
parent | 11f644afe434ce6b6d570c9da2a95590321871b3 (diff) |
Load fonts on demand
Diffstat (limited to 'include')
-rw-r--r-- | include/AsyncTask.hpp | 9 | ||||
-rw-r--r-- | include/Body.hpp | 5 | ||||
-rw-r--r-- | include/Entry.hpp | 2 | ||||
-rw-r--r-- | include/FontLoader.hpp | 19 | ||||
-rw-r--r-- | include/ImageViewer.hpp | 2 | ||||
-rw-r--r-- | include/QuickMedia.hpp | 3 | ||||
-rw-r--r-- | include/SearchBar.hpp | 2 | ||||
-rw-r--r-- | include/Text.hpp | 20 |
8 files changed, 35 insertions, 27 deletions
diff --git a/include/AsyncTask.hpp b/include/AsyncTask.hpp deleted file mode 100644 index 81be1ee..0000000 --- a/include/AsyncTask.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include <functional> -#include <deque> -#include <mutex> - -namespace QuickMedia { - -}
\ No newline at end of file diff --git a/include/Body.hpp b/include/Body.hpp index 1dc1fe8..1a82443 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -135,7 +135,7 @@ namespace QuickMedia { class Body { public: - Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font, sf::Texture &loading_icon_texture); + Body(Program *program, sf::Texture &loading_icon_texture); // Select previous page, ignoring invisible items. Returns true if the item was changed. This can be used to check if the top was hit when wrap_around is set to false bool select_previous_page(); @@ -199,9 +199,6 @@ namespace QuickMedia { float get_page_scroll() const { return page_scroll; } bool is_last_item_fully_visible() const { return last_item_fully_visible; } - sf::Font *font; - sf::Font *bold_font; - sf::Font *cjk_font; sf::Text progress_text; sf::Text replies_text; sf::Text embedded_item_load_text; diff --git a/include/Entry.hpp b/include/Entry.hpp index 27c3517..32dcda2 100644 --- a/include/Entry.hpp +++ b/include/Entry.hpp @@ -17,7 +17,7 @@ namespace QuickMedia { class Entry { public: - Entry(const std::string &placeholder_text, sf::Font *font, sf::Font *cjk_font); + Entry(const std::string &placeholder_text); void process_event(sf::Event &event); void draw(sf::RenderWindow &window); diff --git a/include/FontLoader.hpp b/include/FontLoader.hpp new file mode 100644 index 0000000..bff0f18 --- /dev/null +++ b/include/FontLoader.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include <string> + +namespace sf { + class Font; +} + +namespace QuickMedia::FontLoader { + enum class FontType { + LATIN, + LATIN_BOLD, + CJK, + EMOJI + }; + + // Note: not thread-safe + sf::Font* get_font(FontType font_type); +}
\ No newline at end of file diff --git a/include/ImageViewer.hpp b/include/ImageViewer.hpp index ea53558..f886709 100644 --- a/include/ImageViewer.hpp +++ b/include/ImageViewer.hpp @@ -46,7 +46,7 @@ namespace QuickMedia { class ImageViewer { public: - ImageViewer(MangaImagesPage *manga_images_page, const std::string &content_title, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir, sf::Font *font); + ImageViewer(MangaImagesPage *manga_images_page, const std::string &content_title, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir); ~ImageViewer(); ImageViewerAction draw(sf::RenderWindow &window); // Returns page as 1 indexed diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index b9ec2d9..821a427 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -104,9 +104,6 @@ namespace QuickMedia { Matrix *matrix = nullptr; int monitor_hz; sf::Vector2f window_size; - std::unique_ptr<sf::Font> font; - std::unique_ptr<sf::Font> bold_font; - std::unique_ptr<sf::Font> cjk_font; const char *plugin_name = nullptr; sf::Texture plugin_logo; sf::Texture loading_icon; diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp index eb7a9f2..de3b686 100644 --- a/include/SearchBar.hpp +++ b/include/SearchBar.hpp @@ -21,7 +21,7 @@ namespace QuickMedia { class SearchBar { public: - SearchBar(sf::Font &font, sf::Texture *plugin_logo, const std::string &placeholder, bool input_masked = false); + SearchBar(sf::Texture *plugin_logo, const std::string &placeholder, bool input_masked = false); void draw(sf::RenderWindow &window, bool draw_shadow = true); void on_event(sf::Event &event); void update(); diff --git a/include/Text.hpp b/include/Text.hpp index 7ce7fa3..e471441 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -36,15 +36,21 @@ namespace QuickMedia { TEXT }; + + enum class TextType { + LATIN, + CJK, + EMOJI + }; TextElement() {} - TextElement(const StringViewUtf32 &_text, Type _type) : text(_text), type(_type), is_cjk(false) {} + TextElement(const StringViewUtf32 &_text, Type _type) : text(_text), type(_type), text_type(TextType::LATIN) {} StringViewUtf32 text; sf::Vector2f position; Type type; //bool ownLine; // Currently only used for emoji, to make emoji bigger when it's the only thing on a line - bool is_cjk; + TextType text_type; }; struct VertexRef { @@ -57,8 +63,8 @@ namespace QuickMedia class Text { public: - Text(const sf::Font *font, const sf::Font *cjk_font); - Text(sf::String str, const sf::Font *font, const sf::Font *cjk_font, unsigned int characterSize, float maxWidth); + Text(bool bold_font); + Text(sf::String str, bool bold_font, unsigned int characterSize, float maxWidth); void setString(sf::String str); const sf::String& getString() const; @@ -73,8 +79,7 @@ namespace QuickMedia void setCharacterSize(unsigned int characterSize); unsigned int getCharacterSize() const; - - const sf::Font* getFont() const; + void setFillColor(sf::Color color); void setLineSpacing(float lineSpacing); @@ -127,8 +132,7 @@ namespace QuickMedia int get_vertex_line(int index) const; private: sf::String str; // TODO: Remove this for non-editable text??? also replace with std::string? then we get more efficient editing of text - const sf::Font *font; - const sf::Font *cjk_font; + const bool bold_font; unsigned int characterSize; sf::VertexArray vertices[2]; float maxWidth; |