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.
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
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
)
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
);
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
;
55 swfdec_transform_as_init (SwfdecTransformAs
*transform
)
60 SWFDEC_AS_NATIVE (1106, 101, swfdec_transform_as_get_matrix
)
62 swfdec_transform_as_get_matrix (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
63 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
65 SwfdecTransformAs
*transform
;
67 cairo_matrix_t
*matrix
;
70 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS
, &transform
, "");
71 if (transform
->target
== NULL
)
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
)
100 swfdec_transform_as_set_matrix (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
101 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
104 SwfdecTransformAs
*transform
;
108 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS
, &transform
, "o", &o
);
109 if (transform
->target
== NULL
||
110 !swfdec_matrix_from_as_object (&tmp
, o
))
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
);
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
)
130 swfdec_transform_as_get_concatenatedMatrix (SwfdecAsContext
*cx
,
131 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
134 SWFDEC_STUB ("Transform.concatenatedMatrix (get)");
137 SWFDEC_AS_NATIVE (1106, 104, swfdec_transform_as_set_concatenatedMatrix
)
139 swfdec_transform_as_set_concatenatedMatrix (SwfdecAsContext
*cx
,
140 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
143 SWFDEC_STUB ("Transform.concatenatedMatrix (set)");
146 SWFDEC_AS_NATIVE (1106, 105, swfdec_transform_as_get_colorTransform
)
148 swfdec_transform_as_get_colorTransform (SwfdecAsContext
*cx
,
149 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
152 SwfdecTransformAs
*transform
;
153 SwfdecColorTransformAs
*ctrans
;
155 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS
, &transform
, "");
157 if (transform
->target
== NULL
)
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
)
167 swfdec_transform_as_set_colorTransform (SwfdecAsContext
*cx
,
168 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
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
)
180 if (color
== NULL
|| !SWFDEC_IS_COLOR_TRANSFORM_AS (color
->relay
))
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
)
190 swfdec_transform_as_get_concatenatedColorTransform (SwfdecAsContext
*cx
,
191 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
194 SwfdecTransformAs
*self
;
195 SwfdecColorTransform chain
;
196 SwfdecColorTransformAs
*ctrans
;
199 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS
, &self
, "");
201 if (self
->target
== NULL
)
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
)
216 swfdec_transform_as_set_concatenatedColorTransform (SwfdecAsContext
*cx
,
217 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
223 SWFDEC_AS_NATIVE (1106, 109, swfdec_transform_as_get_pixelBounds
)
225 swfdec_transform_as_get_pixelBounds (SwfdecAsContext
*cx
,
226 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
229 SWFDEC_STUB ("Transform.pixelBounds (get)");
232 SWFDEC_AS_NATIVE (1106, 110, swfdec_transform_as_set_pixelBounds
)
234 swfdec_transform_as_set_pixelBounds (SwfdecAsContext
*cx
,
235 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
238 SWFDEC_STUB ("Transform.pixelBounds (set)");
242 SWFDEC_AS_NATIVE (1106, 0, swfdec_transform_as_construct
)
244 swfdec_transform_as_construct (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
245 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
247 SwfdecTransformAs
*trans
;
250 if (!swfdec_as_context_is_constructing (cx
))
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
);
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
));