2 * Copyright (C) 2007-2008 Pekka Lampila <pekka.lampila@iki.fi>
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.
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
24 #include "swfdec_transform_as.h"
26 #include "swfdec_color_transform_as.h"
27 #include "swfdec_as_strings.h"
28 #include "swfdec_as_internal.h"
29 #include "swfdec_as_frame_internal.h"
30 #include "swfdec_debug.h"
31 #include "swfdec_utils.h"
33 G_DEFINE_TYPE (SwfdecTransformAs
, swfdec_transform_as
, SWFDEC_TYPE_AS_OBJECT
)
36 swfdec_transform_as_class_init (SwfdecTransformAsClass
*klass
)
41 swfdec_transform_as_init (SwfdecTransformAs
*transform
)
46 SWFDEC_AS_NATIVE (1106, 101, swfdec_transform_as_get_matrix
)
48 swfdec_transform_as_get_matrix (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
49 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
51 SwfdecTransformAs
*transform
;
53 cairo_matrix_t
*matrix
;
56 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS
, &transform
, "");
57 if (transform
->target
== NULL
)
60 swfdec_movie_update (transform
->target
);
61 matrix
= &transform
->target
->matrix
;
62 o
= swfdec_as_object_new_empty (cx
);
63 swfdec_as_object_set_constructor_by_name (o
, SWFDEC_AS_STR_flash
,
64 SWFDEC_AS_STR_geom
, SWFDEC_AS_STR_Matrix
, NULL
);
66 SWFDEC_AS_VALUE_SET_NUMBER (&val
, matrix
->xx
);
67 swfdec_as_object_set_variable (o
, SWFDEC_AS_STR_a
, &val
);
68 SWFDEC_AS_VALUE_SET_NUMBER (&val
, matrix
->yx
);
69 swfdec_as_object_set_variable (o
, SWFDEC_AS_STR_b
, &val
);
70 SWFDEC_AS_VALUE_SET_NUMBER (&val
, matrix
->xy
);
71 swfdec_as_object_set_variable (o
, SWFDEC_AS_STR_c
, &val
);
72 SWFDEC_AS_VALUE_SET_NUMBER (&val
, matrix
->yy
);
73 swfdec_as_object_set_variable (o
, SWFDEC_AS_STR_d
, &val
);
74 SWFDEC_AS_VALUE_SET_NUMBER (&val
, matrix
->yy
);
75 swfdec_as_object_set_variable (o
, SWFDEC_AS_STR_d
, &val
);
76 SWFDEC_AS_VALUE_SET_NUMBER (&val
, SWFDEC_TWIPS_TO_DOUBLE (matrix
->x0
));
77 swfdec_as_object_set_variable (o
, SWFDEC_AS_STR_tx
, &val
);
78 SWFDEC_AS_VALUE_SET_NUMBER (&val
, SWFDEC_TWIPS_TO_DOUBLE (matrix
->y0
));
79 swfdec_as_object_set_variable (o
, SWFDEC_AS_STR_ty
, &val
);
81 SWFDEC_AS_VALUE_SET_OBJECT (ret
, o
);
84 SWFDEC_AS_NATIVE (1106, 102, swfdec_transform_as_set_matrix
)
86 swfdec_transform_as_set_matrix (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
87 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
90 SwfdecTransformAs
*transform
;
94 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS
, &transform
, "o", &o
);
95 if (transform
->target
== NULL
||
96 !swfdec_matrix_from_as_object (&tmp
, o
))
99 tmp
.x0
= SWFDEC_DOUBLE_TO_TWIPS (tmp
.x0
);
100 tmp
.y0
= SWFDEC_DOUBLE_TO_TWIPS (tmp
.y0
);
102 /* NB: We don't use begin/end_update_matrix() here, because Flash is
103 * broken enough to not want that. */
104 movie
= transform
->target
;
105 swfdec_movie_invalidate_next (movie
);
109 swfdec_movie_queue_update (movie
, SWFDEC_MOVIE_INVALID_EXTENTS
);
110 swfdec_matrix_ensure_invertible (&movie
->matrix
, &movie
->inverse_matrix
);
111 g_signal_emit_by_name (movie
, "matrix-changed");
114 SWFDEC_AS_NATIVE (1106, 103, swfdec_transform_as_get_concatenatedMatrix
)
116 swfdec_transform_as_get_concatenatedMatrix (SwfdecAsContext
*cx
,
117 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
120 SWFDEC_STUB ("Transform.concatenatedMatrix (get)");
123 SWFDEC_AS_NATIVE (1106, 104, swfdec_transform_as_set_concatenatedMatrix
)
125 swfdec_transform_as_set_concatenatedMatrix (SwfdecAsContext
*cx
,
126 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
129 SWFDEC_STUB ("Transform.concatenatedMatrix (set)");
132 SWFDEC_AS_NATIVE (1106, 105, swfdec_transform_as_get_colorTransform
)
134 swfdec_transform_as_get_colorTransform (SwfdecAsContext
*cx
,
135 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
138 SwfdecTransformAs
*transform
;
140 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS
, &transform
, "");
142 if (transform
->target
== NULL
)
145 SWFDEC_AS_VALUE_SET_OBJECT (ret
,
146 SWFDEC_AS_OBJECT (swfdec_color_transform_as_new_from_transform (cx
,
147 &transform
->target
->color_transform
)));
150 SWFDEC_AS_NATIVE (1106, 106, swfdec_transform_as_set_colorTransform
)
152 swfdec_transform_as_set_colorTransform (SwfdecAsContext
*cx
,
153 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
156 SwfdecTransformAs
*self
;
157 SwfdecColorTransformAs
*transform_as
;
158 SwfdecAsObject
*color
;
160 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS
, &self
, "o", &color
);
162 if (self
->target
== NULL
)
165 if (!SWFDEC_IS_COLOR_TRANSFORM_AS (color
))
168 transform_as
= SWFDEC_COLOR_TRANSFORM_AS (color
);
170 swfdec_color_transform_get_transform (transform_as
, &self
->target
->color_transform
);
173 SWFDEC_AS_NATIVE (1106, 107, swfdec_transform_as_get_concatenatedColorTransform
)
175 swfdec_transform_as_get_concatenatedColorTransform (SwfdecAsContext
*cx
,
176 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
179 SwfdecTransformAs
*self
;
180 SwfdecColorTransform chain
;
183 SWFDEC_AS_CHECK (SWFDEC_TYPE_TRANSFORM_AS
, &self
, "");
185 if (self
->target
== NULL
)
188 chain
= self
->target
->color_transform
;
190 for (movie
= self
->target
->parent
; movie
!= NULL
; movie
= movie
->parent
) {
191 swfdec_color_transform_chain (&chain
, &movie
->color_transform
, &chain
);
194 SWFDEC_AS_VALUE_SET_OBJECT (ret
, SWFDEC_AS_OBJECT (
195 swfdec_color_transform_as_new_from_transform (cx
, &chain
)));
198 SWFDEC_AS_NATIVE (1106, 108, swfdec_transform_as_set_concatenatedColorTransform
)
200 swfdec_transform_as_set_concatenatedColorTransform (SwfdecAsContext
*cx
,
201 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
207 SWFDEC_AS_NATIVE (1106, 109, swfdec_transform_as_get_pixelBounds
)
209 swfdec_transform_as_get_pixelBounds (SwfdecAsContext
*cx
,
210 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
213 SWFDEC_STUB ("Transform.pixelBounds (get)");
216 SWFDEC_AS_NATIVE (1106, 110, swfdec_transform_as_set_pixelBounds
)
218 swfdec_transform_as_set_pixelBounds (SwfdecAsContext
*cx
,
219 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
222 SWFDEC_STUB ("Transform.pixelBounds (set)");
226 SWFDEC_AS_CONSTRUCTOR (1106, 0, swfdec_transform_as_construct
, swfdec_transform_as_get_type
)
228 swfdec_transform_as_construct (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
229 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
231 if (!cx
->frame
->construct
)
235 !SWFDEC_AS_VALUE_IS_OBJECT (&argv
[0]) ||
236 !SWFDEC_IS_MOVIE (SWFDEC_AS_VALUE_GET_OBJECT (&argv
[0]))) {
237 SWFDEC_FIXME ("new Transform without movieclip should give undefined");
241 SWFDEC_TRANSFORM_AS (object
)->target
=
242 SWFDEC_MOVIE (SWFDEC_AS_VALUE_GET_OBJECT (&argv
[0]));
246 swfdec_transform_as_new (SwfdecAsContext
*context
, SwfdecMovie
*target
)
248 SwfdecTransformAs
*transform
;
250 g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context
), NULL
);
251 g_return_val_if_fail (SWFDEC_IS_MOVIE (target
), NULL
);
253 transform
= g_object_new (SWFDEC_TYPE_TRANSFORM_AS
, "context", context
, NULL
);
255 swfdec_as_object_set_constructor_by_name (SWFDEC_AS_OBJECT (transform
),
256 SWFDEC_AS_STR_flash
, SWFDEC_AS_STR_geom
, SWFDEC_AS_STR_Transform
, NULL
);
257 transform
->target
= target
;