~extremepopcorn/dhlib/dhlib_ep

« back to all changes in this revision

Viewing changes to app-squix/squix/test/FlashDefectErase.hx

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* <license>
 
2
 * This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
 
3
 * For full copyright and license information please refer to doc/license.txt.
 
4
 * </license> 
 
5
 */
 
6
package squix.test;
 
7
 
 
8
import flash.display.Bitmap;
 
9
import flash.display.BitmapData;
 
10
import flash.display.Sprite;
 
11
 
 
12
import flash.events.MouseEvent;
 
13
import flash.events.Event;
 
14
 
 
15
/**
 
16
 * This demonstrates an alisgnment problem in Flash when drawing to bitmaps
 
17
 * using the ERASE mode.  The three boxes on the screen should be aligned
 
18
 * on both sides, but they are not, the bottom one is one-pixel smaller to the left
 
19
 * and 2 pixesl smaller to the right
 
20
 *
 
21
 * Hmm, isolated like this I can't see a problem. :(
 
22
 */
 
23
class FlashDefectErase extends ui.StageLayout
 
24
{
 
25
        public function new()
 
26
        {
 
27
                super();
 
28
        }
 
29
        
 
30
        var bitS : Bitmap;
 
31
        var boxS : Sprite;
 
32
        var subS : Bitmap;
 
33
        
 
34
        function _resize( w : Float, h : Float )
 
35
        {
 
36
                //remove children if not first time
 
37
                if( bitS != null )
 
38
                {
 
39
                        removeChild( bitS );
 
40
                        removeChild( boxS );
 
41
                        removeChild( subS );
 
42
                }
 
43
                        
 
44
                //setup background
 
45
                graphics.clear();
 
46
                graphics.beginFill( 0xFF0000 );
 
47
                graphics.drawRect( 0, 0, w, h );
 
48
                graphics.endFill();
 
49
                
 
50
                var left = Math.floor( w/ 4 );
 
51
                var right = Math.floor( w - left );
 
52
                var mid = Math.floor( h/3 );
 
53
                
 
54
                //setup graphic to draw (will server as first child as well)
 
55
                boxS = new Sprite();
 
56
                boxS.graphics.beginFill(0x00FF00);
 
57
                boxS.graphics.lineStyle( 2, 0x0000FF );
 
58
                boxS.graphics.drawRect( left, 0, right - left, mid );
 
59
                boxS.graphics.endFill();
 
60
                        
 
61
                //create new bitmap
 
62
                var bit = new BitmapData( Math.ceil(w), mid, true, 0x00000000 );
 
63
                bit.draw( boxS );
 
64
                bitS = new Bitmap( bit );
 
65
                bitS.x = 0;
 
66
                bitS.y = mid;
 
67
                
 
68
                //create erased bitmap
 
69
                var sub = new BitmapData( Math.ceil( w ), mid, true, 0xFF00FF00 );
 
70
                sub.draw( boxS, null, null, flash.display.BlendMode.ERASE );
 
71
                subS = new Bitmap( sub );
 
72
                subS.x = 0;
 
73
                subS.y = mid *2;
 
74
                
 
75
                //add both children
 
76
                addChild( bitS );
 
77
                addChild( boxS );
 
78
                addChild( subS );
 
79
        }
 
80
        
 
81
        static public function main()
 
82
        {
 
83
                ui.StageLayout.setup( FlashDefectErase );
 
84
        }
 
85
}