#pragma once #include "Text.hpp" #include #include #include #include #include #include namespace QuickMedia { class Program; class BodyItem { public: BodyItem(std::string _title): visible(true), dirty(true) { set_title(std::move(_title)); } BodyItem(const BodyItem &other) { title = other.title; description = other.description; url = other.url; thumbnail_url = other.thumbnail_url; attached_content_url = other.attached_content_url; author = other.author; visible = other.visible; dirty = other.dirty; if(other.title_text) title_text = std::make_unique(*other.title_text); else title_text = nullptr; if(other.description_text) description_text = std::make_unique(*other.description_text); else description_text = nullptr; replies = other.replies; post_number = other.post_number; } void set_title(std::string new_title) { title = std::move(new_title); dirty = true; } void set_description(std::string new_description) { description = std::move(new_description); } const std::string& get_title() const { return title; } const std::string& get_description() const { return description; } // TODO: Use a list of strings instead, not all plugins need all of these fields std::string url; std::string thumbnail_url; std::string attached_content_url; std::string author; bool visible; bool dirty; std::unique_ptr title_text; std::unique_ptr description_text; // Used by image boards for example. The elements are indices to other body items std::vector replies; std::string post_number; private: std::string title; std::string description; }; using BodyItems = std::vector>; class Body { public: Body(Program *program, sf::Font *font, sf::Font *bold_font); // Select previous item, ignoring invisible items void select_previous_item(); // Select next item, ignoring invisible items void select_next_item(); void select_first_item(); void reset_selected(); void clear_items(); void clear_thumbnails(); BodyItem* get_selected() const; void clamp_selection(); void draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size); void draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress); static bool string_find_case_insensitive(const std::string &str, const std::string &substr); // TODO: Make this actually fuzzy... Right now it's just a case insensitive string find. // This would require reordering the body. // TODO: Highlight the part of the text that matches the search. // TODO: Ignore dot, whitespace and special characters void filter_search_fuzzy(const std::string &text); bool no_items_visible() const; sf::Font *font; sf::Font *bold_font; sf::Text progress_text; sf::Text author_text; sf::Text replies_text; int selected_item; BodyItems items; std::thread thumbnail_load_thread; bool draw_thumbnails; private: struct ThumbnailData { bool referenced; std::shared_ptr texture; }; Program *program; std::shared_ptr load_thumbnail_from_url(const std::string &url); std::unordered_map item_thumbnail_textures; bool loading_thumbnail; }; }