GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

create animation pixbuf ".gif"

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
ramesh
GTK+ Guru


Joined: 16 Nov 2006
Posts: 201
Location: INDIA

PostPosted: Thu Aug 21, 2008 10:21 am    Post subject: create animation pixbuf ".gif" Reply with quote

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.
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 643
Location: Falun, WI USA

PostPosted: Thu Aug 21, 2008 4:22 pm    Post subject: Reply with quote

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-pixbuf/stable/gdk-pixbuf-animation.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: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#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;
}
Back to top
ramesh
GTK+ Guru


Joined: 16 Nov 2006
Posts: 201
Location: INDIA

PostPosted: Fri Aug 22, 2008 3:43 am    Post subject: Reply with quote

thank you. its working .
but the problem is the animation image animating very fast than its orginal.
(
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 643
Location: Falun, WI USA

PostPosted: Fri Aug 22, 2008 3:59 am    Post subject: Reply with quote

it might go slower if you increase your timeout interval, ex:
Code: (C)
1
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
Back to top
ramesh
GTK+ Guru


Joined: 16 Nov 2006
Posts: 201
Location: INDIA

PostPosted: Fri Aug 22, 2008 4:07 am    Post subject: Reply with quote

dreblen wrote:
it might go slower if you increase your timeout interval, ex:
Code: (C)
1
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!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP