mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-13 20:18:50 +03:00
add wonky image loading
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user