2020-09-12 07:17:34 +00:00
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <functional>
|
2020-10-03 22:49:22 +00:00
|
|
|
#include <queue>
|
2020-09-12 07:17:34 +00:00
|
|
|
#include <gtkmm.h>
|
|
|
|
#include "filecache.hpp"
|
|
|
|
|
|
|
|
class ImageManager {
|
|
|
|
public:
|
2020-10-03 22:49:22 +00:00
|
|
|
ImageManager();
|
|
|
|
|
2020-12-22 00:08:44 +00:00
|
|
|
using callback_anim_type = sigc::slot<void(Glib::RefPtr<Gdk::PixbufAnimation>)>;
|
2020-10-04 19:31:39 +00:00
|
|
|
using callback_type = sigc::slot<void(Glib::RefPtr<Gdk::Pixbuf>)>;
|
2020-10-03 22:49:22 +00:00
|
|
|
|
2020-09-12 07:17:34 +00:00
|
|
|
Cache &GetCache();
|
2021-01-20 07:26:04 +00:00
|
|
|
void ClearCache();
|
2020-10-03 22:49:22 +00:00
|
|
|
void LoadFromURL(std::string url, callback_type cb);
|
2020-12-22 00:08:44 +00:00
|
|
|
// animations need dimensions before loading since there is no (easy) way to scale a PixbufAnimation
|
|
|
|
void LoadAnimationFromURL(std::string url, int w, int h, callback_anim_type cb);
|
2020-12-18 06:13:31 +00:00
|
|
|
void Prefetch(std::string url);
|
2020-09-12 07:17:34 +00:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> GetFromURLIfCached(std::string url);
|
2020-12-22 00:08:44 +00:00
|
|
|
Glib::RefPtr<Gdk::PixbufAnimation> GetAnimationFromURLIfCached(std::string url, int w, int h);
|
2020-09-12 23:35:24 +00:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> GetPlaceholder(int size);
|
2020-09-12 07:17:34 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-03 22:49:22 +00:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> ReadFileToPixbuf(std::string path);
|
2020-12-22 00:08:44 +00:00
|
|
|
Glib::RefPtr<Gdk::PixbufAnimation> ReadFileToPixbufAnimation(std::string path, int w, int h);
|
2020-10-03 22:49:22 +00:00
|
|
|
|
|
|
|
mutable std::mutex m_load_mutex;
|
|
|
|
void RunCallbacks();
|
|
|
|
Glib::Dispatcher m_cb_dispatcher;
|
|
|
|
mutable std::mutex m_cb_mutex;
|
2020-10-04 19:31:39 +00:00
|
|
|
std::queue<std::function<void()>> m_cb_queue;
|
2020-10-03 22:49:22 +00:00
|
|
|
|
2020-09-12 07:17:34 +00:00
|
|
|
std::unordered_map<std::string, Glib::RefPtr<Gdk::Pixbuf>> m_pixs;
|
|
|
|
Cache m_cache;
|
|
|
|
};
|