2 // Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program 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
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 // Test case for Transform ActionScript class
20 // compile this test case with Ming makeswf, and then
21 // execute it like this gnash -1 -r 0 -v out.swf
27 ASSetPropFlags
(_global
, "flash", 0, 5248);
29 #if OUTPUT_VERSION
< 8
30 # if OUTPUT_VERSION
< 6
31 check_equals
(typeOf
(flash
.geom
.Transform), "undefined");
33 check_equals
(typeOf
(flash
.geom
.Transform), "function");
38 Transform = flash
.geom
.Transform;
39 Matrix = flash
.geom
.Matrix;
40 ColorTransform = flash
.geom
.ColorTransform;
41 Rectangle = flash
.geom
.Rectangle;
43 check
(Transform.prototype
.hasOwnProperty
("matrix"));
44 check
(Transform.prototype
.hasOwnProperty
("concatenatedMatrix"));
45 check
(Transform.prototype
.hasOwnProperty
("colorTransform"));
46 check
(Transform.prototype
.hasOwnProperty
("concatenatedColorTransform"));
47 check
(Transform.prototype
.hasOwnProperty
("pixelBounds"));
49 // Cannot be instantiated without MovieClip argument.
51 check_equals
(t
, undefined);
54 check_equals
(t
, undefined);
57 t
= new Transform(_root
);
58 check_equals
(typeOf
(t
), "object");
59 check
(t instanceOf
Transform);
62 check_equals
(typeOf
(t
), "object");
63 check
(t instanceOf
Transform);
65 check
(t
.matrix instanceOf
Matrix);
66 check
(t
.concatenatedMatrix instanceOf
Matrix);
67 check
(t
.colorTransform instanceOf
ColorTransform);
68 check
(t
.concatenatedColorTransform instanceOf
ColorTransform);
69 xcheck
(t
.pixelBounds instanceOf
Rectangle);
71 check_equals
(t
.matrix
.toString
(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
72 check_equals
(t
.colorTransform
.toString
(), "(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)");
73 check_equals
(t
.concatenatedColorTransform
.toString
(), "(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)");
74 // These vary slightly with the pp
75 //check_equals(t.concatenatedMatrix.toString(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
76 //check_equals(t.pixelBounds.toString(), "(x=-2, y=48, w=804, h=804)");
78 /// transform.colorTransform
80 mcx
= _root
.createEmptyMovieClip
("mcx", getNextHighestDepth
());
81 check_equals
(mcx
.transform
.colorTransform
.toString
(), "(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)");
84 check_equals
(mcx
.transform
.colorTransform
.toString
(), "(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=0.2265625, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)");
87 check_equals
(mcx
.transform
.colorTransform
.toString
(), "(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=-2.02734375, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)");
90 check_equals
(mcx
.transform
.colorTransform
.toString
(), "(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=-0.98828125, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)");
93 check_equals
(mcx
.transform
.colorTransform
.toString
(), "(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=-128, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)");
95 r
= new ColorTransform(2, 3, 4, 5, 5, -5, 5, -5);
96 mcx
.transform
.colorTransform
= r
;
97 check_equals
(mcx
.transform
.colorTransform
.toString
(), "(redMultiplier=2, greenMultiplier=3, blueMultiplier=4, alphaMultiplier=5, redOffset=5, greenOffset=-5, blueOffset=5, alphaOffset=-5)");
99 r
= new ColorTransform(0, 1, 1, 1, 0, 0, 255, 0);
100 mcx
.transform
.colorTransform
= r
;
101 check_equals
(mcx
.transform
.colorTransform
.toString
(), "(redMultiplier=0, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=255, alphaOffset=0)");
103 r
= new ColorTransform(5e-67, 2342341, 11234112, -287394874978, 1222222, 2342343434, 255, 4e+5);
104 mcx
.transform
.colorTransform
= r
;
105 check_equals
(mcx
.transform
.colorTransform
.toString
(), "(redMultiplier=0, greenMultiplier=-128, blueMultiplier=-128, alphaMultiplier=-128, redOffset=-32768, greenOffset=-32768, blueOffset=255, alphaOffset=-32768)");
108 // Tricks with the flash package:
109 flash
.geom
.Matrix = undefined;
110 check_equals
(t
.matrix
, undefined);
111 check_equals
(t
.colorTransform
.toString
(), "(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)");
112 flash
.geom
.ColorTransform = undefined;
113 check_equals
(t
.colorTransform
, undefined);
114 xcheck
(t
.pixelBounds instanceOf
Rectangle);
115 flash
.geom
.Rectangle = undefined;
116 check_equals
(t
.pixelBounds
, undefined);
119 flash
.geom
.Matrix = Matrix;
120 check_equals
(t
.matrix
.toString
(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
121 check_equals
(t
.colorTransform
, undefined);
122 flash
.geom
.ColorTransform = ColorTransform;
123 check_equals
(t
.colorTransform
.toString
(), "(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)");
124 flash
.geom
.Rectangle = Rectangle;
125 xcheck
(t
.pixelBounds instanceOf
Rectangle);
127 mc
= _root
.createEmptyMovieClip
("mc", getNextHighestDepth
());
128 check
(mc
.transform instanceOf
Transform);
129 check
(mc
.transform
.matrix instanceOf
Matrix);
130 check_equals
(mc
.transform
.matrix
.toString
(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
132 // Store Matrix (copy)
133 mat
= mc
.transform
.matrix
;
135 // Store Transform (reference)
136 trans
= mc
.transform
;
139 check_equals
(mc
.transform
.matrix
.toString
(), "(a=1, b=0, c=0, d=1, tx=4, ty=0)");
140 check_equals
(trans
.matrix
.toString
(), "(a=1, b=0, c=0, d=1, tx=4, ty=0)");
141 check_equals
(mat
.toString
(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
145 check_equals
(mc
.transform
.matrix
.toString
(), trans
.matrix
.toString
());
146 check_equals
(Math.round
(trans
.matrix
.b
* 10000), 262);
147 check_equals
(mat
.toString
(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
152 check_equals
(mc
.transform
.matrix
.toString
(), trans
.matrix
.toString
());
153 check_equals
(Math.round
(trans
.matrix
.a
* 1000), 1000);
154 check_equals
(mat
.toString
(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
157 _root
.removeMovieClip
(mc
);
158 check_equals
(Math.round
(mc
.transform
.matrix
.b
* 10000), 262);
162 check_equals
(Math.round
(mc2
.transform
.matrix
.b
* 10000), 262);
163 check_equals
(mc
.transform
.matrix
.toString
(), undefined);
164 check_equals
(mc2
.transform
.matrix
.toString
(), trans
.matrix
.toString
());
165 check_equals
(mat
.toString
(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
167 check_equals
(mc2
._xscale
, 100);
168 check_equals
(mc2
._yscale
, 100);
169 check_equals
(mc2
._rotation
, 1.5);
170 trans
.matrix
= new Matrix(2, 0, 0, 2, 10, 11);
172 check_equals
(trans
.matrix
.toString
(), "(a=2, b=0, c=0, d=2, tx=10, ty=11)");
173 check_equals
(mc2
.transform
.matrix
.toString
(), "(a=2, b=0, c=0, d=2, tx=10, ty=11)");
175 check_equals
(mc2
._xscale
, 100);
176 check_equals
(mc2
._yscale
, 100);
177 check_equals
(mc2
._rotation
, 1.5);
181 check_equals
(mc2
.transform
.matrix
.toString
(), undefined);
182 check_equals
(trans
.matrix
.toString
(), "(a=2, b=0, c=0, d=2, tx=10, ty=11)");
183 check_equals
(mat
.toString
(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
187 check_equals
(trans
.matrix
.toString
(), "(a=2, b=0, c=0, d=2, tx=10, ty=11)");
190 trans
.matrix
= new Matrix;
191 check_equals
(trans
.matrix
.toString
(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
194 mc
= _root
.createEmptyMovieClip
("mc", getNextHighestDepth
());
195 trans
= mc
.transform
;
198 trans
.matrix
= new Matrix(3, 0.5, 0.5, 2, 0, 1);
199 check_equals
(mc
.transform
.matrix
.toString
(), "(a=3, b=0.5, c=0.5, d=2, tx=0, ty=1)");
200 check_equals
(mcOld
.transform
.matrix
.toString
(), "(a=3, b=0.5, c=0.5, d=2, tx=0, ty=1)");
204 mc
= _root
.createEmptyMovieClip
("mc", getNextHighestDepth
());
206 trans
.matrix
= new Matrix(4, 0.3, 0.3, 1, 1, 0);
207 check_equals
(mc
.transform
.matrix
.toString
(), "(a=1, b=0, c=0, d=1, tx=0, ty=0)");
209 // Can we be this accurate? I think the AS matrix class is accurate enough.
210 xcheck_equals
(mcOld
.transform
.matrix
.toString
(), "(a=4, b=0.300000011920929, c=0.300000011920929, d=1, tx=1, ty=0)");
213 // Concatenated transform. Does this make any sense?
215 // The following group of tests was updated on 2010-08-10 to match
216 // FP 9,0,0,115 results (Linux)
218 near
= function(a
, b
) {
219 return Math.abs
(a
- b
) < 0.01;
222 nearly_equal
= function(m
, a
, b
, c
, d
, tx
, ty
) {
223 return near
(m
.a
, a
) && near
(m
.b
, b
) &&
224 near
(m
.c
, c
) && near
(m
.d
, d
) &&
225 near
(m
.tx
, tx
) && near
(m
.ty
, ty
);
228 conc1
= _root
.createEmptyMovieClip
("conc1", getNextHighestDepth
());
229 conc2
= conc1
.createEmptyMovieClip
("conc2", getNextHighestDepth
());
234 xcheck
(nearly_equal
(conc1
.transform
.concatenatedMatrix
, 1, 0, 0, 1, 39.75, 2));
235 xcheck
(nearly_equal
(conc2
.transform
.concatenatedMatrix
, 1, 0, 0, 1, 63.5, 2));
238 xcheck
(nearly_equal
(conc1
.transform
.concatenatedMatrix
, 0, 0, 0, 0, 39.75, 2));
239 xcheck
(nearly_equal
(conc1
.transform
.concatenatedMatrix
, 0, 0, 0, 0, 39.75, 2));
241 d
= _root
.createEmptyMovieClip
("tar", 600);
242 d
.beginFill
(0x00ff00);
250 d
.beginFill
(0xff0000);
256 ct8
= d
.transform
.colorTransform
;
258 check_equals
(ct8
.toString
(), "(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)")
263 btx
= c
.getTransform
();
264 check_equals
(btx
.ra
, 0);
265 check_equals
(btx
.ba
, 0);
266 check_equals
(btx
.ga
, 0);
267 check_equals
(btx
.aa
, 100);
268 check_equals
(btx
.rb
, 255);
269 check_equals
(btx
.gb
, 0);
270 check_equals
(btx
.bb
, 0);
271 check_equals
(btx
.ab
, 0);
273 ct9
= d
.transform
.colorTransform
;
274 check_equals
(ct9
.toString
(), "(redMultiplier=0, greenMultiplier=0, blueMultiplier=0, alphaMultiplier=1, redOffset=255, greenOffset=0, blueOffset=0, alphaOffset=0)")
277 ct10
= d
.transform
.colorTransform
;
278 check_equals
(ct10
.toString
(), "(redMultiplier=0, greenMultiplier=0, blueMultiplier=0, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=255, alphaOffset=0)")
281 tr
.colorTransform
= new ColorTransform(0, 0, 0, 1, 0, 127, 0, 0);
283 ct11
= d
.transform
.colorTransform
;
284 check_equals
(ct11
.toString
(), "(redMultiplier=0, greenMultiplier=0, blueMultiplier=0, alphaMultiplier=1, redOffset=0, greenOffset=127, blueOffset=0, alphaOffset=0)");
287 btx
= c
.getTransform
();
288 check_equals
(btx
.ra
, 0);
289 check_equals
(btx
.ba
, 0);
290 check_equals
(btx
.ga
, 0);
291 check_equals
(btx
.aa
, 100);
292 check_equals
(btx
.rb
, 0);
293 check_equals
(btx
.gb
, 127);
294 check_equals
(btx
.bb
, 0);
295 check_equals
(btx
.ab
, 0);
297 // A fake color transform doesn't work.
299 ct
.redMultiplier
= 1;
300 ct
.blueMultiplier
= 1;
301 ct
.greenMultiplier
= 1;
302 ct
.alphaMultiplier
= 1;
305 ct
.greenOffset
= 255;
309 tr
.colorTransform
= ct
;
312 ctfake
= d
.transform
.colorTransform
;
313 check_equals
(ct11
.toString
(), "(redMultiplier=0, greenMultiplier=0, blueMultiplier=0, alphaMultiplier=1, redOffset=0, greenOffset=127, blueOffset=0, alphaOffset=0)");