1////////////////////////////////////////////////////////////////////////////////
2//
3//  ADOBE SYSTEMS INCORPORATED
4//  Copyright 2009 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.effects
13{
14import flash.geom.Vector3D;
15import flash.utils.Dictionary;
16
17import mx.core.IUIComponent;
18import mx.core.mx_internal;
19import mx.effects.CompositeEffect;
20import mx.effects.Effect;
21import mx.effects.IEffectInstance;
22import mx.effects.Parallel;
23import mx.effects.Sequence;
24import mx.events.EffectEvent;
25import mx.geom.TransformOffsets;
26import mx.styles.IStyleClient;
27
28import spark.core.IGraphicElement;
29import spark.effects.supportClasses.AnimateTransformInstance;
30
31use namespace mx_internal;
32
33//--------------------------------------
34//  Excluded APIs
35//--------------------------------------
36
37/**
38 *  The AnimateTransform3D effect extends the abilities of
39 *  the AnimateTransform effect to 3D transform properties. Like
40 *  AnimateTransform, this effect is not intended to be used directly,
41 *  but instead provides common functionality that is used by its
42 *  subclasses. To get 3D effects, use the subclasses Move3D, Rotate3D,
43 *  and Scale3D.
44 *
45 *  <p>As with AnimateTransform, there are some properties of this
46 *  affect that are shared with all other transform effects that it is
47 *  combined with at runtime. In particular, the projection-related properties
48 *  <code>applyLocalProjection</code>, <code>removeProjectionWhenComplete</code>,
49 *  <code>autoCenterProjection</code>, <code>fieldOfView</code>,
50 *  <code>focalLength</code>, <code>projectionX</code>, and
51 *  <code>projectionY</code> are all shared properties. Set these
52 *  properties similarly on all 3D effects that are combined in a composite
53 *  effect to get predictable results.</p>
54 *
55 *  @mxml
56 *
57 *  <p>The <code>&lt;s:AnimateTransform&gt;</code> tag
58 *  inherits all of the tag attributes of its superclass,
59 *  and adds the following tag attributes:</p>
60 *
61 *  <pre>
62 *  &lt;s:AnimateTransform
63 *    <b>Properties</b>
64 *    id="ID"
65 *    applyChangesPostLayout="true"
66 *    applyLocalProjection="false"
67 *    autoCenterProjection="true"
68 *    fieldOfView="no default"
69 *    focalLength="no default"
70 *    projectionX="0"
71 *    projectionY="0"
72 *    removeLocalProjectionWhenComplete="false"
73 *  /&gt;
74 *  </pre>
75 *
76 *  @see spark.effects.supportClasses.AnimateTransformInstance
77 *
78 *
79 *  @langversion 3.0
80 *  @playerversion Flash 10
81 *  @playerversion AIR 1.5
82 *  @productversion Flex 4
83 */
84public class AnimateTransform3D extends AnimateTransform
85{
86    include "../core/Version.as";
87
88    //--------------------------------------------------------------------------
89    //
90    //  Constructor
91    //
92    //--------------------------------------------------------------------------
93
94    /**
95     *  Constructor.
96     *
97     *  @param target The Object to animate with this effect.
98     *
99     *  @langversion 3.0
100     *  @playerversion Flash 10
101     *  @playerversion AIR 1.5
102     *  @productversion Flex 4
103     */
104    public function AnimateTransform3D(target:Object=null)
105    {
106        super(target);
107        instanceClass = AnimateTransformInstance;
108        applyChangesPostLayout = true;
109    }
110
111
112    //--------------------------------------------------------------------------
113    //
114    //  Properties
115    //
116    //--------------------------------------------------------------------------
117
118    //----------------------------------
119    //  applyChangesPostLayout
120    //----------------------------------
121    [Inspectable(category="General", enumeration="true,false")]
122    /**
123     *  Used by the subclasses of AnimateTransform to specify
124     *  whether the effect changes transform values used by the layout
125     *  manager, or whether it changes values used after layout is run.
126     *  Because the Flex layout system ignores 3D transformation properties,
127     *  this class overrides the <code>AnimateTransform.applyChangesPostLayout</code> property
128     *  to set the default value to <code>true</code> for 3D effects.
129     *
130     *  @default true
131     *
132     *  @langversion 3.0
133     *  @playerversion Flash 10
134     *  @playerversion AIR 1.5
135     *  @productversion Flex 4
136     */
137    override public function get applyChangesPostLayout():Boolean
138    {
139        return super.applyChangesPostLayout;
140    }
141
142    private var _applyLocalProjection:Boolean = true;
143    /**
144     *  If <code>true</code>, the effect creates a perspective projection
145     *  using the other projection-related properties in the effect
146     *  and applies it to the target component's parent when it starts playing.
147     *  By default, the projection is left on the parent when the effect finishes;
148     *  to remove the projection when the effect ends, set
149     *  <code>removeLocalProjectionWhenComplete</code> to <code>true</code>.
150     *
151     *  @see #removeLocalProjectionWhenComplete
152     *  @default true
153     *
154     *  @langversion 3.0
155     *  @playerversion Flash 10
156     *  @playerversion AIR 1.5
157     *  @productversion Flex 4
158     */
159    public function get applyLocalProjection():Boolean
160    {
161        return _applyLocalProjection;
162    }
163    public function set applyLocalProjection(value:Boolean):void
164    {
165        _applyLocalProjection = value;
166    }
167
168    /**
169     *  If <code>true</code>, the effect removes the perspective projection
170     *  from the target component's parent when it completes playing.
171     *  By default, the perspective projection is retained.
172     *
173     *  <p>This property is only used when <code>applyLocalProjection</code>
174     *  is set to <code>true</code>.</p>
175     *
176     *  @see #applyLocalProjection
177     *  @default false
178     *
179     *  @langversion 3.0
180     *  @playerversion Flash 10
181     *  @playerversion AIR 1.5
182     *  @productversion Flex 4
183     */
184    public var removeLocalProjectionWhenComplete:Boolean = false;
185
186    /**
187     *  Set to <code>false</code> to disable a 3D effect from automatically setting
188     *  the projection point to the center of the target.
189     *  You then use the <code>projectionX</code> and <code>projectionY</code> properties
190     *  to explicitly set the projection point
191     *  as the offset of the projection point from the (0, 0) coordinate of the target.
192     *
193     *  <p>The 3D effects work by mapping a three-dimensional image onto a two-dimensional
194     *  representation for display on a computer screen.
195     *  The projection point defines the center of the field of view,
196     *  and controls how the target is projected from three dimensions onto the screen.</p>
197     *
198     *  <p>This property is only used when <code>applyLocalProjection</code>
199     *  is set to <code>true</code>.</p>
200     *
201     *  @see #applyLocalProjection
202     *  @default true
203     *
204     *  @langversion 3.0
205     *  @playerversion Flash 10
206     *  @playerversion AIR 1.5
207     *  @productversion Flex 4
208     */
209    public var autoCenterProjection:Boolean = true;
210
211    /**
212     *  Specifies an angle, in degrees between <code>0</code> and <code>180</code>,
213     *  for the field of view in three dimensions.
214     *  This value determines how strong the perspective transformation and distortion apply to
215     *  a three-dimensional display object with a non-zero z-coordinate.
216     *
217     *  <p>A degree close to <code>0</code> means that the screen's two-dimensional x- and y-coordinates are
218     *  roughly the same as the three-dimensional x-, y-, and z-coordinates with little or
219     *  no distortion. In other words, for a small angle, a display object moving down the z axis appears
220     *  to stay near the same size and moves little. </p>
221     *
222     *  <p>A value close to <code>180</code> degrees results in a fisheye lens effect: positions
223     *  with a <code>z</code> value smaller than <code>0</code> are magnified, while positions with a
224     *  <code>z</code> value larger than <code>0</code> are minimized. With a large angle, a display object
225     *  moving down the z axis appears to change size quickly and moves a great distance. If the field of view
226     *  is set to <code>0</code> or <code>180</code>, nothing is seen on the screen.</p>
227     *
228     *  <p>This property is only used when <code>applyLocalProjection</code>
229     *  is set to <code>true</code>.</p>
230     *
231     *  @see #applyLocalProjection
232     *  @see flash.geom.PerspectiveProjection
233     *
234     *  @langversion 3.0
235     *  @playerversion Flash 10
236     *  @playerversion AIR 1.5
237     *  @productversion Flex 4
238     */
239    public var fieldOfView:Number;
240
241    /**
242     *  The distance between the eye or the viewpoint's origin (0,0,0)
243     *  and the display object located  in the z axis. During the perspective transformation,
244     *  the <code>focalLength</code> is calculated dynamically
245     *  using the angle of the field of view and the stage's aspect ratio (stage width divided by
246     *  stage height).
247     *
248     *  <p>This property is only used when <code>applyLocalProjection</code>
249     *  is set to <code>true</code>.</p>
250     *
251     *  @see #applyLocalProjection
252     *  @see flash.geom.PerspectiveProjection
253     *
254     *  @langversion 3.0
255     *  @playerversion Flash 10
256     *  @playerversion AIR 1.5
257     *  @productversion Flex 4
258     */
259    public var focalLength:Number;
260
261    /**
262     *  Sets the projection point
263     *  as the offset of the projection point in the x direction
264     *  from the (0, 0) coordinate of the target.
265     *  By default, when you apply a 3D effect, the effect automatically sets
266     *  the projection point to the center of the target.
267     *  You can set the <code>autoCenterProjection</code> property of the effect
268     *  to <code>false</code> to disable this default, and use the
269     *  <code>projectionX</code> and <code>projectionY</code> properties instead.
270     *
271     *  <p>This property is only used when <code>applyLocalProjection</code>
272     *  is set to <code>true</code>.</p>
273     *
274     *  @see #applyLocalProjection
275     *
276     *  @langversion 3.0
277     *  @playerversion Flash 10
278     *  @playerversion AIR 1.5
279     *  @productversion Flex 4
280     */
281    public var projectionX:Number = 0;
282
283    /**
284     *  Sets the projection point
285     *  as the offset of the projection point in the y direction
286     *  from the (0, 0) coordinate of the target.
287     *  By default, when you apply a 3D effect, the effect automatically sets
288     *  the projection point to the center of the target.
289     *  You can set the <code>autoCenterProjection</code> property of the effect
290     *  to <code>false</code> to disable this default, and use the
291     *  <code>projectionX</code> and <code>projectionY</code> properties instead.
292     *
293     *  <p>This property is only used when <code>applyLocalProjection</code>
294     *  is set to <code>true</code>.</p>
295     *
296     *  @see #applyLocalProjection
297     *
298     *  @langversion 3.0
299     *  @playerversion Flash 10
300     *  @playerversion AIR 1.5
301     *  @productversion Flex 4
302     */
303    public var projectionY:Number = 0;
304
305    //--------------------------------------------------------------------------
306    //
307    // Methods
308    //
309    //--------------------------------------------------------------------------
310
311    /**
312     * @private
313     *
314     * This is where we create the single instance and/or feed extra
315     * MotionPath information (from the transform-related effects) into the
316     * single transform effect instance.
317     */
318    override protected function initInstance(instance:IEffectInstance):void
319    {
320        super.initInstance(instance);
321
322        var transformInstance:AnimateTransformInstance =
323            AnimateTransformInstance(instance);
324
325        transformInstance.applyLocalProjection = applyLocalProjection;
326        transformInstance.removeLocalProjectionWhenComplete = removeLocalProjectionWhenComplete;
327        transformInstance.autoCenterProjection = autoCenterProjection;
328        transformInstance.fieldOfView = fieldOfView;
329        transformInstance.focalLength = focalLength;
330        transformInstance.projectionX = projectionX;
331        transformInstance.projectionY = projectionY;
332    }
333
334}
335}
336