abaddon-ppc/imgmanager.hpp

39 lines
1.3 KiB
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();
2020-12-22 00:08:44 +00:00
using callback_anim_type = sigc::slot<void(Glib::RefPtr<Gdk::PixbufAnimation>)>;
using callback_type = sigc::slot<void(Glib::RefPtr<Gdk::Pixbuf>)>;
2020-09-12 07:17:34 +00:00
Cache &GetCache();
2021-01-20 07:26:04 +00:00
void ClearCache();
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);
Glib::RefPtr<Gdk::Pixbuf> GetPlaceholder(int size);
2020-09-12 07:17:34 +00:00
private:
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);
mutable std::mutex m_load_mutex;
void RunCallbacks();
Glib::Dispatcher m_cb_dispatcher;
mutable std::mutex m_cb_mutex;
std::queue<std::function<void()>> 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;
};