add wonky image loading

This commit is contained in:
ouwou
2020-09-30 00:12:38 -04:00
parent 1460d89140
commit 4ac27e9140
10 changed files with 239 additions and 20 deletions

View File

@@ -5,15 +5,15 @@ Cache &ImageManager::GetCache() {
}
void ImageManager::LoadFromURL(std::string url, std::function<void(Glib::RefPtr<Gdk::Pixbuf>)> cb) {
if (m_pixs.find(url) != m_pixs.end()) {
/*if (m_pixs.find(url) != m_pixs.end()) {
cb(m_pixs.at(url));
return;
}
}*/
m_cache.GetFileFromURL(url, [this, url, cb](std::string path) {
try {
auto buf = Gdk::Pixbuf::create_from_file(path);
m_pixs[url] = buf;
//m_pixs[url] = buf;
cb(buf);
} catch (std::exception &e) {
fprintf(stderr, "err loading pixbuf from %s: %s\n", path.c_str(), e.what());
@@ -22,20 +22,23 @@ void ImageManager::LoadFromURL(std::string url, std::function<void(Glib::RefPtr<
}
Glib::RefPtr<Gdk::Pixbuf> ImageManager::GetFromURLIfCached(std::string url) {
if (m_pixs.find(url) != m_pixs.end())
return m_pixs.at(url);
std::string path = m_cache.GetPathIfCached(url);
if (path != "")
return Gdk::Pixbuf::create_from_file(path);
//if (m_pixs.find(url) != m_pixs.end())
// return m_pixs.at(url);
return Glib::RefPtr<Gdk::Pixbuf>(nullptr);
}
Glib::RefPtr<Gdk::Pixbuf> ImageManager::GetPlaceholder(int size) {
std::string name = "/placeholder" + std::to_string(size);
if (m_pixs.find(name) != m_pixs.end())
return m_pixs.at(name);
//if (m_pixs.find(name) != m_pixs.end())
// return m_pixs.at(name);
try {
auto buf = Gdk::Pixbuf::create_from_file("res/decamarks.png", size, size);
m_pixs[name] = buf;
// m_pixs[name] = buf;
return buf;
} catch (std::exception &e) {
fprintf(stderr, "error loading placeholder\n");