1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2008 Adobe Systems Incorporated 5// All Rights Reserved. 6// 7// NOTICE: Adobe permits you to use, modify, and distribute this file 8// in accordance with the terms of the license agreement accompanying it. 9// 10//////////////////////////////////////////////////////////////////////////////// 11 12package spark.filters 13{ 14import flash.filters.BitmapFilter; 15import flash.filters.DropShadowFilter; 16import mx.filters.BaseDimensionFilter; 17import mx.filters.IBitmapFilter; 18 19 20/** 21 * The DropShadowFilter class lets you add a drop shadow to display objects. 22 * The shadow algorithm is based on the same box filter that the blur filter uses. You have 23 * several options for the style of the drop shadow, including inner or outer shadow and knockout mode. 24 * You can apply the filter to any display object (that is, objects that inherit from the DisplayObject class), 25 * such as MovieClip, SimpleButton, TextField, and Video objects, as well as to BitmapData objects. 26 * 27 * <p>The use of filters depends on the object to which you apply the filter:</p> 28 * <ul><li>To apply filters to display objects use the 29 * <code>filters</code> property (inherited from DisplayObject). Setting the <code>filters</code> 30 * property of an object does not modify the object, and you can remove the filter by clearing the 31 * <code>filters</code> property. </li> 32 * 33 * <li>To apply filters to BitmapData objects, use the <code>BitmapData.applyFilter()</code> method. 34 * Calling <code>applyFilter()</code> on a BitmapData object takes the source BitmapData object 35 * and the filter object and generates a filtered image as a result.</li> 36 * </ul> 37 * 38 * <p>If you apply a filter to a display object, the value of the <code>cacheAsBitmap</code> property of the 39 * display object is set to <code>true</code>. If you clear all filters, the original value of 40 * <code>cacheAsBitmap</code> is restored.</p> 41 * <p>This filter supports Stage scaling. However, it does not support general scaling, rotation, and 42 * skewing. If the object itself is scaled (if <code>scaleX</code> and <code>scaleY</code> are 43 * set to a value other than 1.0), the filter is not scaled. It is scaled only when 44 * the user zooms in on the Stage.</p> 45 * 46 * <p>A filter is not applied if the resulting image exceeds the maximum dimensions. 47 * In AIR 1.5 and Flash Player 10, the maximum is 8,191 pixels in width or height, 48 * and the total number of pixels cannot exceed 16,777,215 pixels. (So, if an image is 8,191 pixels 49 * wide, it can only be 2,048 pixels high.) 50 * If, for example, you zoom in on a large movie clip with a filter applied, the filter is 51 * turned off if the resulting image exceeds the maximum dimensions.</p> 52 * 53 * @mxml 54 * <p>The <code><s:DropShadowFilter></code> tag inherits all of the tag 55 * attributes of its superclass and adds the following tag attributes:</p> 56 * 57 * <pre> 58 * <s:DropShadowFilter 59 * <strong>Properties</strong> 60 * alpha="1" 61 * angle="45" 62 * color="0xFF0000" 63 * distance="4" 64 * hideObject="false" 65 * inner="false" 66 * /> 67 * </pre> 68 * 69 * @includeExample examples/DropShadowFilterExample.mxml 70 * 71 * @see flash.filters.DropShadowFilter 72 * 73 * @langversion 3.0 74 * @playerversion Flash 10 75 * @playerversion AIR 1.5 76 * @productversion Flex 4 77 */ 78 79public class DropShadowFilter extends BaseDimensionFilter implements IBitmapFilter 80{ 81 /** 82 * Constructor. 83 * 84 * @param distance Offset distance for the shadow, in pixels. 85 * @param angle Angle of the shadow, 0 to 360 degrees (floating point). 86 * @param color Color of the shadow, in hexadecimal format 87 * <i>0xRRGGBB</i>. The default value is 0x000000. 88 * @param alpha Alpha transparency value for the shadow color. Valid values are 0.0 to 1.0. 89 * For example, .25 sets a transparency value of 25%. 90 * @param blurX Amount of horizontal blur. Valid values are 0 to 255.0 (floating point). 91 * @param blurY Amount of vertical blur. Valid values are 0 to 255.0 (floating point). 92 * @param strength The strength of the imprint or spread. The higher the value, 93 * the more color is imprinted and the stronger the contrast between the shadow and the background. 94 * Valid values are 0 to 255.0. 95 * @param quality The number of times to apply the filter. Use the BitmapFilterQuality constants: 96 * <ul> 97 * <li><code>BitmapFilterQuality.LOW</code></li> 98 * <li><code>BitmapFilterQuality.MEDIUM</code></li> 99 * <li><code>BitmapFilterQuality.HIGH</code></li> 100 * </ul> 101 * <p>For more information about these values, see the <code>quality</code> property description.</p> 102 * 103 * @param inner Indicates whether or not the shadow is an inner shadow. A value of <code>true</code> specifies 104 * an inner shadow. A value of <code>false</code> specifies an outer shadow (a 105 * shadow around the outer edges of the object). 106 * @param knockout Applies a knockout effect (<code>true</code>), which effectively 107 * makes the object's fill transparent and reveals the background color of the document. 108 * @param hideObject Indicates whether or not the object is hidden. A value of <code>true</code> 109 * indicates that the object itself is not drawn; only the shadow is visible. 110 * 111 * @see flash.filters.BitmapFilterQuality 112 * 113 * @langversion 3.0 114 * @playerversion Flash 10 115 * @playerversion AIR 1.5 116 * @productversion Flex 4 117 */ 118 public function DropShadowFilter(distance:Number = 4.0, angle:Number = 45, 119 color:uint = 0, alpha:Number = 1.0, 120 blurX:Number = 4.0, blurY:Number = 4.0, 121 strength:Number = 1.0, quality:int = 1, 122 inner:Boolean = false, 123 knockout:Boolean = false, 124 hideObject:Boolean = false) 125 { 126 super(); 127 128 this.distance = distance; 129 this.angle = angle; 130 this.color = color; 131 this.alpha = alpha; 132 this.blurX = blurX; 133 this.blurY = blurY; 134 this.strength = strength; 135 this.quality = quality; 136 this.inner = inner; 137 this.knockout = knockout; 138 this.hideObject = hideObject; 139 } 140 141 //---------------------------------- 142 // alpha 143 //---------------------------------- 144 145 private var _alpha:Number = 1.0; 146 147 [Inspectable(minValue="0.0", maxValue="1.0")] 148 149 /** 150 * The alpha transparency value for the color. Valid values are 0 to 1. 151 * For example, .25 sets a transparency value of 25%. 152 * 153 * @default 1 154 * 155 * @langversion 3.0 156 * @playerversion Flash 10 157 * @playerversion AIR 1.5 158 * @productversion Flex 4 159 */ 160 public function get alpha():Number 161 { 162 return _alpha; 163 } 164 165 public function set alpha(value:Number):void 166 { 167 if (value != _alpha) 168 { 169 _alpha = value; 170 notifyFilterChanged(); 171 } 172 } 173 174 //---------------------------------- 175 // angle 176 //---------------------------------- 177 178 private var _angle:Number = 45; 179 180 /** 181 * The angle of the bevel. Valid values are from 0 to 360°. 182 * The angle value represents the angle of the theoretical light source falling on the 183 * object and determines the placement of the effect relative to the object. 184 * If the distance property is set to 0, the effect is not offset from the object and, 185 * therefore, the angle property has no effect. 186 * 187 * @default 45 188 * 189 * @langversion 3.0 190 * @playerversion Flash 10 191 * @playerversion AIR 1.5 192 * @productversion Flex 4 193 */ 194 public function get angle():Number 195 { 196 return _angle; 197 } 198 199 public function set angle(value:Number):void 200 { 201 if (value != _angle) 202 { 203 _angle = value; 204 notifyFilterChanged(); 205 } 206 } 207 208 //---------------------------------- 209 // color 210 //---------------------------------- 211 212 private var _color:uint = 0x000000; 213 214 /** 215 * The color of the glow. Valid values are in the hexadecimal format 216 * 0xRRGGBB. 217 * @default 0xFF0000 218 * 219 * @langversion 3.0 220 * @playerversion Flash 10 221 * @playerversion AIR 1.5 222 * @productversion Flex 4 223 */ 224 public function get color():uint 225 { 226 return _color; 227 } 228 229 public function set color(value:uint):void 230 { 231 if (value != _color) 232 { 233 _color = value; 234 notifyFilterChanged(); 235 } 236 } 237 238 //---------------------------------- 239 // distance 240 //---------------------------------- 241 242 private var _distance:Number = 4.0; 243 244 /** 245 * The offset distance of the bevel. Valid values are in pixels (floating point). 246 * @default 4 247 * 248 * @langversion 3.0 249 * @playerversion Flash 10 250 * @playerversion AIR 1.5 251 * @productversion Flex 4 252 */ 253 public function get distance():Number 254 { 255 return _distance; 256 } 257 258 public function set distance(value:Number):void 259 { 260 if (value != _distance) 261 { 262 _distance = value; 263 notifyFilterChanged(); 264 } 265 } 266 267 //---------------------------------- 268 // hideObject 269 //---------------------------------- 270 271 private var _hideObject:Boolean = false; 272 273 /** 274 * Indicates whether or not the object is hidden. 275 * The value <code>true</code> indicates that the 276 * object itself is not drawn; only the shadow is visible. 277 * The default is <code>false</code>, meaning that the object is shown. 278 * 279 * @default false 280 * 281 * @langversion 3.0 282 * @playerversion Flash 10 283 * @playerversion AIR 1.5 284 * @productversion Flex 4 285 */ 286 public function get hideObject():Boolean 287 { 288 return _hideObject; 289 } 290 291 public function set hideObject(value:Boolean):void 292 { 293 if (value != _hideObject) 294 { 295 _hideObject = value; 296 notifyFilterChanged(); 297 } 298 } 299 300 //---------------------------------- 301 // inner 302 //---------------------------------- 303 304 private var _inner:Boolean = false; 305 306 /** 307 * Specifies whether the glow is an inner glow. 308 * The value <code>true</code> indicates an inner glow. 309 * The default is <code>false</code> that creates an outer glow 310 * (a glow around the outer edges of the object). 311 * 312 * @default false 313 * 314 * @langversion 3.0 315 * @playerversion Flash 10 316 * @playerversion AIR 1.5 317 * @productversion Flex 4 318 */ 319 public function get inner():Boolean 320 { 321 return _inner; 322 } 323 324 public function set inner(value:Boolean):void 325 { 326 if (value != _inner) 327 { 328 _inner = value; 329 notifyFilterChanged(); 330 } 331 } 332 333 /** 334 * Returns a copy of this filter object. 335 * @return A new DropShadowFilter instance with all the 336 * properties of the original DropShadowFilter instance. 337 * 338 * @langversion 3.0 339 * @playerversion Flash 10 340 * @playerversion AIR 1.5 341 * @productversion Flex 4 342 */ 343 344 public function clone():BitmapFilter 345 { 346 return new flash.filters.DropShadowFilter(distance, angle, color, alpha, blurX, 347 blurY, strength, quality, inner, 348 knockout, hideObject); 349 } 350 351} 352 353}