GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Apr 24, 2014 3:39 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: create animation pixbuf ".gif"
PostPosted: Thu Aug 21, 2008 10:21 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
hi all
i would like to put an animation image in the gtk window.
is it possible.
can you give me an example program for this.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 4:22 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
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;
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 3:43 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
thank you. its working .
but the problem is the animation image animating very fast than its orginal.
(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 3:59 am 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
it might go slower if you increase your timeout interval, ex:
Code:
g_timeout_add(gdk_pixbuf_animation_iter_get_delay_time(iter)+100, (GSourceFunc)advance_frame, (gpointer)&ii);

the interval is measured in milliseconds, so adding 100 will add a 10th of a second


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 4:07 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
dreblen wrote:
it might go slower if you increase your timeout interval, ex:
Code:
g_timeout_add(gdk_pixbuf_animation_iter_get_delay_time(iter)+100, (GSourceFunc)advance_frame, (gpointer)&ii);

the interval is measured in milliseconds, so adding 100 will add a 10th of a second


great!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group