From c7138bca7ea7d007198c544b2d8bc27ae414d2e2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 3 Nov 2018 22:49:29 +0100 Subject: Start with gif/image widget --- src/DynamicImage.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/DynamicImage.cpp (limited to 'src/DynamicImage.cpp') diff --git a/src/DynamicImage.cpp b/src/DynamicImage.cpp new file mode 100644 index 0000000..8759497 --- /dev/null +++ b/src/DynamicImage.cpp @@ -0,0 +1,28 @@ +#include "../include/DynamicImage.hpp" +#include "../include/GlobalCache.hpp" +#include "../include/GtkGif.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) + { + GtkGif *gif = (GtkGif*)result.gif; + gif->draw(cairo, alloc.get_width(), alloc.get_height()); + } + } + queue_draw(); + return true; + } +} \ No newline at end of file -- cgit v1.2.3