aboutsummaryrefslogtreecommitdiff
path: root/src/GtkGif.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/GtkGif.cpp')
-rw-r--r--src/GtkGif.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/GtkGif.cpp b/src/GtkGif.cpp
index 1da48a8..92aae88 100644
--- a/src/GtkGif.cpp
+++ b/src/GtkGif.cpp
@@ -5,8 +5,7 @@ namespace dchat
GtkGif::GtkGif(StringView fileContent) :
Gif(fileContent)
{
- //signal_draw().connect(sigc::mem_fun(*this, &GtkGif::updateContent));
- set_app_paintable(true);
+
}
bool GtkGif::createTexture(int width, int height)
@@ -18,14 +17,32 @@ namespace dchat
void GtkGif::updateTexture(void *textureData)
{
unsigned char *pixels = surface->get_data();
- memcpy(pixels, textureData, surface->get_stride() * surface->get_height());
+ surface->flush();
+ char *p = (char*)textureData;
+ // TODO: Optimize this
+ for(int i = 0; i < surface->get_stride() * surface->get_height(); i += 4)
+ {
+ pixels[i + 0] = p[i + 2];
+ pixels[i + 1] = p[i + 1];
+ pixels[i + 2] = p[i + 0];
+ pixels[i + 3] = p[i + 3];
+ }
+ //memcpy(pixels, textureData, surface->get_stride() * surface->get_height());
+ surface->mark_dirty();
}
- bool GtkGif::on_draw(const Cairo::RefPtr<Cairo::Context> &cairo)
+ void GtkGif::draw(const Cairo::RefPtr<Cairo::Context> &cairo, int width, int height)
{
update();
+
+ int minSize = std::min(width/2, height/2);
+ cairo->arc(width/2, height/2, minSize, 0.0, 2.0 * M_PI);
+ cairo->clip();
+
+ double scaleX = (double)width / (double)surface->get_width();
+ double scaleY = (double)height / (double)surface->get_height();
+ cairo->scale(scaleX, scaleY);
cairo->set_source(surface, 0.0, 0.0);
- cairo->fill();
- return true;
+ cairo->paint();
}
} \ No newline at end of file