move dereferencing out of SwfdecAsValue macros
[swfdec.git] / swfdec / swfdec_transform_as.c
blob380f43d7ee5a356dd77be7cfcc55a6a5d53cdcbf
1 /* Swfdec
2 * Copyright (C) 2007-2008 Pekka Lampila <pekka.lampila@iki.fi>
3 * 2008 Benjamin Otte <otte@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
25 #include "swfdec_transform_as.h"
27 #include "swfdec_color_transform_as.h"
28 #include "swfdec_as_internal.h"
29 #include "swfdec_as_strings.h"
30 #include "swfdec_debug.h"
31 #include "swfdec_utils.h"
33 G_DEFINE_TYPE (SwfdecTransformAs, swfdec_transform_as, SWFDEC_TYPE_AS_RELAY)
35 static void
36 swfdec_transform_as_mark (SwfdecGcObject *object)
38 SwfdecTransformAs *trans = SWFDEC_TRANSFORM_AS (object);
40 if (trans->target != NULL)
41 swfdec_gc_object_mark (trans->target);
43 SWFDEC_GC_OBJECT_CLASS (swfdec_transform_as_parent_class)->mark (object);
46 static void
47 swfdec_transform_as_class_init (SwfdecTransformAsClass *klass)
49 SwfdecGcObjectClass *gc_class = SWFDEC_GC_OBJECT_CLASS (klass);
51 gc_class->mark = swfdec_transform_as_mark;
54 static void
55 swfdec_transform_as_init (SwfdecTransformAs *transform)
59 // properties
60 SWFDEC_AS_NATIVE (1106, 101, swfdec_transform_as_get_matrix)
61 void
62 swfdec_transform_as_get_matrix (SwfdecAsContext *cx, SwfdecAsObject *object,
63 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
65 SwfdecTransformAs *transform;
66 SwfdecAsObject *o;
67 cairo_matrix_t *matrix;
68 SwfdecAsValue val;
70 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS, &transform, "");
71 if (transform->target == NULL)
72 return;
74 swfdec_movie_update (transform->target);
75 matrix = &transform->target->matrix;
76 o = swfdec_as_object_new_empty (cx);
77 swfdec_as_object_set_constructor_by_name (o, SWFDEC_AS_STR_flash,
78 SWFDEC_AS_STR_geom, SWFDEC_AS_STR_Matrix, NULL);
80 swfdec_as_value_set_number (cx, &val, matrix->xx);
81 swfdec_as_object_set_variable (o, SWFDEC_AS_STR_a, &val);
82 swfdec_as_value_set_number (cx, &val, matrix->yx);
83 swfdec_as_object_set_variable (o, SWFDEC_AS_STR_b, &val);
84 swfdec_as_value_set_number (cx, &val, matrix->xy);
85 swfdec_as_object_set_variable (o, SWFDEC_AS_STR_c, &val);
86 swfdec_as_value_set_number (cx, &val, matrix->yy);
87 swfdec_as_object_set_variable (o, SWFDEC_AS_STR_d, &val);
88 swfdec_as_value_set_number (cx, &val, matrix->yy);
89 swfdec_as_object_set_variable (o, SWFDEC_AS_STR_d, &val);
90 swfdec_as_value_set_number (cx, &val, SWFDEC_TWIPS_TO_DOUBLE (matrix->x0));
91 swfdec_as_object_set_variable (o, SWFDEC_AS_STR_tx, &val);
92 swfdec_as_value_set_number (cx, &val, SWFDEC_TWIPS_TO_DOUBLE (matrix->y0));
93 swfdec_as_object_set_variable (o, SWFDEC_AS_STR_ty, &val);
95 SWFDEC_AS_VALUE_SET_OBJECT (ret, o);
98 SWFDEC_AS_NATIVE (1106, 102, swfdec_transform_as_set_matrix)
99 void
100 swfdec_transform_as_set_matrix (SwfdecAsContext *cx, SwfdecAsObject *object,
101 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
103 cairo_matrix_t tmp;
104 SwfdecTransformAs *transform;
105 SwfdecAsObject *o;
106 SwfdecMovie *movie;
108 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS, &transform, "o", &o);
109 if (transform->target == NULL ||
110 !swfdec_matrix_from_as_object (&tmp, o))
111 return;
113 tmp.x0 = SWFDEC_DOUBLE_TO_TWIPS (tmp.x0);
114 tmp.y0 = SWFDEC_DOUBLE_TO_TWIPS (tmp.y0);
116 /* NB: We don't use begin/end_update_matrix() here, because Flash is
117 * broken enough to not want that. */
118 movie = transform->target;
119 swfdec_movie_invalidate_next (movie);
121 movie->matrix = tmp;
123 swfdec_movie_queue_update (movie, SWFDEC_MOVIE_INVALID_EXTENTS);
124 swfdec_matrix_ensure_invertible (&movie->matrix, &movie->inverse_matrix);
125 g_signal_emit_by_name (movie, "matrix-changed");
128 SWFDEC_AS_NATIVE (1106, 103, swfdec_transform_as_get_concatenatedMatrix)
129 void
130 swfdec_transform_as_get_concatenatedMatrix (SwfdecAsContext *cx,
131 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
132 SwfdecAsValue *ret)
134 SWFDEC_STUB ("Transform.concatenatedMatrix (get)");
137 SWFDEC_AS_NATIVE (1106, 104, swfdec_transform_as_set_concatenatedMatrix)
138 void
139 swfdec_transform_as_set_concatenatedMatrix (SwfdecAsContext *cx,
140 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
141 SwfdecAsValue *ret)
143 SWFDEC_STUB ("Transform.concatenatedMatrix (set)");
146 SWFDEC_AS_NATIVE (1106, 105, swfdec_transform_as_get_colorTransform)
147 void
148 swfdec_transform_as_get_colorTransform (SwfdecAsContext *cx,
149 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
150 SwfdecAsValue *ret)
152 SwfdecTransformAs *transform;
153 SwfdecColorTransformAs *ctrans;
155 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS, &transform, "");
157 if (transform->target == NULL)
158 return;
160 ctrans = swfdec_color_transform_as_new_from_transform (cx,
161 &transform->target->color_transform);
162 SWFDEC_AS_VALUE_SET_OBJECT (ret, swfdec_as_relay_get_as_object (SWFDEC_AS_RELAY (ctrans)));
165 SWFDEC_AS_NATIVE (1106, 106, swfdec_transform_as_set_colorTransform)
166 void
167 swfdec_transform_as_set_colorTransform (SwfdecAsContext *cx,
168 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
169 SwfdecAsValue *ret)
171 SwfdecTransformAs *self;
172 SwfdecColorTransformAs *transform_as;
173 SwfdecAsObject *color;
175 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS, &self, "o", &color);
177 if (self->target == NULL)
178 return;
180 if (color == NULL || !SWFDEC_IS_COLOR_TRANSFORM_AS (color->relay))
181 return;
183 transform_as = SWFDEC_COLOR_TRANSFORM_AS (color->relay);
185 swfdec_color_transform_get_transform (transform_as, &self->target->color_transform);
188 SWFDEC_AS_NATIVE (1106, 107, swfdec_transform_as_get_concatenatedColorTransform)
189 void
190 swfdec_transform_as_get_concatenatedColorTransform (SwfdecAsContext *cx,
191 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
192 SwfdecAsValue *ret)
194 SwfdecTransformAs *self;
195 SwfdecColorTransform chain;
196 SwfdecColorTransformAs *ctrans;
197 SwfdecMovie *movie;
199 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS, &self, "");
201 if (self->target == NULL)
202 return;
204 chain = self->target->color_transform;
206 for (movie = self->target->parent; movie != NULL; movie = movie->parent) {
207 swfdec_color_transform_chain (&chain, &movie->color_transform, &chain);
210 ctrans = swfdec_color_transform_as_new_from_transform (cx, &chain);
211 SWFDEC_AS_VALUE_SET_OBJECT (ret, swfdec_as_relay_get_as_object (SWFDEC_AS_RELAY (ctrans)));
214 SWFDEC_AS_NATIVE (1106, 108, swfdec_transform_as_set_concatenatedColorTransform)
215 void
216 swfdec_transform_as_set_concatenatedColorTransform (SwfdecAsContext *cx,
217 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
218 SwfdecAsValue *ret)
220 // read-only
223 SWFDEC_AS_NATIVE (1106, 109, swfdec_transform_as_get_pixelBounds)
224 void
225 swfdec_transform_as_get_pixelBounds (SwfdecAsContext *cx,
226 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
227 SwfdecAsValue *ret)
229 SWFDEC_STUB ("Transform.pixelBounds (get)");
232 SWFDEC_AS_NATIVE (1106, 110, swfdec_transform_as_set_pixelBounds)
233 void
234 swfdec_transform_as_set_pixelBounds (SwfdecAsContext *cx,
235 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
236 SwfdecAsValue *ret)
238 SWFDEC_STUB ("Transform.pixelBounds (set)");
241 // constructor
242 SWFDEC_AS_NATIVE (1106, 0, swfdec_transform_as_construct)
243 void
244 swfdec_transform_as_construct (SwfdecAsContext *cx, SwfdecAsObject *object,
245 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
247 SwfdecTransformAs *trans;
248 SwfdecMovie *movie;
250 if (!swfdec_as_context_is_constructing (cx))
251 return;
253 SWFDEC_AS_CHECK (0, NULL, "M", &movie);
255 trans = g_object_new (SWFDEC_TYPE_TRANSFORM_AS, "context", cx, NULL);
256 trans->target = SWFDEC_AS_VALUE_GET_MOVIE (*&argv[0]);
257 swfdec_as_object_set_relay (object, SWFDEC_AS_RELAY (trans));
258 SWFDEC_AS_VALUE_SET_OBJECT (ret, object);
261 SwfdecTransformAs *
262 swfdec_transform_as_new (SwfdecAsContext *context, SwfdecMovie *target)
264 SwfdecTransformAs *transform;
265 SwfdecAsObject *object;
267 g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), NULL);
268 g_return_val_if_fail (SWFDEC_IS_MOVIE (target), NULL);
270 transform = g_object_new (SWFDEC_TYPE_TRANSFORM_AS, "context", context, NULL);
271 transform->target = target;
273 object = swfdec_as_object_new (context, NULL);
274 swfdec_as_object_set_constructor_by_name (object,
275 SWFDEC_AS_STR_flash, SWFDEC_AS_STR_geom, SWFDEC_AS_STR_Transform, NULL);
277 swfdec_as_object_set_relay (object, SWFDEC_AS_RELAY (transform));
279 return transform;