make numbers garbage-collected objects
[swfdec.git] / swfdec / swfdec_movie.h
blobf00098a663e8a604b3cbe438be6523604911e2fd
1 /* Swfdec
2 * Copyright (C) 2006-2008 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifndef _SWFDEC_MOVIE_H_
21 #define _SWFDEC_MOVIE_H_
23 #include <glib-object.h>
24 #include <swfdec/swfdec_as_object.h>
25 #include <swfdec/swfdec_color.h>
26 #include <swfdec/swfdec.h>
27 #include <swfdec/swfdec_event.h>
28 #include <swfdec/swfdec_rect.h>
29 #include <swfdec/swfdec_types.h>
31 G_BEGIN_DECLS
34 typedef struct _SwfdecMovieClass SwfdecMovieClass;
36 /* descriptions taken from http://www.kirupa.com/developer/actionscript/depths2.htm */
37 typedef enum {
38 SWFDEC_DEPTH_CLASS_EMPTY,
39 SWFDEC_DEPTH_CLASS_TIMELINE,
40 SWFDEC_DEPTH_CLASS_DYNAMIC,
41 SWFDEC_DEPTH_CLASS_RESERVED
42 } SwfdecDepthClass;
44 typedef enum {
45 SWFDEC_MOVIE_STATE_RUNNING = 0, /* the movie has been created */
46 SWFDEC_MOVIE_STATE_REMOVED, /* swfdec_movie_remove has been called */
47 SWFDEC_MOVIE_STATE_DESTROYED /* swfdec_movie_destroy has been called */
48 } SwfdecMovieState;
50 typedef enum {
51 SWFDEC_FLASH_MAYBE = 0,
52 SWFDEC_FLASH_YES,
53 SWFDEC_FLASH_NO
54 } SwfdecFlashBool;
56 typedef enum {
57 SWFDEC_MOVIE_PROPERTY_X = 0,
58 SWFDEC_MOVIE_PROPERTY_Y = 1,
59 SWFDEC_MOVIE_PROPERTY_XSCALE = 2,
60 SWFDEC_MOVIE_PROPERTY_YSCALE = 3,
61 SWFDEC_MOVIE_PROPERTY_CURRENTFRAME = 4,
62 SWFDEC_MOVIE_PROPERTY_TOTALFRAMES = 5,
63 SWFDEC_MOVIE_PROPERTY_ALPHA = 6,
64 SWFDEC_MOVIE_PROPERTY_VISIBLE = 7,
65 SWFDEC_MOVIE_PROPERTY_WIDTH = 8,
66 SWFDEC_MOVIE_PROPERTY_HEIGHT = 9,
67 SWFDEC_MOVIE_PROPERTY_ROTATION = 10,
68 SWFDEC_MOVIE_PROPERTY_TARGET = 11,
69 SWFDEC_MOVIE_PROPERTY_FRAMESLOADED = 12,
70 SWFDEC_MOVIE_PROPERTY_NAME = 13,
71 SWFDEC_MOVIE_PROPERTY_DROPTARGET = 14,
72 SWFDEC_MOVIE_PROPERTY_URL = 15,
73 SWFDEC_MOVIE_PROPERTY_HIGHQUALITY = 16,
74 SWFDEC_MOVIE_PROPERTY_FOCUSRECT = 17,
75 SWFDEC_MOVIE_PROPERTY_SOUNDBUFTIME = 18,
76 SWFDEC_MOVIE_PROPERTY_QUALITY = 19,
77 SWFDEC_MOVIE_PROPERTY_XMOUSE = 20,
78 SWFDEC_MOVIE_PROPERTY_YMOUSE = 21
79 } SwfdecMovieProperty;
81 #define SWFDEC_BLEND_MODE_NONE 0
82 #define SWFDEC_BLEND_MODE_NORMAL 1
83 #define SWFDEC_BLEND_MODE_LAYER 2
84 #define SWFDEC_BLEND_MODE_MULTIPLY 3
85 #define SWFDEC_BLEND_MODE_SCREEN 4
86 #define SWFDEC_BLEND_MODE_LIGHTEN 5
87 #define SWFDEC_BLEND_MODE_DARKEN 6
88 #define SWFDEC_BLEND_MODE_DIFFERENCE 7
89 #define SWFDEC_BLEND_MODE_ADD 8
90 #define SWFDEC_BLEND_MODE_SUBTRACT 9
91 #define SWFDEC_BLEND_MODE_INVERT 10
92 #define SWFDEC_BLEND_MODE_ALPHA 11
93 #define SWFDEC_BLEND_MODE_ERASE 12
94 #define SWFDEC_BLEND_MODE_OVERLAY 13
95 #define SWFDEC_BLEND_MODE_HARDLIGHT 14
97 #define SWFDEC_TYPE_MOVIE (swfdec_movie_get_type())
98 #define SWFDEC_IS_MOVIE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_MOVIE))
99 #define SWFDEC_IS_MOVIE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_MOVIE))
100 #define SWFDEC_MOVIE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_MOVIE, SwfdecMovie))
101 #define SWFDEC_MOVIE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_MOVIE, SwfdecMovieClass))
102 #define SWFDEC_MOVIE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_MOVIE, SwfdecMovieClass))
104 /* NB: each following state includes the previous */
105 typedef enum {
106 SWFDEC_MOVIE_UP_TO_DATE = 0, /* everything OK */
107 SWFDEC_MOVIE_INVALID_CHILDREN, /* call update on children */
108 SWFDEC_MOVIE_INVALID_EXTENTS, /* recalculate extents */
109 } SwfdecMovieCacheState;
111 typedef void (*SwfdecMovieVariableListenerFunction) (SwfdecAsObject *object,
112 const char *name, const SwfdecAsValue *val);
114 typedef struct {
115 SwfdecAsObject * object;
116 const char * name;
117 SwfdecMovieVariableListenerFunction function;
118 } SwfdecMovieVariableListener;
120 struct _SwfdecMovie {
121 SwfdecAsObject object;
123 SwfdecGraphic * graphic; /* graphic represented by this movie or NULL if script-created */
124 const char * name; /* name of movie - GC'd */
125 GList * list; /* our contained movie clips (ordered by depth) */
126 int depth; /* depth of movie (equals content->depth unless explicitly set) */
127 SwfdecMovieCacheState cache_state; /* whether we are up to date */
128 SwfdecMovieState state; /* state the movie is in */
129 GSList *variable_listeners; /* textfield's listening to changes in variables - SwfdecMovieVariableListener */
131 /* static properties (set by PlaceObject tags) */
132 const char * original_name; /* the original name - GC'd and static */
133 cairo_matrix_t original_transform; /* initial transform used */
134 guint original_ratio; /* ratio used in this movie */
135 int clip_depth; /* up to which movie this movie clips */
137 /* parenting information */
138 SwfdecMovie * parent; /* movie that contains us or NULL for root movies */
139 gboolean lockroot; /* when looking for _root we should use this movie, even if it has a parent */
140 SwfdecResource * resource; /* the resource that created us */
142 /* positioning - the values are applied in this order */
143 SwfdecRect extents; /* the extents occupied after transform is applied */
144 SwfdecRect original_extents; /* the extents from all children - unmodified */
145 gboolean modified; /* TRUE if the transform has been modified by scripts */
146 double xscale; /* x scale in percent */
147 double yscale; /* y scale in percent */
148 double rotation; /* rotation in degrees [-180, 180] */
149 cairo_matrix_t matrix; /* cairo matrix computed from above and content->transform */
150 cairo_matrix_t inverse_matrix; /* the inverse of the cairo matrix */
151 SwfdecColorTransform color_transform; /* scripted color transformation */
152 guint blend_mode; /* blend mode to use - see to-cairo conversion code for what they mean */
154 /* iteration state */
155 gboolean visible; /* whether we currently can be seen or iterate */
157 /* drawing state */
158 SwfdecMovie * mask_of; /* movie this movie is a mask of or NULL if none */
159 SwfdecMovie * masked_by; /* movie we are masked by or NULL if none */
160 GSList * filters; /* filters to apply to movie */
161 gboolean cache_as_bitmap; /* the movie should be cached */
162 /* FIXME: could it be that shape drawing (SwfdecGraphicMovie etc) uses these same objects? */
163 SwfdecImage * image; /* image loaded via loadMovie */
164 SwfdecRect draw_extents; /* extents of the items in the following list */
165 GSList * draws; /* all the items to draw */
166 SwfdecDraw * draw_fill; /* current fill style or NULL */
167 SwfdecDraw * draw_line; /* current line style or NULL */
168 int draw_x; /* current x position for drawing */
169 int draw_y; /* current y position for drawing */
171 /* invalidatation state */
172 gboolean invalidate_last; /* TRUE if this movie's previous contents are already invalidated */
173 gboolean invalidate_next; /* TRUE if this movie should be invalidated before unlocking */
175 /* leftover unimplemented variables from the Actionscript spec */
176 #if 0
177 int droptarget;
178 #endif
181 struct _SwfdecMovieClass {
182 SwfdecAsObjectClass object_class;
184 /* general vfuncs */
185 void (* init_movie) (SwfdecMovie * movie);
186 void (* finish_movie) (SwfdecMovie * movie);
187 void (* property_get) (SwfdecMovie * movie,
188 guint prop_id,
189 SwfdecAsValue * value);
190 void (* property_set) (SwfdecMovie * movie,
191 guint prop_id,
192 const SwfdecAsValue * value);
193 void (* replace) (SwfdecMovie * movie,
194 SwfdecGraphic * graphic);
195 void (* set_ratio) (SwfdecMovie * movie);
196 void (* update_extents) (SwfdecMovie * movie,
197 SwfdecRect * extents);
198 void (* render) (SwfdecMovie * movie,
199 cairo_t * cr,
200 const SwfdecColorTransform *trans);
201 void (* invalidate) (SwfdecMovie * movie,
202 const cairo_matrix_t * movie_to_global,
203 gboolean new_contents);
205 SwfdecMovie * (* contains) (SwfdecMovie * movie,
206 double x,
207 double y,
208 gboolean events);
211 GType swfdec_movie_get_type (void);
213 SwfdecMovie * swfdec_movie_new (SwfdecPlayer * player,
214 int depth,
215 SwfdecMovie * parent,
216 SwfdecResource * resource,
217 SwfdecGraphic * graphic,
218 const char * name);
219 SwfdecMovie * swfdec_movie_duplicate (SwfdecMovie * movie,
220 const char * name,
221 int depth);
222 void swfdec_movie_initialize (SwfdecMovie * movie);
223 SwfdecMovie * swfdec_movie_find (SwfdecMovie * movie,
224 int depth);
225 SwfdecMovie * swfdec_movie_get_by_name (SwfdecMovie * movie,
226 const char * name,
227 gboolean unnamed);
228 SwfdecMovie * swfdec_movie_get_root (SwfdecMovie * movie);
229 void swfdec_movie_property_set (SwfdecMovie * movie,
230 guint id,
231 const SwfdecAsValue * val);
232 void swfdec_movie_property_get (SwfdecMovie * movie,
233 guint id,
234 SwfdecAsValue * val);
235 void swfdec_movie_remove (SwfdecMovie * movie);
236 void swfdec_movie_destroy (SwfdecMovie * movie);
237 void swfdec_movie_set_static_properties
238 (SwfdecMovie * movie,
239 const cairo_matrix_t * transform,
240 const SwfdecColorTransform *ctrans,
241 int ratio,
242 int clip_depth,
243 guint blend_mode,
244 SwfdecEventList * events);
245 void swfdec_movie_invalidate_last (SwfdecMovie * movie);
246 void swfdec_movie_invalidate_next (SwfdecMovie * movie);
247 void swfdec_movie_invalidate (SwfdecMovie * movie,
248 const cairo_matrix_t * parent_to_global,
249 gboolean last);
250 void swfdec_movie_queue_update (SwfdecMovie * movie,
251 SwfdecMovieCacheState state);
252 void swfdec_movie_update (SwfdecMovie * movie);
253 void swfdec_movie_begin_update_matrix(SwfdecMovie * movie);
254 void swfdec_movie_end_update_matrix (SwfdecMovie * movie);
255 void swfdec_movie_local_to_global (SwfdecMovie * movie,
256 double * x,
257 double * y);
258 void swfdec_movie_global_to_local (SwfdecMovie * movie,
259 double * x,
260 double * y);
261 void swfdec_movie_global_to_local_matrix
262 (SwfdecMovie * movie,
263 cairo_matrix_t * matrix);
264 void swfdec_movie_local_to_global_matrix
265 (SwfdecMovie * movie,
266 cairo_matrix_t * matrix);
267 void swfdec_movie_rect_local_to_global (SwfdecMovie * movie,
268 SwfdecRect * rect);
269 void swfdec_movie_rect_global_to_local (SwfdecMovie * movie,
270 SwfdecRect * rect);
271 void swfdec_movie_set_depth (SwfdecMovie * movie,
272 int depth);
274 void swfdec_movie_get_mouse (SwfdecMovie * movie,
275 double * x,
276 double * y);
277 #define swfdec_movie_contains(movie, x, y) \
278 (swfdec_movie_get_movie_at ((movie), (x), (y), FALSE) != NULL)
279 SwfdecMovie * swfdec_movie_get_movie_at (SwfdecMovie * movie,
280 double x,
281 double y,
282 gboolean events);
283 char * swfdec_movie_get_path (SwfdecMovie * movie,
284 gboolean dot);
285 void swfdec_movie_render (SwfdecMovie * movie,
286 cairo_t * cr,
287 const SwfdecColorTransform *trans);
288 gboolean swfdec_movie_is_scriptable (SwfdecMovie * movie);
289 SwfdecMovie * swfdec_movie_resolve (SwfdecMovie * movie);
290 guint swfdec_movie_get_version (SwfdecMovie * movie);
292 int swfdec_movie_compare_depths (gconstpointer a,
293 gconstpointer b);
294 SwfdecDepthClass
295 swfdec_depth_classify (int depth);
297 /* in swfdec_movie_asprops.c */
298 guint swfdec_movie_property_lookup (const char * name);
299 void swfdec_movie_property_do_set (SwfdecMovie * movie,
300 guint id,
301 const SwfdecAsValue * val);
302 void swfdec_movie_property_do_get (SwfdecMovie * movie,
303 guint id,
304 SwfdecAsValue * val);
306 void swfdec_movie_add_variable_listener (SwfdecMovie * movie,
307 SwfdecAsObject * object,
308 const char * name,
309 const SwfdecMovieVariableListenerFunction function);
310 void swfdec_movie_remove_variable_listener (SwfdecMovie * movie,
311 SwfdecAsObject * object,
312 const char * name,
313 const SwfdecMovieVariableListenerFunction function);
314 SwfdecResource *swfdec_movie_get_own_resource (SwfdecMovie * movie);
316 G_END_DECLS
317 #endif