summaryrefslogtreecommitdiff
path: root/src/imgmanager.hpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-11-28 22:48:30 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2021-11-28 22:48:30 -0500
commite1703aea3fd597b23bde90e6c505278c517be611 (patch)
tree37d98fc90c9cd0844388bfb79beda2204f44af92 /src/imgmanager.hpp
parentfd53a76bf6f53a095a639765923a30f2206b2cd6 (diff)
parente02107feea8214a045e6faa969f00dcbc0d2b072 (diff)
downloadabaddon-portaudio-e1703aea3fd597b23bde90e6c505278c517be611.tar.gz
abaddon-portaudio-e1703aea3fd597b23bde90e6c505278c517be611.zip
merge master
Diffstat (limited to 'src/imgmanager.hpp')
-rw-r--r--src/imgmanager.hpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/imgmanager.hpp b/src/imgmanager.hpp
new file mode 100644
index 0000000..eb8a590
--- /dev/null
+++ b/src/imgmanager.hpp
@@ -0,0 +1,38 @@
+#pragma once
+#include <string>
+#include <unordered_map>
+#include <functional>
+#include <queue>
+#include <gtkmm.h>
+#include "filecache.hpp"
+
+class ImageManager {
+public:
+ ImageManager();
+
+ using callback_anim_type = sigc::slot<void(Glib::RefPtr<Gdk::PixbufAnimation>)>;
+ using callback_type = sigc::slot<void(Glib::RefPtr<Gdk::Pixbuf>)>;
+
+ Cache &GetCache();
+ void ClearCache();
+ void LoadFromURL(std::string url, callback_type cb);
+ // 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);
+ void Prefetch(std::string url);
+ Glib::RefPtr<Gdk::Pixbuf> GetFromURLIfCached(std::string url);
+ Glib::RefPtr<Gdk::PixbufAnimation> GetAnimationFromURLIfCached(std::string url, int w, int h);
+ Glib::RefPtr<Gdk::Pixbuf> GetPlaceholder(int size);
+
+private:
+ Glib::RefPtr<Gdk::Pixbuf> ReadFileToPixbuf(std::string path);
+ 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;
+
+ std::unordered_map<std::string, Glib::RefPtr<Gdk::Pixbuf>> m_pixs;
+ Cache m_cache;
+};