#include "../include/DynamicImage.hpp" #include "../include/GlobalCache.hpp" #include "../include/GtkGif.hpp" #include "../include/GtkScaledImage.hpp" namespace dchat { DynamicImage::DynamicImage(int _downloadLimitBytes) : downloadLimitBytes(_downloadLimitBytes) { signal_draw().connect(sigc::mem_fun(*this, &DynamicImage::updateContent)); } bool DynamicImage::updateContent(const Cairo::RefPtr &cairo) { if(!url.empty()) { Gtk::Allocation alloc = get_allocation(); auto result = getGlobalCache().getContentByUrl(url, downloadLimitBytes); if(result.type == ContentByUrlResult::Type::CACHED && result.gif) { switch(result.cachedType) { case ContentByUrlResult::CachedType::STATIC_IMAGE: { GtkScaledImage *staticImage = (GtkScaledImage*)result.staticImage; staticImage->draw(cairo, alloc.get_width(), alloc.get_height(), true); break; } case ContentByUrlResult::CachedType::GIF: { GtkGif *gif = (GtkGif*)result.gif; gif->draw(cairo, alloc.get_width(), alloc.get_height(), true); break; } default: break; } } } queue_draw(); return true; } }