~ubuntu-branches/ubuntu/utopic/gdk-pixbuf/utopic

« back to all changes in this revision

Viewing changes to gdk-pixbuf/io-ani-animation.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl
  • Date: 2012-02-06 04:39:50 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20120206043950-fqtxk78h435kiyrh
Tags: 2.24.1-1
* New upstream release.
* Explicitly enable X11 support.
* Use upper case form of term GDK in package description. (Closes: #622217)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "gdk-pixbuf-private.h"
27
27
#include "io-ani-animation.h"
28
28
 
29
 
static void gdk_pixbuf_ani_anim_class_init (GdkPixbufAniAnimClass *klass);
30
29
static void gdk_pixbuf_ani_anim_finalize   (GObject        *object);
31
30
 
32
31
static gboolean                gdk_pixbuf_ani_anim_is_static_image  (GdkPixbufAnimation *animation);
40
39
 
41
40
 
42
41
 
43
 
static gpointer parent_class;
 
42
G_DEFINE_TYPE  (GdkPixbufAniAnim, gdk_pixbuf_ani_anim, GDK_TYPE_PIXBUF_ANIMATION)
44
43
 
45
 
GType
46
 
gdk_pixbuf_ani_anim_get_type (void)
 
44
static void
 
45
gdk_pixbuf_ani_anim_init (GdkPixbufAniAnim *anim)
47
46
{
48
 
        static GType object_type = 0;
49
 
 
50
 
        if (!object_type) {
51
 
                const GTypeInfo object_info = {
52
 
                        sizeof (GdkPixbufAniAnimClass),
53
 
                        (GBaseInitFunc) NULL,
54
 
                        (GBaseFinalizeFunc) NULL,
55
 
                        (GClassInitFunc) gdk_pixbuf_ani_anim_class_init,
56
 
                        NULL,           /* class_finalize */
57
 
                        NULL,           /* class_data */
58
 
                        sizeof (GdkPixbufAniAnim),
59
 
                        0,              /* n_preallocs */
60
 
                        (GInstanceInitFunc) NULL,
61
 
                };
62
 
                
63
 
                object_type = g_type_register_static (GDK_TYPE_PIXBUF_ANIMATION,
64
 
                                                      g_intern_static_string ("GdkPixbufAniAnim"),
65
 
                                                      &object_info, 0);
66
 
        }
67
 
        
68
 
        return object_type;
69
47
}
70
48
 
71
49
static void
73
51
{
74
52
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
75
53
        GdkPixbufAnimationClass *anim_class = GDK_PIXBUF_ANIMATION_CLASS (klass);
76
 
        
77
 
        parent_class = g_type_class_peek_parent (klass);
78
 
        
 
54
 
79
55
        object_class->finalize = gdk_pixbuf_ani_anim_finalize;
80
56
 
81
57
        anim_class->is_static_image = gdk_pixbuf_ani_anim_is_static_image;
97
73
        g_free (ani_anim->pixbufs);
98
74
        g_free (ani_anim->sequence);
99
75
        g_free (ani_anim->delay);
100
 
        
101
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
 
76
 
 
77
        G_OBJECT_CLASS (gdk_pixbuf_ani_anim_parent_class)->finalize (object);
102
78
}
103
79
 
104
80
static gboolean
105
 
gdk_pixbuf_ani_anim_is_static_image  (GdkPixbufAnimation *animation)
 
81
gdk_pixbuf_ani_anim_is_static_image (GdkPixbufAnimation *animation)
106
82
{
107
83
        GdkPixbufAniAnim *ani_anim;
108
84
 
121
97
        if (ani_anim->pixbufs == NULL)
122
98
                return NULL;
123
99
        else
124
 
                return ani_anim->pixbufs[0];        
 
100
                return ani_anim->pixbufs[0];
125
101
}
126
102
 
127
103
static void
144
120
static void
145
121
iter_restart (GdkPixbufAniAnimIter *iter)
146
122
{
147
 
        iter->current_frame = 0;        
 
123
        iter->current_frame = 0;
148
124
        iter->position = 0;
149
125
        iter->elapsed = 0;
150
126
}
160
136
        iter->ani_anim = GDK_PIXBUF_ANI_ANIM (anim);
161
137
 
162
138
        g_object_ref (iter->ani_anim);
163
 
        
 
139
 
164
140
        iter_restart (iter);
165
141
 
166
142
        iter->start_time = *start_time;
167
143
        iter->current_time = *start_time;
168
 
        
 
144
 
169
145
        return GDK_PIXBUF_ANIMATION_ITER (iter);
170
146
}
171
147
 
172
148
 
173
149
 
174
 
static void gdk_pixbuf_ani_anim_iter_class_init (GdkPixbufAniAnimIterClass *klass);
175
150
static void gdk_pixbuf_ani_anim_iter_finalize   (GObject                   *object);
176
151
 
177
152
static int        gdk_pixbuf_ani_anim_iter_get_delay_time             (GdkPixbufAnimationIter *iter);
182
157
 
