
{"id":2545,"date":"2010-08-16T20:49:15","date_gmt":"2010-08-16T15:19:15","guid":{"rendered":"http:\/\/www.jeffrin.in\/?p=2545"},"modified":"2010-08-16T20:49:15","modified_gmt":"2010-08-16T15:19:15","slug":"cairo-graphics-0-6-circle-animation","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2010\/08\/16\/cairo-graphics-0-6-circle-animation\/","title":{"rendered":"cairo graphics 0.6 Circle animation"},"content":{"rendered":"<p><a href=\"http:\/\/www.trueangle.org\/wp-content\/uploads\/2010\/09\/56163-circleanimation1-2.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.trueangle.org\/wp-content\/uploads\/2010\/09\/56163-circleanimation1-2.png?w=300\" alt=\"\" title=\"circleanimation\" width=\"300\" height=\"225\" class=\"alignnone size-medium wp-image-2548\" \/><\/a><br \/>\n<code><br \/>\n\/* Jeffrin Jose  Licensed GPL v3 Copyright<br \/>\nAugust 2010 GPL --&gt; http:\/\/www.gnu.org\/copyleft\/gpl.html *\/<\/p>\n<p>#include<br \/>\n#include<br \/>\n#include <\/p>\n<p>\/\/the global pixmap that will serve as our buffer<br \/>\nstatic GdkPixmap *pixmap = NULL;<\/p>\n<p>gboolean on_window_configure_event(GtkWidget * da, GdkEventConfigure * event, gpointer user_data){<br \/>\n    static int oldw = 0;<br \/>\n    static int oldh = 0;<br \/>\n    \/\/make our selves a properly sized pixmap if our window has been resized<br \/>\n    if (oldw != event-&gt;width || oldh != event-&gt;height){<br \/>\n        \/\/create our new pixmap with the correct size.<br \/>\n        GdkPixmap *tmppixmap = gdk_pixmap_new(da-&gt;window, event-&gt;width,  event-&gt;height, -1);<br \/>\n        \/\/copy the contents of the old pixmap to the new pixmap.  This keeps ugly uninitialized<br \/>\n        \/\/pixmaps from being painted upon resize<br \/>\n        int minw = oldw, minh = oldh;<br \/>\n        if( event-&gt;width width; }<br \/>\n        if( event-&gt;height height; }<br \/>\n        gdk_draw_drawable(tmppixmap, da-&gt;style-&gt;fg_gc[GTK_WIDGET_STATE(da)], pixmap, 0, 0, 0, 0, minw, minh);<br \/>\n        \/\/we're done with our old pixmap, so we can get rid of it and replace it with our properly-sized one.<br \/>\n        g_object_unref(pixmap);<br \/>\n        pixmap = tmppixmap;<br \/>\n    }<br \/>\n    oldw = event-&gt;width;<br \/>\n    oldh = event-&gt;height;<br \/>\n    return TRUE;<br \/>\n}<\/p>\n<p>gboolean on_window_expose_event(GtkWidget * da, GdkEventExpose * event, gpointer user_data){<br \/>\n    gdk_draw_drawable(da-&gt;window,<br \/>\n        da-&gt;style-&gt;fg_gc[GTK_WIDGET_STATE(da)], pixmap,<br \/>\n        \/\/ Only copy the area that was exposed.<br \/>\n        event-&gt;area.x, event-&gt;area.y,<br \/>\n        event-&gt;area.x, event-&gt;area.y,<br \/>\n        event-&gt;area.width, event-&gt;area.height);<br \/>\n    return TRUE;<br \/>\n}<\/p>\n<p>static int currently_drawing = 0;<br \/>\n\/\/do_draw will be executed in a separate thread whenever we would like to update<br \/>\n\/\/our animation<br \/>\nvoid *do_draw(void *ptr){<\/p>\n<p>    currently_drawing = 1;<\/p>\n<p>    int width, height;<br \/>\n    gdk_threads_enter();<br \/>\n    gdk_drawable_get_size(pixmap, &amp;width, &amp;height);<br \/>\n    gdk_threads_leave();<\/p>\n<p>    \/\/create a gtk-independant surface to draw on<br \/>\n    cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);<br \/>\n    cairo_t *cr = cairo_create(cst);<\/p>\n<p>    \/\/do some time-consuming drawing<br \/>\n    static int i = 0;<br \/>\n    ++i; i = i % 300;   \/\/give a little movement to our animation<br \/>\n    cairo_set_source_rgb (cr, .9, .9, .9);<br \/>\n    cairo_paint(cr);<br \/>\n            cairo_set_source_rgb (cr, 0.8, 0.5, 0.9);<br \/>\n            cairo_move_to(cr, 50,50);<\/p>\n<p>    int j,k;<br \/>\n\/*    for(k=0; k&lt;100; ++k){*\/   \/\/lets just redraw lots of times to use a lot of proc power<br \/>\n        for(j=0; j window,700,700,-1);<br \/>\n    \/\/because we will be painting our pixmap manually during expose events<br \/>\n    \/\/we can turn off gtk's automatic painting and double buffering routines.<br \/>\n    gtk_widget_set_app_paintable(window, TRUE);<br \/>\n    gtk_widget_set_double_buffered(window, FALSE);<\/p>\n<p>    (void)g_timeout_add(33, (GSourceFunc)timer_exe, window);<\/p>\n<p>    gtk_main();<br \/>\n    gdk_threads_leave();<\/p>\n<p>    return 0;<br \/>\n}<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* Jeffrin Jose Licensed GPL v3 Copyright August 2010 GPL &#8211;&gt; http:\/\/www.gnu.org\/copyleft\/gpl.html *\/ #include #include #include \/\/the global pixmap that will serve as our buffer static GdkPixmap *pixmap = NULL; gboolean on_window_configure_event(GtkWidget * da, GdkEventConfigure * event, gpointer user_data){ static int oldw = 0; static int oldh = 0; \/\/make our selves a properly sized &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2010\/08\/16\/cairo-graphics-0-6-circle-animation\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;cairo graphics 0.6 Circle animation&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[395,540,908,1030,1132],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/2545"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=2545"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/2545\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=2545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=2545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=2545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}