2 // Some tests for the Drawing API
4 // makeswf -o DrawingApi.swf DrawingApi.as
6 // firefox DrawingApi.swf
8 // gnash DrawingApi.swf
11 // Click the mouse button to turn the cursor shape into a mask and back.
12 // Press a number on the keyboard to switch between "pages" of the drawing.
13 // We currently have pages 1, 2, 3, 4.
14 // All pages are tested automatically.
16 // '-' and '+' decrement and increment _alpha
17 // 'h' toggles _visible
21 #include "../actionscript.all/check.as"
23 // This tests the gradients found in DrawingApiTest for version 8, where
24 // some extra arguments were added.
26 // Make Matrix visible for easier gradient tests.
27 ASSetPropFlags
(_global
, "flash", 0, 5248);
29 draw100x100Box
= function(x
, y
, mc
) {
41 createEmptyMovieClip
("grad", 150);
44 // The beginGradientFill function works with fake Matrices, but there is no
45 // point making more work for ourselves as that testing is already done for
47 // Only the "box" matrixType gets special handling.
58 colors
= [0x0000ff, 0xffffff];
61 matrix
= new flash
.geom
.Matrix();
62 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
63 draw100x100Box
(x
, y
, grad
);
67 colors
= [0x0000ff, 0xffffff];
70 matrix
.createGradientBox
(90, 90, 0, x
, y
);
71 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
72 draw100x100Box
(x
, y
, grad
);
76 colors
= [0x0000ff, 0xffffff, 0xff00ff];
77 alphas
= [100, 100, 100];
78 ratios
= [0, 0xff / 2, 0xff];
79 matrix
.createGradientBox
(90, 90, Math.PI
/ 4, x
, y
);
80 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
81 draw100x100Box
(x
, y
, grad
);
85 colors
= [0x0000ff, 0xffffff, 0xff00ff];
86 alphas
= [100, 100, 100];
87 ratios
= [0, 0xff / 2, 0xff];
88 matrix
.createGradientBox
(180, 180, Math.PI
/ 4, x
, y
);
89 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
90 draw100x100Box
(x
, y
, grad
);
94 colors
= [0x0000ff, 0xffffff, 0x00ff00];
95 alphas
= [100, 100, 100];
96 ratios
= [0, 0xff / 2, 0xff];
97 matrix
.createGradientBox
(180, 180, Math.PI
/ 4 * 3, x
- 90, y
- 90);
98 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
99 draw100x100Box
(x
, y
, grad
);
103 colors
= [0x0000ff, 0xffffff, 0x00ff00, 0xff00ff, 0x00ffff, 0xffff00 ];
104 alphas
= [100, 100, 100, 50, 25, 100];
105 ratios
= [0, 0xff / 5, 0xff / 5 * 2, 0xff / 5 * 3, 0xff / 5 * 4, 0xff];
106 matrix
.createGradientBox
(90, 90, Math.PI
/ 2, x
, y
);
107 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
108 draw100x100Box
(x
, y
, grad
);
117 colors
= [0x0000ff, 0xffffff];
120 matrix
= new flash
.geom
.Matrix();
121 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
122 draw100x100Box
(x
, y
, grad
);
126 colors
= [0x0000ff, 0xffffff];
129 matrix
.createGradientBox
(90, 90, 0, x
, y
);
130 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
131 draw100x100Box
(x
, y
, grad
);
135 colors
= [0x0000ff, 0xffffff, 0xff00ff];
136 alphas
= [100, 100, 100];
137 ratios
= [0, 0xff / 2, 0xff];
138 matrix
.createGradientBox
(90, 90, Math.PI
/ 4, x
, y
);
139 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
140 draw100x100Box
(x
, y
, grad
);
144 colors
= [0x0000ff, 0xffffff, 0xff00ff];
145 alphas
= [100, 100, 100];
146 ratios
= [0, 0xff / 2, 0xff];
147 matrix
.createGradientBox
(180, 180, Math.PI
/ 4, x
, y
);
148 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
149 draw100x100Box
(x
, y
, grad
);
153 colors
= [0x0000ff, 0xffffff, 0x00ff00];
154 alphas
= [100, 100, 100];
155 ratios
= [0, 0xff / 2, 0xff];
156 matrix
.createGradientBox
(180, 180, Math.PI
/ 4 * 3, x
- 90, y
- 90);
157 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
158 draw100x100Box
(x
, y
, grad
);
162 colors
= [0x0000ff, 0xffffff, 0x00ff00, 0xff00ff, 0x00ffff, 0xffff00 ];
163 alphas
= [100, 100, 100, 50, 25, 100];
164 ratios
= [0, 0xff / 5, 0xff / 5 * 2, 0xff / 5 * 3, 0xff / 5 * 4, 0xff];
165 matrix
.createGradientBox
(90, 90, Math.PI
/ 2, x
, y
);
166 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
167 draw100x100Box
(x
, y
, grad
);
174 // Check that ratios are adjusted if they do not get successively larger.
176 colors
= [0x0000ff, 0xffffff, 0x00ff00];
177 alphas
= [100, 100, 100];
178 ratios
= [0, 0x10, 0x05];
179 matrix
.createGradientBox
(90, 90, 0, x
, y
);
180 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
181 draw100x100Box
(x
, y
, grad
);
187 // Test a linear gradient with one stop
192 matrix
.createGradientBox
(90, 90, 0, x
, y
);
193 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
194 draw100x100Box
(x
, y
, grad
);
200 // Test a linear gradient with one stop
205 matrix
.createGradientBox
(90, 90, 0, x
, y
);
206 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
);
207 draw100x100Box
(x
, y
, grad
);
212 // Test a radial gradient with SWF8 args
214 colors
= [0xffff00, 0x0000ff, 0x00ffff];
215 alphas
= [100, 100, 100];
216 ratios
= [0, 0xa0, 0xff];
217 matrix
.createGradientBox
(90, 90, 0, x
, y
);
218 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
, "pad");
219 draw100x100Box
(x
, y
, grad
);
224 // Test a radial gradient with SWF8 args
226 colors
= [0xffff00, 0x0000ff, 0x00ffff];
227 alphas
= [100, 100, 100];
228 ratios
= [0, 0xa0, 0xff];
229 matrix
.createGradientBox
(90, 90, 0, x
, y
);
230 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
, "reflect");
231 draw100x100Box
(x
, y
, grad
);
236 // Test a radial gradient with SWF8 args
238 colors
= [0xffff00, 0x0000ff, 0x00ffff];
239 alphas
= [100, 100, 100];
240 ratios
= [0, 0xa0, 0xff];
241 matrix
.createGradientBox
(90, 90, 0, x
, y
);
242 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
, "repeat");
243 draw100x100Box
(x
, y
, grad
);
250 // Test a radial gradient with SWF8 args
252 colors
= [0xffff00, 0x0000ff, 0x00ffff];
253 alphas
= [100, 100, 100];
254 ratios
= [0, 0xa0, 0xff];
255 matrix
.createGradientBox
(90, 90, 0, x
, y
);
256 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
, "");
257 draw100x100Box
(x
, y
, grad
);
262 // Test a radial gradient with SWF8 args
264 colors
= [0xffff00, 0x0000ff, 0x00ffff];
265 alphas
= [100, 100, 100];
266 ratios
= [0, 0xa0, 0xff];
267 matrix
.createGradientBox
(90, 90, 0, x
, y
);
268 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
, "pad",
270 draw100x100Box
(x
, y
, grad
);
276 // Test a radial gradient with SWF8 args
278 colors
= [0xffff00, 0x0000ff, 0x00ffff];
279 alphas
= [100, 100, 100];
280 ratios
= [0, 0xa0, 0xff];
281 matrix
.createGradientBox
(90, 90, 0, x
, y
);
282 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
, "pad",
284 draw100x100Box
(x
, y
, grad
);
289 // Test a radial gradient with SWF8 args
291 colors
= [0xffff00, 0x0000ff, 0x00ffff];
292 alphas
= [100, 100, 100];
293 ratios
= [0, 0xa0, 0xff];
294 matrix
.createGradientBox
(90, 90, 0, x
, y
);
295 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
, "pad",
297 draw100x100Box
(x
, y
, grad
);
303 colors
= [0xffff00, 0x0000ff, 0x00ffff];
304 alphas
= [100, 100, 100];
305 ratios
= [0, 0xa0, 0xff];
306 matrix
.createGradientBox
(90, 90, 0, x
, y
);
307 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
, "pad",
309 draw100x100Box
(x
, y
, grad
);
315 colors
= [0xff0000, 0x00ff00];
318 matrix
.createGradientBox
(90, 90, 0, x
, y
);
319 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
, "pad",
321 draw100x100Box
(x
, y
, grad
);
328 colors
= [0xff0000, 0x00ff00];
331 matrix
.createGradientBox
(90, 90, 0, x
, y
);
332 beginGradientFill
(fillType
, colors
, alphas
, ratios
, matrix
, "pad",
334 draw100x100Box
(x
, y
, grad
);
337 grad
.onRollOver
= function() {};
339 testbmp
= new flash
.display
.BitmapData(1000, 1000, false);
342 searchArray
= function(ar
, el
) {
344 if (ar
[i
] == el
) return true;
349 nearColor
= function(a
, b
, exfail
) {
351 ra
= (a
& 0xff0000) >> 16;
352 ba
= (a
& 0xff00) >> 8;
354 rb
= (b
& 0xff0000) >> 16;
355 bb
= (b
& 0xff00) >> 8;
357 dist
= Math.sqrt
(Math.pow
(ra
- rb
, 2) + Math.pow
(ba
- bb
, 2) + Math.pow
(ga
- gb
, 2));
358 if (dist
> tolerance
) {
359 str
= "Expected: 0x" + b
.toString
(16) + ", got: 0x" + a
.toString
(16);
360 str
+= " (Allowed tolerance: " + tolerance
+ ", distance: " + dist
+ ")";
361 if (exfail
) xfail_check
(str
);
362 else fail_check
(str
);
365 str
= "0x" + b
.toString
(16) + " is near to 0x" + a
.toString
(16);
366 if (exfail
) xpass_check
(str
);
367 else pass_check
(str
);
381 // Passes is an optional array of the index of the tests that
383 checkSquare
= function(x
, y
, ar
, bmp
, fails
) {
384 trace
("Checking square at " + x
+ "x" + y
);
391 "0x" + testbmp
.getPixel
(x
+ low
, y
+ low
).toString
(16),
392 "0x" + testbmp
.getPixel
(x
+ low
, y
+ mid
).toString
(16),
393 "0x" + testbmp
.getPixel
(x
+ low
, y
+ high
).toString
(16),
394 "0x" + testbmp
.getPixel
(x
+ mid
, y
+ low
).toString
(16),
395 "0x" + testbmp
.getPixel
(x
+ mid
, y
+ mid
).toString
(16),
396 "0x" + testbmp
.getPixel
(x
+ mid
, y
+ high
).toString
(16),
397 "0x" + testbmp
.getPixel
(x
+ high
, y
+ low
).toString
(16),
398 "0x" + testbmp
.getPixel
(x
+ high
, y
+ mid
).toString
(16),
399 "0x" + testbmp
.getPixel
(x
+ high
, y
+ high
).toString
(16)
403 nearColor
(testbmp
.getPixel
(x
+ low
, y
+ low
), ar
[0], searchArray
(fails
, 0));
404 nearColor
(testbmp
.getPixel
(x
+ low
, y
+ mid
), ar
[1], searchArray
(fails
, 1));
405 nearColor
(testbmp
.getPixel
(x
+ low
, y
+ high
), ar
[2], searchArray
(fails
, 2));
406 nearColor
(testbmp
.getPixel
(x
+ mid
, y
+ low
), ar
[3], searchArray
(fails
, 3));
407 nearColor
(testbmp
.getPixel
(x
+ mid
, y
+ mid
), ar
[4], searchArray
(fails
, 4));
408 nearColor
(testbmp
.getPixel
(x
+ mid
, y
+ high
), ar
[5], searchArray
(fails
, 5));
409 nearColor
(testbmp
.getPixel
(x
+ high
, y
+ low
), ar
[6], searchArray
(fails
, 6));
410 nearColor
(testbmp
.getPixel
(x
+ high
, y
+ mid
), ar
[7], searchArray
(fails
, 7));
411 nearColor
(testbmp
.getPixel
(x
+ high
, y
+ high
), ar
[8], searchArray
(fails
, 8));
414 checkSquare
(0, 0, [0x8080ff,0x8080ff,0x8080ff,0x8787ff,0x8787ff,0x8787ff,0x8d8dff,0x8d8dff,0x8d8dff], bmp
);
415 checkSquare
(100, 0, [0xb0bff,0xb0bff,0xb0bff,0x7f7fff,0x7f7fff,0x7f7fff,0xf4f4ff,0xf4f4ff,0xf4f4ff], bmp
);
416 checkSquare
(200, 0, [0xff,0x5a5aff,0xfffdff,0x5a5aff,0xffffff,0xff59ff,0xffffff,0xff59ff,0xff00ff], bmp
);
417 checkSquare
(300, 0, [0xff,0xff,0x4a4aff,0xff,0x4a4aff,0x9c9cff,0x4a4aff,0x9c9cff,0xeeeeff], bmp
);
418 checkSquare
(400, 0, [0xffffff,0xabffab,0x59ff59,0xacacff,0xffffff,0xabffab,0x5a5aff,0xacacff,0xffffff], bmp
);
419 checkSquare
(500, 0, [0x3737ff,0xa29ea2,0xd1ff57,0x3737ff,0xa29ea2,0xd1ff57,0x3737ff,0xa29ea2,0xd1ff57], bmp
);
421 checkSquare
(0, 100, [0x2020ff,0x2d2dff,0x3a3aff,0x2323ff,0x2f2fff,0x3b3bff,0x2a2aff,0x3434ff,0x4040ff], bmp
);
422 checkSquare
(100, 100, [0xffffff,0xe9e9ff,0xffffff,0xe9e9ff,0xff,0xe9e9ff,0xffffff,0xe9e9ff,0xffffff], bmp
);
423 checkSquare
(200, 100, [0xff00ff,0xff2bff,0xff00ff,0xff2bff,0xff,0xff2bff,0xff00ff,0xff2bff,0xff00ff], bmp
);
424 checkSquare
(300, 100, [0xff00ff,0xff00ff,0xff15ff,0xff00ff,0xff93ff,0xfffdff,0xff15ff,0xfffdff,0x2020ff], bmp
);
425 checkSquare
(400, 100, [0x2020ff,0xfdfffd,0x15ff15,0xfdfffd,0x93ff93,0xff00,0x15ff15,0xff00,0xff00], bmp
);
426 checkSquare
(500, 100, [0xffff00,0xb4ff9d,0xffff00,0xb4ff9d,0xff,0xb4ff9d,0xffff00,0xb4ff9d,0xffff00], bmp
);
428 checkSquare
(0, 200, [0xafafff,0xafafff,0xafafff,0xff00,0xff00,0xff00,0xff00,0xff00,0xff00], bmp
);
429 checkSquare
(100, 200, [0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000], bmp
);
430 checkSquare
(200, 200, [0xff00,0xff00,0xff00,0xff00,0xff00,0xff00,0xff00,0xff00,0xff00], bmp
);
431 checkSquare
(300, 200, [0xffff,0xc3ff,0xffff,0xc3ff,0xffff00,0xc3ff,0xffff,0xc3ff,0xffff], bmp
);
432 checkSquare
(400, 200, [0x55ff,0xa9ff,0x43ff,0xb6ff,0xeded11,0xd1ff,0x30ff,0xdeff,0x1dff], bmp
);
433 checkSquare
(500, 200, [0x9d9d61,0xa3ff,0x91916d,0xb6ff,0xeaea14,0xd1ff,0x82827c,0xe4ff,0x757589], bmp
, [7]);
435 checkSquare
(0, 300, [0xffff,0xc3ff,0xffff,0xc3ff,0xffff00,0xc3ff,0xffff,0xc3ff,0xffff], bmp
);
436 checkSquare
(100, 300, [0xffff,0xc3ff,0xffff,0xc3ff,0xffff00,0xc3ff,0xffff,0xc3ff,0xffff], bmp
);
437 checkSquare
(200, 300, [0xfefe,0xe2fe,0xfefe,0xe2fe,0xfefe00,0xe2fe,0xfefe,0xe2fe,0xfefe], bmp
, [4]);
438 checkSquare
(300, 300, [0xffff,0xc3ff,0xffff,0xc3ff,0xffff00,0xc3ff,0xffff,0xc3ff,0xffff], bmp
);
439 checkSquare
(400, 300, [0xffff,0xe1ff,0xffff,0xc6ff,0x3636c8,0xc6ff,0xffff,0xf2f20c,0xffff], bmp
);
440 checkSquare
(500, 300, [0xfa3a00,0xfa3a00,0xfa3a00,0xbbbb00,0xbbbb00,0xbbbb00,0x3afa00,0x3afa00,0x3afa00], bmp
);
442 checkSquare
(0, 400, [0xfa420b,0xfa420b,0xfa420b,0xdddd7f,0xdddd7f,0xdddd7f,0xf6fff4,0xf6fff4,0xf6fff4], bmp
);