aboutsummaryrefslogtreecommitdiff
path: root/include/Body.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/Body.hpp')
-rw-r--r--include/Body.hpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/include/Body.hpp b/include/Body.hpp
index 008aa70..9f7c2d8 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -10,6 +10,7 @@
#include "../external/RoundedRectangleShape.hpp"
#include <json/value.h>
#include <thread>
+#include <future>
namespace QuickMedia {
class Program;
@@ -82,6 +83,7 @@ namespace QuickMedia {
class Body {
public:
Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font);
+ ~Body();
// Select previous item, 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_item();
@@ -123,7 +125,6 @@ namespace QuickMedia {
sf::Text progress_text;
sf::Text replies_text;
BodyItems items;
- std::thread thumbnail_load_thread;
bool draw_thumbnails;
bool wrap_around;
// Set to {0, 0} to disable resizing
@@ -134,14 +135,22 @@ namespace QuickMedia {
void draw_item(sf::RenderWindow &window, BodyItem *item, const sf::Vector2f &pos, const sf::Vector2f &size, const float item_height, const int item_index, const Json::Value &content_progress);
float get_item_height(BodyItem *item);
private:
+ enum class LoadingState {
+ NOT_LOADED,
+ LOADING,
+ FINISHED_LOADING,
+ APPLIED_TO_TEXTURE
+ };
+
struct ThumbnailData {
bool referenced = false;
- std::shared_ptr<sf::Texture> texture;
- bool loaded = false;
+ LoadingState loading_state = LoadingState::NOT_LOADED;
+ sf::Texture texture;
+ std::unique_ptr<sf::Image> image; // Set in another thread, and then reset after loading it into |texture|
};
Program *program;
- std::shared_ptr<sf::Texture> load_thumbnail_from_url(const std::string &url, bool local, sf::Vector2i thumbnail_resize_target_size);
- std::unordered_map<std::string, ThumbnailData> item_thumbnail_textures;
+ void load_thumbnail_from_url(const std::string &url, bool local, sf::Vector2i thumbnail_resize_target_size, std::shared_ptr<ThumbnailData> thumbnail_data);
+ std::unordered_map<std::string, std::shared_ptr<ThumbnailData>> item_thumbnail_textures;
bool loading_thumbnail;
int selected_item;
int prev_selected_item;
@@ -151,5 +160,6 @@ namespace QuickMedia {
sf::RectangleShape item_background_shadow;
sf::RoundedRectangleShape item_background;
sf::Sprite image;
+ std::future<void> load_thumbnail_future;
};
} \ No newline at end of file