1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4  
     5  import org.aswing.*;
     6  import org.aswing.graphices.*;
     7   
     8  /**
     9   * GrayFilteredIcon use to filter a icon to be gray.
    10   * Current this is just approximate effect, will be implement 
    11   * ture gray filter with flash 8ball new functions.
    12   * @author iiley
    13   */
    14  class org.aswing.GrayFilteredIcon extends ComponentDecorator implements Icon{
    15  	public static var DEFAULT_GRAY:Number = 50;
    16  	
    17  	private var icon:Icon;
    18  	private var filterTranform:Object;
    19  	
    20  	/**
    21  	 * Create a gray filtered icon by given icon.
    22  	 * <p>
    23  	 * GrayFilterIcon(icon:Icon) gray by default.<br> 
    24  	 * GrayFilterIcon(icon:Icon, gray:Number)<br>
    25  	 * <p>
    26  	 * @param icon the icon need to be filtered.
    27  	 * @param gray the gray value, in range [-100,-100], default is 50.
    28  	 */
    29  	public function GrayFilteredIcon(icon:Icon, gray:Number){
    30  		super();
    31  		this.icon = icon;
    32  		if(gray == undefined) gray = DEFAULT_GRAY;
    33  		filterTranform = { ra:gray, rb:0, ga:gray, gb:0, ba:gray, bb:0, aa:gray, ab:0};
    34  	}
    35  	
    36  	/**
    37  	 * Return the icon's width.
    38  	 */
    39  	public function getIconWidth():Number{
    40  		return icon.getIconWidth();
    41  	}
    42  	
    43  	/**
    44  	 * Return the icon's height.
    45  	 */
    46  	public function getIconHeight():Number{
    47  		return icon.getIconHeight();
    48  	}
    49  	
    50  	/**
    51  	 * This method call <code>super.createDecorateMC()</code> to create the MC
    52  	 * and then set gray transform to the MC.
    53  	 */
    54  	public function createDecorateMC(c:Component):MovieClip{
    55  		var mc:MovieClip = super.createDecorateMC(c);
    56  		var color:Color = new Color(mc);
    57  		color.setTransform(filterTranform);
    58  		return mc;
    59  	}
    60  	
    61  	public function paintIcon(com:Component, g:Graphics, x:Number, y:Number):Void{
    62  		var mc:MovieClip = this.getCreateDecorateMC(com);
    63  		mc.clear();
    64  		var graphics:Graphics = new Graphics(mc);
    65  		icon.paintIcon(com, graphics, x, y);
    66  	}
    67  	
    68  	public function uninstallIcon(com:Component):Void{
    69  		icon.uninstallIcon(com);
    70  		removeDecorateMC(com);
    71  	}
    72  }
    73