183
158
 
184
159
 
185
 
static gpointer iter_parent_class;
 
160
G_DEFINE_TYPE (GdkPixbufAniAnimIter, gdk_pixbuf_ani_anim_iter, GDK_TYPE_PIXBUF_ANIMATION_ITER);
186
161
 
187
 
GType
188
 
gdk_pixbuf_ani_anim_iter_get_type (void)
 
162
static void
 
163
gdk_pixbuf_ani_anim_iter_init (GdkPixbufAniAnimIter *anim)
189
164
{
190
 
        static GType object_type = 0;
191
 
 
192
 
        if (!object_type) {
193
 
                const GTypeInfo object_info = {
194
 
                        sizeof (GdkPixbufAniAnimIterClass),
195
 
                        (GBaseInitFunc) NULL,
196
 
                        (GBaseFinalizeFunc) NULL,
197
 
                        (GClassInitFunc) gdk_pixbuf_ani_anim_iter_class_init,
198
 
                        NULL,           /* class_finalize */
199
 
                        NULL,           /* class_data */
200
 
                        sizeof (GdkPixbufAniAnimIter),
201
 
                        0,              /* n_preallocs */
202
 
                        (GInstanceInitFunc) NULL,
203
 
                };
204
 
                
205
 
                object_type = g_type_register_static (GDK_TYPE_PIXBUF_ANIMATION_ITER,
206
 
                                                      g_intern_static_string ("GdkPixbufAniAnimIter"),
207
 
                                                      &object_info, 0);
208
 
        }
209
 
        
210
 
        return object_type;
211
165
}
212
166
 
213
167
static void
216
170
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
217
171
        GdkPixbufAnimationIterClass *anim_iter_class =
218
172
                GDK_PIXBUF_ANIMATION_ITER_CLASS (klass);
219
 
        
220
 
        iter_parent_class = g_type_class_peek_parent (klass);
221
 
        
 
173
 
222
174
        object_class->finalize = gdk_pixbuf_ani_anim_iter_finalize;
223
175
 
224
176
        anim_iter_class->get_delay_time = gdk_pixbuf_ani_anim_iter_get_delay_time;
233
185
        GdkPixbufAniAnimIter *iter = GDK_PIXBUF_ANI_ANIM_ITER (object);
234
186
 
235
187
        g_object_unref (iter->ani_anim);
236
 
        
237
 
        G_OBJECT_CLASS (iter_parent_class)->finalize (object);
 
188
 
 
189
        G_OBJECT_CLASS (gdk_pixbuf_ani_anim_iter_parent_class)->finalize (object);
238
190
}
239
191
 
240
192
static gboolean
247
199
        gint old;
248
200
 
249
201
        iter = GDK_PIXBUF_ANI_ANIM_ITER (anim_iter);
250
 
        
 
202
 
251
203
        iter->current_time = *current_time;
252
204
 
253
205
        /* We use milliseconds for all times */
264
216
        }
265
217
 
266
218
        g_assert (iter->ani_anim->total_time > 0);
267
 
        
 
219
 
268
220
        /* See how many times we've already played the full animation,
269
221
         * and subtract time for that.
270
222
         */
271
223
        elapsed = elapsed % iter->ani_anim->total_time;
272
224
 
273
225
        iter->position = elapsed;
274
 
        
 
226
 
275
227
        /* Now move to the proper frame */
276
 
        
 
228
 
277
229
        iter->elapsed = 0;
278
230
        for (tmp = 0; tmp < iter->ani_anim->n_frames; tmp++) {
279
231
                if (iter->position >= iter->elapsed &&
283
235
        }
284
236
 
285
237
        old = iter->current_frame;
286
 
        
 
238
 
287
239
        iter->current_frame = tmp;
288
240
 
289
241
        return iter->current_frame != old;
293
245
gdk_pixbuf_ani_anim_iter_get_delay_time (GdkPixbufAnimationIter *anim_iter)
294
246
{
295
247
        GdkPixbufAniAnimIter *iter;
296
 
  
 
248
 
297
249
        iter = GDK_PIXBUF_ANI_ANIM_ITER (anim_iter);
298
250
 
299
251
        return iter->ani_anim->delay[iter->current_frame] - (iter->position - iter->elapsed);
323
275
        gint frame;
324
276
 
325
277
        iter = GDK_PIXBUF_ANI_ANIM_ITER (anim_iter);
326
 
      
 
278
 
327
279
        if (iter->current_frame >= iter->ani_anim->n_frames - 1)
328
280
                return TRUE;
329
 
        
 
281
 
330
282
        frame = iter->ani_anim->sequence[iter->current_frame + 1];
331
283
 
332
 
        if (!iter->ani_anim->pixbufs[frame]) 
 
284
        if (!iter->ani_anim->pixbufs[frame])
333
285
                return TRUE;
334
286
 
335
287
        return FALSE;