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////////////////////////////////////////////////////////////////////////////////
11package spark.effects
12{
13import flash.display.Shader;
14import flash.utils.ByteArray;
15import mx.effects.IEffectInstance;
16
17/**
18 *  The Wipe effect uses Pixel Bender, which is not supported
19 *  for AIR mobile applications.
20 */
21[DiscouragedForProfile("mobileDevice")]
22
23/**
24 *  The Wipe effect performs a bitmap transition effect by running a
25 *  directional wipe between the first and second bitmaps.
26 *  This wipe exposes the second bitmap over the course of the
27 *  animation in a direction indicated by the <code>direction</code>
28 *  property.
29 *
30 *  <p>A pixel-shader program loaded by the effect
31 *  runs the underlying bitmap effect.
32 *  If you want to use
33 *  a different Wipe behavior, you can specify a custom pixel-shader program.
34 *  The pixel-shader program must adhere to the constraints
35 *  specified for the <code>shaderByteCode</code>
36 *  property of AnimateTransitionShader class, and supply three additional
37 *  parameters.
38 *  The extra parameters required by the Wipe shader
39 *  are:</p>
40 *
41 *  <ul>
42 *    <li>An int <code>direction</code> parameter,
43 *  whose value means the same as the related String property
44 *  in the Wipe class.</li>
45 *    <li>Two floating point parameters:
46 *  <code>imageWidth</code> and <code>imageHeight</code>. </li>
47 *  </ul>
48 *
49 *  <p>All of these parameters are set on the shader when the effect starts playing,
50 *  so the parameters need to exist and do something appropriate in
51 *  order for the effect to function correctly.</p>
52 *
53 *  @mxml
54 *
55 *  <p>The <code>&lt;s:Wipe&gt;</code> tag
56 *  inherits all of the tag attributes of its superclass,
57 *  and adds the following tag attributes:</p>
58 *
59 *  <pre>
60 *  &lt;s:Wipe
61 *    <b>Properties</b>
62 *    id="ID"
63 *    direction="right"
64 *  /&gt;
65 *  </pre>
66 *
67 *  @see spark.effects.WipeDirection
68 *  @see spark.effects.AnimateTransitionShader
69 *  @see spark.effects.AnimateTransitionShader#shaderByteCode
70 *
71 *  @includeExample examples/WipeExample.mxml
72 *
73 *  @langversion 3.0
74 *  @playerversion Flash 10
75 *  @playerversion AIR 1.5
76 *  @productversion Flex 4
77 */
78public class Wipe extends AnimateTransitionShader
79{
80    [Embed(source="WipeUp.pbj", mimeType="application/octet-stream")]
81    private static var WipeUpShaderClass:Class;
82    private static var wipeUpShaderCode:ByteArray = new WipeUpShaderClass();
83    [Embed(source="WipeDown.pbj", mimeType="application/octet-stream")]
84    private static var WipeDownShaderClass:Class;
85    private static var wipeDownShaderCode:ByteArray = new WipeDownShaderClass();
86    [Embed(source="WipeRight.pbj", mimeType="application/octet-stream")]
87    private static var WipeRightShaderClass:Class;
88    private static var wipeRightShaderCode:ByteArray = new WipeRightShaderClass();
89    [Embed(source="WipeLeft.pbj", mimeType="application/octet-stream")]
90    private static var WipeLeftShaderClass:Class;
91    private static var wipeLeftShaderCode:ByteArray = new WipeLeftShaderClass();
92
93
94    [Inspectable(enumeration="left,right,up,down", defaultValue="right")]
95    /**
96     *  The direction that the wipe moves during the animation:
97     *  <code>WipeDirection.RIGHT</code>, <code>WipeDirection.LEFT</code>,
98     *  <code>WipeDirection.UP</code>, or <code>WipeDirection.DOWN</code>.
99     *
100     *  @default WipeDirection.RIGHT
101     *
102     *  @see WipeDirection#RIGHT
103     *  @see WipeDirection#UP
104     *  @see WipeDirection#LEFT
105     *  @see WipeDirection#DOWN
106     *
107     *  @langversion 3.0
108     *  @playerversion Flash 10
109     *  @playerversion AIR 1.5
110     *  @productversion Flex 4
111     */
112    public var direction:String = WipeDirection.RIGHT;
113
114    /**
115     *  Constructor.
116     *
117     *  @param target The Object to animate with this effect.
118     *
119     *  @langversion 3.0
120     *  @playerversion Flash 10
121     *  @playerversion AIR 1.5
122     *  @productversion Flex 4
123     */
124    public function Wipe(target:Object=null)
125    {
126        super(target);
127        // Note that we do not need a separate WipeInstance; the only
128        // addition that Wipe adds is specifying the Crossfade
129        // Pixel Bender shader, which is done at instance creation time,
130        // according to the value of the direction property.
131        // Everything else needed is in the superclass already.
132    }
133
134    /**
135     *  @private
136     */
137    override protected function initInstance(instance:IEffectInstance):void
138    {
139        switch (direction)
140        {
141            case WipeDirection.RIGHT:
142                shaderByteCode = wipeRightShaderCode;
143                break;
144            case WipeDirection.LEFT:
145                shaderByteCode = wipeLeftShaderCode;
146                break;
147            case WipeDirection.UP:
148                shaderByteCode = wipeUpShaderCode;
149                break;
150            case WipeDirection.DOWN:
151                shaderByteCode = wipeDownShaderCode;
152                break;
153        }
154        super.initInstance(instance);
155    }
156
157}
158}
159