Update with current status
[gnash.git] / testsuite / misc-ming.all / DrawingApiTest.as
blobb52211260550fa40e5cdd017fb8a8e9a88ddd5e6
1 //
2 // Some tests for the Drawing API
3 // Build with:
4 // makeswf -o DrawingApi.swf DrawingApi.as
5 // Run with:
6 // firefox DrawingApi.swf
7 // Or:
8 // gnash DrawingApi.swf
9 //
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 // Make Matrix visible for easier gradient tests.
24 ASSetPropFlags(_global, "flash", 0, 5248);
26 printBounds = function(b)
28 return ''+Math.round(b.xMin*100)/100+','+Math.round(b.yMin*100)/100+' '+Math.round(b.xMax*100)/100+','+Math.round(b.yMax*100)/100;
31 // Can draw both on a dynamically-created movie...
32 createEmptyMovieClip("a", 10);
33 // ... or on a statically-created one
34 //a = _root;
36 red = new Object();
37 red.valueOf = function() { return 0xFF0000; };
39 thick = new Object();
40 thick.valueOf = function() { return 20; };
42 halftransparent = new Object();
43 halftransparent.valueOf = function() { return 50; };
45 // Draw a circle with given center and radius
46 // Uses 8 curves to approximate the circle
47 drawCircle = function (where, x, y, rad)
49 var ctl = Math.sin(24*Math.PI/180)*rad;
50 var cos = Math.cos(45*Math.PI/180)*rad;
51 var sin = Math.sin(45*Math.PI/180)*rad;
53 with (where)
55 moveTo(x, y-rad);
56 curveTo(x+ctl, y-rad, x+cos, y-sin);
57 curveTo(x+rad, y-ctl, x+rad, y);
58 curveTo(x+rad, y+ctl, x+cos, y+sin);
59 curveTo(x+ctl, y+rad, x, y+rad);
60 curveTo(x-ctl, y+rad, x-cos, y+sin);
61 curveTo(x-rad, y+ctl, x-rad, y);
62 curveTo(x-rad, y-ctl, x-cos, y-sin);
63 curveTo(x-ctl, y-rad, x, y-rad);
68 with (a)
70 clear();
72 bnd = printBounds(a.getBounds());
73 if ( bnd == "6710886.35,6710886.35 6710886.35,6710886.35" ) {
74 trace("PASSED: getBounds() returns "+bnd+" after clear");
75 } else {
76 trace("FAILED: getBounds() returns "+bnd+" after clear");
79 // The thick red line
80 lineStyle(thick, red, 100);
81 moveTo(100, 100);
83 bnd = printBounds(a.getBounds());
84 check_equals(bnd, "6710886.35,6710886.35 6710886.35,6710886.35");
86 lineTo(200, 200);
88 bnd = printBounds(a.getBounds());
89 check_equals(bnd, "80,80 220,220"); // line is 20 pixels thick..
91 // The hairlined horizontal black line
92 lineStyle(0, 0x000000, 100);
93 moveTo(220, 180);
95 bnd = printBounds(a.getBounds());
96 check_equals(bnd, "80,80 220,220"); // neither line style change nore moveTo change the bounds
98 lineTo(280, 180);
100 bnd = printBounds(a.getBounds());
101 check_equals(bnd, "80,80 280,220"); // now hairlined line from 220,180 to 280,180 was added
103 // The violet line
104 moveTo(100, 200);
105 lineStyle(5, 0xFF00FF, halftransparent);
107 bnd = printBounds(a.getBounds());
108 check_equals(bnd, "80,80 280,220"); // line style change and moveTo don't change anything
110 lineTo(200, 250);
112 bnd = printBounds(a.getBounds());
113 check_equals(bnd, "80,80 280,255"); // line thinkness is now 5, so 250 gets to 255
115 // The yellow line
116 lineStyle(10, 0xFFFF00, 100);
117 lineTo(400, 200);
119 bnd = printBounds(a.getBounds());
120 check_equals(bnd, "80,80 410,260"); // line thinkness of 10 adds to x (now 410) and to starting point y (was 250)
122 // The green curve
123 lineStyle(8, 0x00FF00, 100);
124 curveTo(400, 120, 300, 100);
125 check( ! hitTest(376, 180, true) );
126 check( hitTest(376, 139, true) );
128 bnd = printBounds(a.getBounds());
129 check_equals(bnd, "80,80 410,260"); // the curve is all inside the current bounds
131 // Transparent line
132 lineStyle();
133 lineTo(80, 100);
135 // The black thick vertical line
136 lineStyle(20);
137 lineTo(80, 150);
139 bnd = printBounds(a.getBounds());
140 check_equals(bnd, "60,80 410,260"); // new thinkness of 20 moves our left margin
142 // The ugly blue-fill red-stroke thingy
143 moveTo(80, 180);
144 lineStyle(2, 0xFF0000);
145 beginFill(0x0000FF, 100);
146 lineTo(50, 180);
148 bnd = printBounds(a.getBounds());
149 check_equals(bnd, "48,80 410,260"); // we get left to 50-thickness(2) now
151 curveTo(20, 200, 50, 250);
153 bnd = printBounds(a.getBounds());
154 check_equals(bnd, "18,80 410,260"); // we get left to 20-thickness(2) now
156 lineTo(100, 250);
157 lineTo(80, 180);
158 endFill();
159 lineTo(50, 150);
161 // The clockwise blue-stroke, cyan-fill square
162 moveTo(200, 100);
163 lineStyle(1, 0x00FF00);
164 beginFill(0x00FFFF, 100);
165 lineTo(200, 120);
166 lineTo(180, 120);
167 lineTo(180, 100);
168 lineTo(200, 100);
169 endFill();
171 bnd = printBounds(a.getBounds());
172 check_equals(bnd, "18,80 410,260"); // nothing new..
174 // The counter-clockwise cyan-stroke, green-fill (alpha 50) square
175 moveTo(230, 100);
176 lineStyle(1, 0x00FFFF);
177 beginFill(0x00FF00, 50);
178 lineTo(210, 100);
179 lineTo(210, 120);
180 lineTo(230, 120);
181 lineTo(230, 100);
182 endFill();
184 // The clockwise green-stroke, violet-fill square, with move after beginFill
185 lineStyle(1, 0x00FF00);
186 beginFill(0xFF00FF, 100);
187 moveTo(260, 100);
188 lineTo(260, 120);
189 lineTo(240, 120);
190 lineTo(240, 100);
191 lineTo(260, 100);
192 endFill();
194 // The green circle
195 lineStyle(8, 0x000000);
196 beginFill(0x00FF00, 100);
197 drawCircle(a, 330, 160, 35);
198 endFill();
200 bnd = printBounds(a.getBounds());
201 check_equals(bnd, "18,80 410,260"); // nothing new..
203 createEmptyMovieClip("zshape", 1);
204 with (zshape)
206 // The Z-shaped 3 edges stroke
209 // 0-----1--+
210 // |
211 // 2
212 // |
213 // |
214 // +--3----4
216 lineStyle(4, 0);
217 x = 223; y=145;
218 moveTo(x, y);
219 lineTo(x+20, y+0);
220 lineTo(x+20, y+20);
221 lineTo(x+50, y+20);
223 bnd = printBounds(zshape.getBounds());
224 check_equals(bnd, "219,141 277,169");
225 // "223,145 273,165" + 4 for thickness
226 check_equals( typeof(zshape.hitTest), 'function' );
227 check( zshape.hitTest(223, 145, true) ); // 0
228 check( zshape.hitTest((223+10), (145+0), true) ); // 1
229 check( zshape.hitTest((223+20), (145+5), true) ); // 2
230 check( zshape.hitTest((223+25), (145+20), true) ); // 3
231 check( zshape.hitTest(273, 165, true) ); // 4
233 // The ugly orange stroke / light brown fill
234 // expected to auto-close on endFill()
235 createEmptyMovieClip("x", 20);
236 with (x)
238 lineStyle(6, 0xFF8800);
239 beginFill(0x888800, 100);
240 moveTo(100, 100);
241 //lineTo("string", NaN); // equivalent to 0, 0
242 lineTo(0, 0);
243 //curveTo(100, "string", Object, 100); // equivalent to 100, 0, 0, 100
244 curveTo(100, 0, 0 ,100);
245 //moteTo(undefined, 0); // equivalent to 0, 0
246 //moveTo(0,0); ???
247 //lineTo(100, null); // equivalent to 100, 0
248 lineTo(100, 0);
249 endFill();
251 x._x = 100;
252 x._y = 150;
253 x._xscale = 30;
254 x._yscale = 30;
256 check( x.hitTest(126, 168, true) );
257 check( x.hitTest(112, 158, true) );
259 // COMPATIBLITY NOTE:
260 // flashplayer 10.0.12.10 for linux fails this, whereas 9.0.115.0 doesn't
261 check( x.hitTest(122, 157, true) );
263 check( ! x.hitTest(120, 155, true) );
264 check( x.hitTest(120, 155, false) );
265 check( ! x.hitTest(116, 177, true) );
266 check( x.hitTest(116, 177, false) );
269 // Make the MovieClip "active" (grabbing mouse events)
270 // This allows testing of fill styles and "thick" lines
271 a.onRollOver = function() {};
273 frameno = 0;
274 a.createEmptyMovieClip("b", 2);
275 a.onEnterFrame = function()
277 if ( ++frameno > 8 )
279 //this.clear();
280 frameno = 0;
281 ret = delete this.onEnterFrame;
282 if ( ret ) {
283 trace("PASSED: delete this.onEnterFrame returned "+ret);
284 } else {
285 trace("FAILED: delete this.onEnterFrame returned "+ret);
288 else
290 // #40315: test that we don't crash without a line style.
291 this.b.lineTo(10, 20);
293 this.b.clear();
294 this.b.lineStyle(2, 0xFF0000);
295 this.b.beginFill(0xFFFF00, 100);
296 drawCircle(this.b, (50*frameno), 280, 10);
297 this.b.endFill();
301 //---------------------------------------------------------------------------
302 // Some invalid shapes, get there hitting the right-arrow
303 //---------------------------------------------------------------------------
305 createEmptyMovieClip("inv", 100);
306 with(inv)
308 // Crossing edge
309 createEmptyMovieClip("inv1", 1);
310 with (inv1)
312 moveTo(10, 10);
313 beginFill(0xFF0000);
314 lineTo(20, 10);
315 lineTo(10, 20);
316 lineTo(20, 20);
317 endFill(); // should close to 10,10
319 inv1._xscale = inv1._yscale = 400;
320 inv1.onRollOver = function() {};
322 // Four intersecting edges (like in "four in a row")
323 createEmptyMovieClip("inv2", 2);
324 with (inv2)
326 lineStyle(0, 0); // hairline
327 beginFill(0x00FF00);
329 moveTo(10, 8);
330 lineTo(10, 20);
332 moveTo(8, 10);
333 lineTo(20, 10);
335 moveTo(18, 8);
336 lineTo(18, 20);
338 moveTo(8, 18);
339 lineTo(20, 18);
342 inv2._xscale = inv2._yscale = 400; inv2._x = 100;
343 inv2.onRollOver = function() {};
345 // Opposite el shapes
346 createEmptyMovieClip("inv3", 3);
347 with (inv3)
349 lineStyle(0, 0); // hairline
350 beginFill(0x00FF00);
352 moveTo(10, 8);
353 lineTo(10, 20);
354 lineTo(2, 20);
356 moveTo(18, 8);
357 lineTo(18, 20);
358 lineTo(26, 20);
361 inv3._xscale = inv3._yscale = 400; inv3._y = 100;
362 inv3.onRollOver = function() {};
364 check( inv3.hitTest((8*4), 100 + (18*4), true) ); // Inside the left autofill
365 check( !inv3.hitTest((4*4), 100 + (10*4), true) ); // Outside the left autofill (but in the boundaries)
366 check( inv3.hitTest((4*4), 100 + (10*4), false) ); // Outside the left autofill (but in the boundaries)
368 check( inv3.hitTest((20*4), 100 + (18*4), true) ); // Inside the right autofill
369 check( !inv3.hitTest((24*4), 100 + (10*4), true) ); // Outside the right autofill (but in the boundaries)
370 check( inv3.hitTest((24*4), 100 + (10*4), false) ); // Outside the right autofill (but in the boundaries)
372 // Nested squares (inner is an hole)
373 // Both squares are defined in counterclockwise order
374 createEmptyMovieClip("inv4", 4);
375 with (inv4)
377 lineStyle(0, 0); // hairline
378 beginFill(0x00FF00);
380 moveTo(10, 10);
381 lineTo(10, 20);
382 lineTo(20, 20);
383 lineTo(20, 10);
384 lineTo(10, 10);
386 moveTo(12, 12);
387 lineTo(12, 18);
388 lineTo(18, 18);
389 lineTo(18, 12);
390 lineTo(12, 12);
392 inv4._xscale = inv4._yscale = 400;
393 inv4._y = 100; inv4._x = 100;
394 inv4.onRollOver = function() {};
396 // check that a point inside the hole doesn't hit the shape
397 // (gnash fails due to bogus point_test, or missing normalization)
398 check( ! inv4.hitTest(100 + (15*4), 100 + (15*4), true) );
400 // while a points on the border do hit it
401 check( inv4.hitTest(100 + (11*4), 100 + (11*4), true) ); // Upper-Left
402 check( inv4.hitTest(100 + (11*4), 100 + (14*4), true) ); // Center-Left
403 check( inv4.hitTest(100 + (11*4), 100 + (19*4), true) ); // Lower-Left
404 check( inv4.hitTest(100 + (14*4), 100 + (19*4), true) ); // Lower-Center
405 check( inv4.hitTest(100 + (19*4), 100 + (19*4), true) ); // Lower-Right
406 check( inv4.hitTest(100 + (19*4), 100 + (14*4), true) ); // Center-Right
407 check( inv4.hitTest(100 + (19*4), 100 + (11*4), true) ); // Upper-Right
408 check( inv4.hitTest(100 + (14*4), 100 + (11*4), true) ); // Upper-Center
410 // Nested squares (inner is an hole)
411 // Outer square counterclockwise order, inner in closwise order
412 // NOTE that there's no difference with inv4 in rendering and hit test
413 createEmptyMovieClip("inv5", 5);
414 with (inv5)
416 lineStyle(0, 0); // hairline
417 beginFill(0x00FF00);
419 moveTo(10, 10);
420 lineTo(10, 20);
421 lineTo(20, 20);
422 lineTo(20, 10);
423 lineTo(10, 10);
425 moveTo(12, 12);
426 lineTo(18, 12);
427 lineTo(18, 18);
428 lineTo(12, 18);
429 lineTo(12, 12);
431 inv5._xscale = inv5._yscale = 400;
432 inv5._y = 100; inv5._x = 150;
433 inv5.onRollOver = function() {};
435 // check that a point inside the hole doesn't hit the shape
436 // (gnash fails due to bogus point_test, or missing normalization)
437 check( ! inv5.hitTest(150 + (15*4), 100 + (15*4), true) );
439 // while a points on the border do hit it
440 check( inv5.hitTest(150 + (11*4), 100 + (11*4), true) ); // Upper-Left
441 check( inv5.hitTest(150 + (11*4), 100 + (14*4), true) ); // Center-Left
442 check( inv5.hitTest(150 + (11*4), 100 + (19*4), true) ); // Lower-Left
443 check( inv5.hitTest(150 + (14*4), 100 + (19*4), true) ); // Lower-Center
444 check( inv5.hitTest(150 + (19*4), 100 + (19*4), true) ); // Lower-Right
445 check( inv5.hitTest(150 + (19*4), 100 + (14*4), true) ); // Center-Right
446 check( inv5.hitTest(150 + (19*4), 100 + (11*4), true) ); // Upper-Right
447 check( inv5.hitTest(150 + (14*4), 100 + (11*4), true) ); // Upper-Center
449 // Nested squares (this time we call beginFill again before the move)
450 // Outer square counterclockwise order, inner in clockwise order
451 // This time, the inner square will NOT be considered an hole !
452 createEmptyMovieClip("inv6", 6);
453 with (inv6)
455 lineStyle(0, 0); // hairline
456 beginFill(0x00FF00);
458 moveTo(10, 10);
459 lineTo(10, 20);
460 lineTo(20, 20);
461 lineTo(20, 10);
462 lineTo(10, 10);
464 // this forces endFill call, which triggers finalization of previous path (I think)
465 beginFill(0x00FF00);
467 moveTo(12, 12);
468 lineTo(18, 12);
469 lineTo(18, 18);
470 lineTo(12, 18);
471 lineTo(12, 12);
473 inv6._xscale = inv6._yscale = 400;
474 inv6._y = 100; inv6._x = 200;
475 inv6.onRollOver = function() {};
477 // Point inside the inner square hits the shape !
478 check( inv6.hitTest(200 + (15*4), 100 + (15*4), true) );
479 // As points on the outer borders
480 check( inv6.hitTest(200 + (11*4), 100 + (11*4), true) ); // Upper-Left
481 check( inv6.hitTest(200 + (11*4), 100 + (14*4), true) ); // Center-Left
482 check( inv6.hitTest(200 + (11*4), 100 + (19*4), true) ); // Lower-Left
483 check( inv6.hitTest(200 + (14*4), 100 + (19*4), true) ); // Lower-Center
484 check( inv6.hitTest(200 + (19*4), 100 + (19*4), true) ); // Lower-Right
485 check( inv6.hitTest(200 + (19*4), 100 + (14*4), true) ); // Center-Right
486 check( inv6.hitTest(200 + (19*4), 100 + (11*4), true) ); // Upper-Right
487 check( inv6.hitTest(200 + (14*4), 100 + (11*4), true) ); // Upper-Center
489 // Nested squares, calling beginFill again after the move)
490 // Outer square counterclockwise order, inner in clockwise order
491 createEmptyMovieClip("inv7", 7);
492 with (inv7)
494 lineStyle(0, 0); // hairline
495 beginFill(0x00FF00);
497 moveTo(10, 10);
498 lineTo(10, 20);
499 lineTo(20, 20);
500 lineTo(20, 10);
501 lineTo(10, 10);
503 moveTo(12, 12);
505 // this forces endFill call, which triggers finalization of previous path (I think)
506 beginFill(0x00FF00);
508 lineTo(18, 12);
509 lineTo(18, 18);
510 lineTo(12, 18);
511 lineTo(12, 12);
513 inv7._xscale = inv7._yscale = 400;
514 inv7._y = 100; inv7._x = 250;
515 inv7.onRollOver = function() {};
517 // Point inside the inner square hits the shape !
518 check( inv7.hitTest(250 + (15*4), 100 + (15*4), true) );
519 // As points on the outer borders
520 check( inv7.hitTest(250 + (11*4), 100 + (11*4), true) ); // Upper-Left
521 check( inv7.hitTest(250 + (11*4), 100 + (14*4), true) ); // Center-Left
522 check( inv7.hitTest(250 + (11*4), 100 + (19*4), true) ); // Lower-Left
523 check( inv7.hitTest(250 + (14*4), 100 + (19*4), true) ); // Lower-Center
524 check( inv7.hitTest(250 + (19*4), 100 + (19*4), true) ); // Lower-Right
525 check( inv7.hitTest(250 + (19*4), 100 + (14*4), true) ); // Center-Right
526 check( inv7.hitTest(250 + (19*4), 100 + (11*4), true) ); // Upper-Right
527 check( inv7.hitTest(250 + (14*4), 100 + (11*4), true) ); // Upper-Center
529 //------------------------------------------------
531 // Single path with complex crossing
534 // 10 5----4,0----------1
535 // |#####|###########|
536 // |#####|###########|
537 // 20 6-----+----7######|
538 // | |######|
539 // | |######|
540 // 30 9----8######|
541 // |###########|
542 // 40 3-----------2
544 // 10 20 30 40
546 //------------------------------------------------
547 createEmptyMovieClip("inv8", 8);
548 with (inv8)
550 beginFill(0xFF0000);
551 moveTo(20, 10); // 0
552 lineTo(40, 10); // 1
553 lineTo(40, 40); // 2
554 lineTo(20, 40); // 3
555 lineTo(20, 10); // 4
557 lineTo(10, 10); // 5
558 lineTo(10, 20); // 6
559 lineTo(30, 20); // 7
560 lineTo(30, 30); // 8
561 lineTo(20, 30); // 9
563 // implicit close-up to 0 (aka 4, aka 20,10)
566 inv8._xscale = inv8._yscale = 200;
567 inv8._x = 200;
568 inv8.onRollOver = function() {};
570 check( inv8.hitTest(200 + (15*2), 0 + (15*2), true) ); // Upper-Left
571 check( inv8.hitTest(200 + (25*2), 0 + (15*2), true) ); // Upper-Center
572 check( inv8.hitTest(200 + (35*2), 0 + (15*2), true) ); // Upper-Right
574 check( !inv8.hitTest(200 + (15*2), 0 + (25*2), true) ); // Center-Left
575 check( !inv8.hitTest(200 + (25*2), 0 + (25*2), true) ); // Center-Center
576 check( inv8.hitTest(200 + (35*2), 0 + (25*2), true) ); // Center-Right
578 check( !inv8.hitTest(200 + (15*2), 0 + (35*2), true) ); // Lower-Left
579 check( inv8.hitTest(200 + (25*2), 0 + (35*2), true) ); // Lower-Center
580 check( inv8.hitTest(200 + (35*2), 0 + (35*2), true) ); // Lower-Right
582 check( !inv8.hitTest(200 + (20*2), 0 + (25*2), true) ); // On the 0-9 stroke, out of fill
585 _visible = false;
588 createEmptyMovieClip("line", 110);
589 with(line) {
591 col = 0xff0000;
592 colc = 100;
593 x = 20;
594 y = 20;
595 xr = 100;
596 yr = 100;
597 n = 10;
598 alpha = 100;
600 // =======================
601 // Shape 1
602 // =======================
604 beginFill(col,colc);
605 lineStyle(n,0x0000ff,alpha);
607 moveTo(x,y);
608 lineTo(x+xr,y);
609 lineTo((x+xr),(y+yr));
611 // In Gnash, next line forces a new path,
612 // and closeup of the former (shouldn't)
614 lineStyle(n,0x00ff00,alpha);
616 lineTo(x,(y+yr));
617 lineTo(x,y);
619 endFill();
621 // =======================
622 // Shape 2
623 // =======================
625 x += 200;
627 beginFill(col,colc);
628 lineStyle(n,1,alpha);
630 moveTo(x,y);
631 lineTo(x+xr,y);
633 lineStyle(n,0x0000ff,alpha);
635 lineTo((x+xr),(y+yr));
637 lineStyle(n,0x00ff00,alpha);
639 lineTo(x,(y+yr));
640 lineTo(x,y);
642 endFill();
644 // =======================
645 // Shape 3
646 // =======================
648 x += 200;
650 createEmptyMovieClip("d", 500);
651 with (d)
653 lineStyle(10, 10, 100);
654 moveTo(x, y);
655 lineTo(x, y + yr);
656 lineTo(x + xr, y + yr);
657 endFill(); // does NOT force closeup
660 // =======================
661 // Shape 4
662 // =======================
664 x = 20;
665 y += 150;
667 createEmptyMovieClip("e", 501);
668 with (e)
670 lineStyle(10, 10, 100);
671 beginFill(); // does NOT start a fill
672 moveTo(x, y);
673 lineTo(x, y + yr);
674 lineTo(x + xr, y + yr);
675 endFill(); // does NOT force closeup
678 // The shape is not closed to form a triangle,
679 // so the only way to hit it is to hit the line.
680 check(!e.hitTest(x + 30, y + 30, true));
682 // Top right 'corner'
683 check(e.hitTest(x, y, true));
685 // =======================
686 // Shape 5
687 // =======================
689 x += 200;
691 createEmptyMovieClip("f", 502);
692 with (f)
694 lineStyle(10, 10, 100);
695 beginFill(0); // does start a fill
696 moveTo(x, y);
697 lineTo(x, y + yr);
698 lineTo(x + xr, y + yr);
699 endFill(); // DOES force closeup
702 // Somewhere within the closed triangle.
703 check(f.hitTest(x + 30, y + 30, true));
705 // =======================
706 // Shape 6
707 // =======================
709 x += 200;
711 createEmptyMovieClip("g", 503);
712 with (g)
714 lineStyle(10, 0xFFFF00, 100);
715 beginFill(0x00ff00); // does start a fill
716 moveTo(x, y);
717 lineTo(x, y + yr);
718 lineTo(x + xr, y + yr);
719 beginFill(0x0000ff); // closes previous fill, opens a new one
720 lineTo(x + xr, y);
721 lineTo(x + xr, y + yr);
722 endFill(); // DOES force closeup
725 // Bottom left
726 check(g.hitTest(x + 20, y + 80, true));
728 // Top right
729 // COMPATIBLITY NOTE:
730 // 9,0,115,0 for linux sometimes finds the point to hit
731 // the shape and sometimes it doesn't.
732 // 10,0,12,10 never succeeds the hit test.
734 // The point is clearly within a fill so we'll take an hit test
735 // success as expected.
737 check(g.hitTest(x + 80, y + 20, true));
739 _visible = false;
741 line.onRollOver = function() {};
743 // Check the the top right diagonal half of Shape 2.
744 xcheck(line.hitTest(270, 40, true));
746 // Check the bottom left diagonal half of Shape 2.
747 check(line.hitTest(230, 80, true));
750 // Page 4 ( page[3] )
752 draw100x100Box = function(x, y, mc) {
753 s = 90;
754 with (mc) {
755 moveTo(x, y);
756 lineTo(x + s, y);
757 lineTo(x + s, y + s);
758 lineTo(x, y + s);
759 lineTo(x, y);
760 endFill();
765 createEmptyMovieClip("grad", 150);
767 // Test gradients.
768 // The beginGradientFill function works with fake Matrices, but there is no
769 // point making more work for ourselves as that testing is already done for
770 // the Matrix class.
771 // Only the "box" matrixType gets special handling.
773 with(grad) {
775 // Linear gradients
776 fillType = "linear";
778 x = 0;
779 y = 0;
781 // shape 1
782 colors = [0x0000ff, 0xffffff];
783 alphas = [100, 100];
784 ratios = [0, 0xff];
785 matrix = new flash.geom.Matrix();
786 beginGradientFill(fillType, colors, alphas, ratios, matrix);
787 draw100x100Box(x, y, grad);
789 // shape 2
790 x += 100;
791 colors = [0x0000ff, 0xffffff];
792 alphas = [100, 100];
793 ratios = [0, 0xff];
794 matrix.createGradientBox(90, 90, 0, x, y);
795 beginGradientFill(fillType, colors, alphas, ratios, matrix);
796 draw100x100Box(x, y, grad);
798 // shape 3
799 x += 100;
800 colors = [0x0000ff, 0xffffff, 0xff00ff];
801 alphas = [100, 100, 100];
802 ratios = [0, 0xff / 2, 0xff];
803 matrix.createGradientBox(90, 90, Math.PI / 4, x, y);
804 beginGradientFill(fillType, colors, alphas, ratios, matrix);
805 draw100x100Box(x, y, grad);
807 // shape 4
808 x += 100;
809 colors = [0x0000ff, 0xffffff, 0xff00ff];
810 alphas = [100, 100, 100];
811 ratios = [0, 0xff / 2, 0xff];
812 matrix.createGradientBox(180, 180, Math.PI / 4, x, y);
813 beginGradientFill(fillType, colors, alphas, ratios, matrix);
814 draw100x100Box(x, y, grad);
816 // shape 5
817 x += 100;
818 colors = [0x0000ff, 0xffffff, 0x00ff00];
819 alphas = [100, 100, 100];
820 ratios = [0, 0xff / 2, 0xff];
821 matrix.createGradientBox(180, 180, Math.PI / 4 * 3, x - 90, y - 90);
822 beginGradientFill(fillType, colors, alphas, ratios, matrix);
823 draw100x100Box(x, y, grad);
825 // shape 6
826 x += 100;
827 colors = [0x0000ff, 0xffffff, 0x00ff00, 0xff00ff, 0x00ffff, 0xffff00 ];
828 alphas = [100, 100, 100, 50, 25, 100];
829 ratios = [0, 0xff / 5, 0xff / 5 * 2, 0xff / 5 * 3, 0xff / 5 * 4, 0xff];
830 matrix.createGradientBox(90, 90, Math.PI / 2, x, y);
831 beginGradientFill(fillType, colors, alphas, ratios, matrix);
832 draw100x100Box(x, y, grad);
834 // Radial gradients
835 fillType = "radial";
837 x = 0;
838 y += 100;
840 // shape 7
841 colors = [0x0000ff, 0xffffff];
842 alphas = [100, 100];
843 ratios = [0, 0xff];
844 matrix = new flash.geom.Matrix();
845 beginGradientFill(fillType, colors, alphas, ratios, matrix);
846 draw100x100Box(x, y, grad);
848 // shape 8
849 x += 100;
850 colors = [0x0000ff, 0xffffff];
851 alphas = [100, 100];
852 ratios = [0, 0xff];
853 matrix.createGradientBox(90, 90, 0, x, y);
854 beginGradientFill(fillType, colors, alphas, ratios, matrix);
855 draw100x100Box(x, y, grad);
857 // shape 9
858 x += 100;
859 colors = [0x0000ff, 0xffffff, 0xff00ff];
860 alphas = [100, 100, 100];
861 ratios = [0, 0xff / 2, 0xff];
862 matrix.createGradientBox(90, 90, Math.PI / 4, x, y);
863 beginGradientFill(fillType, colors, alphas, ratios, matrix);
864 draw100x100Box(x, y, grad);
866 // shape 10
867 x += 100;
868 colors = [0x0000ff, 0xffffff, 0xff00ff];
869 alphas = [100, 100, 100];
870 ratios = [0, 0xff / 2, 0xff];
871 matrix.createGradientBox(180, 180, Math.PI / 4, x, y);
872 beginGradientFill(fillType, colors, alphas, ratios, matrix);
873 draw100x100Box(x, y, grad);
875 // shape 11
876 x += 100;
877 colors = [0x0000ff, 0xffffff, 0x00ff00];
878 alphas = [100, 100, 100];
879 ratios = [0, 0xff / 2, 0xff];
880 matrix.createGradientBox(180, 180, Math.PI / 4 * 3, x - 90, y - 90);
881 beginGradientFill(fillType, colors, alphas, ratios, matrix);
882 draw100x100Box(x, y, grad);
884 // shape 12
885 x += 100;
886 colors = [0x0000ff, 0xffffff, 0x00ff00, 0xff00ff, 0x00ffff, 0xffff00 ];
887 alphas = [100, 100, 100, 50, 25, 100];
888 ratios = [0, 0xff / 5, 0xff / 5 * 2, 0xff / 5 * 3, 0xff / 5 * 4, 0xff];
889 matrix.createGradientBox(90, 90, Math.PI / 2, x, y);
890 beginGradientFill(fillType, colors, alphas, ratios, matrix);
891 draw100x100Box(x, y, grad);
893 y += 100;
894 x = 0;
896 // Shape 13
898 // Check that ratios are adjusted if they do not get successively larger.
899 fillType = "linear";
900 colors = [0x0000ff, 0xffffff, 0x00ff00];
901 alphas = [100, 100, 100];
902 ratios = [0, 0x10, 0x05];
903 matrix.createGradientBox(90, 90, 0, x, y);
904 beginGradientFill(fillType, colors, alphas, ratios, matrix);
905 draw100x100Box(x, y, grad);
908 // Shape 14
909 x += 100;
911 // Test a linear gradient with one stop
912 fillType = "linear";
913 colors = [0xff0000];
914 alphas = [100];
915 ratios = [0];
916 matrix.createGradientBox(90, 90, 0, x, y);
917 beginGradientFill(fillType, colors, alphas, ratios, matrix);
918 draw100x100Box(x, y, grad);
921 // Shape 15
922 x += 100;
924 // Test a linear gradient with one stop
925 fillType = "radial";
926 colors = [0x00ff00];
927 alphas = [100];
928 ratios = [0];
929 matrix.createGradientBox(90, 90, 0, x, y);
930 beginGradientFill(fillType, colors, alphas, ratios, matrix);
931 draw100x100Box(x, y, grad);
933 // Shape 16
934 x += 100;
936 // Bad fill style results in no fill.
937 fillType = "rodial";
938 colors = [0x0000ff, 0xffffff, 0x00ff00];
939 alphas = [100, 100, 100];
940 ratios = [0, 0x10, 0x05];
941 matrix.createGradientBox(90, 90, 0, x, y);
942 beginGradientFill(fillType, colors, alphas, ratios, matrix);
943 draw100x100Box(x, y, grad);
945 // Shape 17
946 x += 100;
948 // Extra arguments result in no fill for SWF6
949 fillType = "radial";
950 colors = [0x0000ff, 0xffffff, 0x00ff00];
951 alphas = [100, 100, 100];
952 ratios = [0, 0x10, 0x05];
953 matrix.createGradientBox(90, 90, 0, x, y);
954 beginGradientFill(fillType, colors, alphas, ratios, matrix, "pad");
955 draw100x100Box(x, y, grad);
957 x = 0;
958 y += 100;
960 // Shape 18
962 // 4 arguments result in no fill for SWF6
963 fillType = "radial";
964 colors = [0x0000ff, 0xffffff, 0x00ff00];
965 alphas = [100, 100, 100];
966 ratios = [0, 0x10, 0x05];
967 matrix.createGradientBox(90, 90, 0, x, y);
968 beginGradientFill(fillType, colors, alphas, ratios);
969 draw100x100Box(x, y, grad);
971 _visible = false;
974 grad.onRollOver = function() {};
976 //---------------------------------------------------------------------------
978 //---------------------------------------------------------------------------
980 createEmptyMovieClip("hitdetector", 3);
981 hitdetector.createEmptyMovieClip("shapeshape", 1);
982 with(hitdetector.shapeshape)
984 lineStyle(2, 0x000000);
985 beginFill(0xFFFF00, 100);
986 drawCircle(hitdetector.shapeshape, 0, 0, 20);
987 endFill();
990 hitdetector.createEmptyMovieClip("bboxpoint", 2);
991 with(hitdetector.bboxpoint)
993 lineStyle(2, 0x000000);
994 beginFill(0xFFFF00, 100);
995 drawCircle(hitdetector.bboxpoint, 0, 0, 20);
996 endFill();
997 _x = 60;
1000 hitdetector.createEmptyMovieClip("shapepoint", 3);
1001 with(hitdetector.shapepoint)
1003 lineStyle(2, 0x000000);
1004 beginFill(0xFFFF00, 100);
1005 drawCircle(hitdetector.shapepoint, 0, 0, 20);
1006 endFill();
1007 _x = 120;
1010 hitdetector._y = 350;
1013 createEmptyMovieClip("cursor", 12);
1014 with(cursor)
1016 lineStyle(2, 0x000000);
1017 beginFill(0xFF0000, 100);
1018 drawCircle(_root.cursor, 0, 0, 10);
1019 endFill();
1020 onEnterFrame = function()
1022 hd = _root.hitdetector;
1024 // don't move the controls for now...
1025 #if 0
1026 with(hd)
1028 if ( typeof(xshift) == 'undefined' )
1030 xshift = 1;
1032 else if ( xshift > 0 && _x >= 300 )
1034 xshift = -1;
1036 else if ( xshift < 0 && _x == 0 )
1038 xshift = 1;
1041 _x += xshift;
1043 #endif
1046 _x = _root._xmouse;
1047 _y = _root._ymouse;
1049 var ch = _root.page[_root.visibleIndex];
1051 // Bounding box check
1052 if ( hitTest(ch) ) {
1053 hd.shapeshape._xscale=150;
1054 hd.shapeshape._yscale=150;
1055 } else {
1056 hd.shapeshape._xscale=100;
1057 hd.shapeshape._yscale=100;
1060 // Bounding box check with circle center
1061 if ( ch.hitTest(_x, _y) ) {
1062 hd.bboxpoint._xscale=150;
1063 hd.bboxpoint._yscale=150;
1064 } else {
1065 hd.bboxpoint._xscale=100;
1066 hd.bboxpoint._yscale=100;
1069 // Shape check with circle center
1070 if ( ch.hitTest(_x, _y, true) ) {
1071 hd.shapepoint._xscale=150;
1072 hd.shapepoint._yscale=150;
1073 } else {
1074 hd.shapepoint._xscale=100;
1075 hd.shapepoint._yscale=100;
1081 isMask = false;
1082 onMouseDown = function()
1084 var ch = _root.page[_root.visibleIndex];
1086 if ( isMask )
1088 ch.setMask(); // no effect !
1089 ch.setMask(true); // no effect !
1090 trace("Disabling cursor mask");
1091 ch.setMask(undefined); // works
1092 //a.setMask(null); // also work
1094 else
1096 trace("Enabling cursor mask");
1097 ch.setMask(cursor);
1099 isMask = !isMask;
1104 visibleIndex = 0;
1105 page = new Array;
1106 page[0] = a;
1107 page[1] = inv;
1108 page[2] = line;
1109 page[3] = grad;
1111 onKeyDown = function()
1113 var ascii = Key.getAscii();
1114 if ( ascii >= 48 && ascii <= 57 ) // 0..9 - activate corresponding drawing
1116 with (page[visibleIndex])
1118 _visible = false;
1119 setMask(null);
1122 visibleIndex = parseInt(ascii)-49;
1123 trace("Key "+visibleIndex+" hit");
1125 with (page[visibleIndex])
1127 _visible = true;
1130 else if ( ascii == 104 ) // 'h' - toggle visibility
1132 page[visibleIndex]._visible = ! page[visibleIndex]._visible;
1134 else if ( ascii == 45 ) // '-' - decrease alpha
1136 var newAlpha = page[visibleIndex]._alpha - 25;
1137 if ( newAlpha < 0 ) newAlpha = 0;
1138 page[visibleIndex]._alpha = newAlpha;
1140 else if ( ascii == 43 ) // '+' - increase alpha
1142 var newAlpha = page[visibleIndex]._alpha + 25;
1143 if ( newAlpha > 100 ) newAlpha = 100;
1144 page[visibleIndex]._alpha = newAlpha;
1146 else if ( ascii == 100 ) // 'd' - start/stop dragging something :)
1148 if ( ! hitdetector.dragging ) {
1149 hitdetector.dragging = true;
1150 hitdetector.startDrag();
1151 // hitdetector.startDrag(true); // lock centered
1152 //hitdetector.startDrag(true, 100, 100, 200, 200); // lock centered, box-constrained
1153 } else {
1154 hitdetector.dragging = flase;
1155 hitdetector.stopDrag();
1160 Key.addListener(this);
1162 stop();