2 * Copyright (C) 2003-2006 David Schleef <ds@schleef.org>
3 * 2005-2006 Eric Anholt <eric@anholt.net>
4 * 2006-2007 Benjamin Otte <otte@gnome.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
27 #include "swfdec_sprite.h"
28 #include "swfdec_debug.h"
29 #include "swfdec_movie.h"
30 #include "swfdec_player_internal.h"
31 #include "swfdec_script.h"
32 #include "swfdec_sound.h"
33 #include "swfdec_sprite_movie.h"
34 #include "swfdec_swf_decoder.h"
35 #include "swfdec_tag.h"
37 G_DEFINE_TYPE (SwfdecSprite
, swfdec_sprite
, SWFDEC_TYPE_GRAPHIC
)
40 swfdec_sprite_dispose (GObject
*object
)
42 SwfdecSprite
* sprite
= SWFDEC_SPRITE (object
);
46 for (i
= 0; i
< sprite
->n_frames
; i
++) {
47 g_slist_foreach (sprite
->frames
[i
].labels
, (GFunc
) g_free
, NULL
);
48 g_slist_free (sprite
->frames
[i
].labels
);
50 g_free(sprite
->frames
);
52 for (i
= 0; i
< sprite
->actions
->len
; i
++) {
53 SwfdecSpriteAction
*cur
= &g_array_index (sprite
->actions
, SwfdecSpriteAction
, i
);
55 swfdec_buffer_unref (cur
->buffer
);
57 g_array_free (sprite
->actions
, TRUE
);
58 sprite
->actions
= NULL
;
59 if (sprite
->init_action
) {
60 swfdec_script_unref (sprite
->init_action
);
61 sprite
->init_action
= NULL
;
64 G_OBJECT_CLASS (swfdec_sprite_parent_class
)->dispose (object
);
68 swfdec_sprite_add_action (SwfdecSprite
*sprite
, guint tag
, SwfdecBuffer
*buffer
)
70 SwfdecSpriteAction action
;
73 action
.buffer
= buffer
;
74 g_array_append_val (sprite
->actions
, action
);
78 swfdec_sprite_get_action (SwfdecSprite
*sprite
, guint n
, guint
*tag
, SwfdecBuffer
**buffer
)
80 SwfdecSpriteAction
*action
;
82 g_return_val_if_fail (SWFDEC_IS_SPRITE (sprite
), FALSE
);
83 g_return_val_if_fail (tag
!= NULL
, FALSE
);
84 g_return_val_if_fail (buffer
!= NULL
, FALSE
);
86 if (n
>= sprite
->actions
->len
)
88 action
= &g_array_index (sprite
->actions
, SwfdecSpriteAction
, n
);
90 *buffer
= action
->buffer
;
95 swfdec_sprite_class_init (SwfdecSpriteClass
* g_class
)
97 GObjectClass
*object_class
= G_OBJECT_CLASS (g_class
);
98 SwfdecGraphicClass
*graphic_class
= SWFDEC_GRAPHIC_CLASS (g_class
);
100 object_class
->dispose
= swfdec_sprite_dispose
;
102 graphic_class
->movie_type
= SWFDEC_TYPE_SPRITE_MOVIE
;
106 swfdec_sprite_init (SwfdecSprite
* sprite
)
108 sprite
->actions
= g_array_new (FALSE
, FALSE
, sizeof (SwfdecSpriteAction
));
112 swfdec_sprite_set_n_frames (SwfdecSprite
*sprite
, guint n_frames
,
115 g_return_if_fail (SWFDEC_IS_SPRITE (sprite
));
118 sprite
->frames
= g_new0 (SwfdecSpriteFrame
, n_frames
);
119 sprite
->n_frames
= n_frames
;
122 SWFDEC_LOG ("n_frames = %d", sprite
->n_frames
);
126 swfdec_sprite_get_frame (SwfdecSprite
*sprite
, const char *label
)
130 g_return_val_if_fail (SWFDEC_IS_SPRITE (sprite
), -1);
131 g_return_val_if_fail (label
!= NULL
, -1);
133 for (i
= 0; i
< SWFDEC_SPRITE (sprite
)->n_frames
; i
++) {
134 SwfdecSpriteFrame
*frame
= &sprite
->frames
[i
];
137 for (iter
= frame
->labels
; iter
!= NULL
; iter
= iter
->next
) {
138 if (g_str_equal (iter
->data
, label
))