abaddon/imgmanager.hpp

32 lines
854 B
C++
Raw Normal View History

2020-09-12 07:17:34 +00:00
#pragma once
#include <string>
#include <unordered_map>
#include <functional>
#include <queue>
2020-09-12 07:17:34 +00:00
#include <gtkmm.h>
#include "filecache.hpp"
class ImageManager {
public:
ImageManager();
using callback_type = std::function<void(Glib::RefPtr<Gdk::Pixbuf>)>;
2020-09-12 07:17:34 +00:00
Cache &GetCache();
void LoadFromURL(std::string url, callback_type cb);
2020-09-12 07:17:34 +00:00
Glib::RefPtr<Gdk::Pixbuf> GetFromURLIfCached(std::string url);
Glib::RefPtr<Gdk::Pixbuf> GetPlaceholder(int size);
2020-09-12 07:17:34 +00:00
private:
Glib::RefPtr<Gdk::Pixbuf> ReadFileToPixbuf(std::string path);
mutable std::mutex m_load_mutex;
void RunCallbacks();
Glib::Dispatcher m_cb_dispatcher;
mutable std::mutex m_cb_mutex;
std::queue<std::pair<Glib::RefPtr<Gdk::Pixbuf>, callback_type>> m_cb_queue;
2020-09-12 07:17:34 +00:00
std::unordered_map<std::string, Glib::RefPtr<Gdk::Pixbuf>> m_pixs;
Cache m_cache;
};