you can use gtk_image_new_from_file on a .gif and it will load the animation and loop it forever.
you can also use GdkPixbufAnimation
http://library.gnome.org/devel/gdk-pixb ... ation.html
which gives a bit more control.
the only advantage that I can really think of for using GdkPixbufAnimation is that you can stop the animation once a condition is met,
in my example I stop the animation after 30 frames
Code:
#include <gtk/gtk.h>
typedef struct _Iter_Image
{
GtkWidget *im;
GdkPixbufAnimationIter *iter;
} Iter_Image;
gboolean advance_frame(Iter_Image *ii)
{
static gint frame = 1;
if(gdk_pixbuf_animation_iter_advance(ii->iter, NULL))
{
frame++;
gtk_image_set_from_pixbuf(GTK_IMAGE(ii->im), gdk_pixbuf_animation_iter_get_pixbuf(ii->iter));
}
if(frame == 30)
return FALSE;
return TRUE;
}
int main(int argc, char **argv)
{
GtkWidget *win;
GtkWidget *im;
GdkPixbufAnimation *anim;
GdkPixbufAnimationIter *iter;
GdkPixbuf *pbuf;
GError *err;
Iter_Image ii;
err = NULL;
gtk_init(&argc, &argv);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(gtk_main_quit), NULL);
anim = gdk_pixbuf_animation_new_from_file("test.gif", &err);
if(err != NULL)
{
g_critical(err->message);
g_error_free(err);
return 1;
}
iter = gdk_pixbuf_animation_get_iter(anim, NULL);
pbuf = gdk_pixbuf_animation_iter_get_pixbuf(iter);
im = gtk_image_new_from_pixbuf(pbuf);
gtk_container_add(GTK_CONTAINER(win), im);
gtk_widget_show(im);
ii.im = im;
ii.iter = iter;
g_timeout_add(gdk_pixbuf_animation_iter_get_delay_time(iter), (GSourceFunc)advance_frame, (gpointer)&ii);
gtk_widget_show(win);
gtk_main();
return 0;
}