AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzAnim.h
Go to the documentation of this file.
00001 #if !defined(_CCZ_ANIMATION_H_)
00002 #define _CCZ_ANIMATION_H_
00003 
00004 #include "CzUtil.h"
00005 #include "CzXoml.h"
00006 #include "CzEvents.h"
00007 
00008 class CzAnimInstance;
00009 class CzAnimTimeline;
00010 class CzAnimTimelinesManager;
00011 
00012 /**
00013  @addtogroup Animation
00014  @{
00015  */
00016  
00017 /**
00018  @typedef   float (*CzTweenEffect)(float)
00019 
00020  @brief CzTweenEffect - Animation tweening effect (used to tween between different frames).
00021  */
00022 
00023 typedef float (*CzTweenEffect)(float);
00024 
00025 /**
00026  @struct    CzAnimFrame
00027 
00028  @brief Animation frame data.
00029 
00030  Base class of specific animation frame data types:
00031  - CzAnimFrameBool
00032  - CzAnimFrameFloat
00033  - CzAnimFrameVec2
00034  - CzAnimFrameVec3
00035  - CzAnimFrameVec4
00036  - CzAnimFrameRect
00037  - CzAnimFrameString
00038 
00039  A CzAnim is built from a number of these key frames. A key frame is the state of a property of the animations target at a specific point in time.
00040 
00041  */
00042 
00043 struct CzAnimFrame
00044 {
00045     /**
00046      @enum  eAnimType
00047     
00048      @brief Values that represent different types of animations.
00049      */
00050     enum eAnimType
00051     {
00052         FT_Invalid,
00053         FT_Bool,
00054         FT_Float,
00055         FT_Vec2,
00056         FT_Vec3,
00057         FT_Vec4,
00058         FT_Rect,
00059         FT_String,
00060         FT_Custom,
00061     };
00062 
00063     /**
00064      @enum  eAnimEase
00065     
00066      @brief Values that represent different types of easing functions.
00067      */
00068     enum eAnimEase
00069     {
00070         AT_Linear, 
00071         AT_QuadIn, 
00072         AT_QuadOut, 
00073         AT_CubicIn, 
00074         AT_CubicOut, 
00075         AT_QuarticIn, 
00076         AT_QuarticOut, 
00077     };
00078 
00079     float               Time;                   ///< Time at which this frame should be active
00080     CzTweenEffect       EasingFunc;             ///< Easing function
00081 
00082     CzAnimFrame() : EasingFunc(NULL) {}
00083     virtual ~CzAnimFrame() {}
00084 
00085     void                setEasing(eAnimEase effect);
00086 };
00087 
00088 struct CzAnimFrameBool: public CzAnimFrame
00089 {
00090     bool    data;   //< Frame data
00091     CzAnimFrameBool() : CzAnimFrame() {}
00092 };
00093 
00094 struct CzAnimFrameFloat: public CzAnimFrame
00095 {
00096     float   data;   //< Frame data
00097     CzAnimFrameFloat() : CzAnimFrame() {}
00098 };
00099 
00100 struct CzAnimFrameVec2: public CzAnimFrame
00101 {
00102     CzVec2 data;    //< Frame data
00103     CzAnimFrameVec2() : CzAnimFrame() {}
00104 };
00105 
00106 struct CzAnimFrameVec3: public CzAnimFrame
00107 {
00108     CzVec3 data;    //< Frame data
00109     CzAnimFrameVec3() : CzAnimFrame() {}
00110 };
00111 
00112 struct CzAnimFrameVec4: public CzAnimFrame
00113 {
00114     CzVec4 data;    //< Frame data
00115     CzAnimFrameVec4() : CzAnimFrame() {}
00116 };
00117 
00118 struct CzAnimFrameRect: public CzAnimFrame
00119 {
00120     CzIRect data;   //< Frame data
00121     CzAnimFrameRect() : CzAnimFrame() {}
00122 };
00123 
00124 struct CzAnimFrameString: public CzAnimFrame
00125 {
00126     CzString data;  //< Frame data
00127     CzAnimFrameString() : CzAnimFrame() {}
00128 };
00129 
00130 /**
00131  @class IzAnimTarget
00132 
00133  @brief An animation target object.
00134 
00135  Classes that derive from IzAnimTarget and implement UpdateFromAnimation() can have properties that can be the target of an animation. For example CzActor derives from IzAnimTarget and 
00136  implements CzActor:: UpdateFromAnimation(). This enables animations to target their properties such as position, angle, scale etc.. using timelines.
00137 
00138  */
00139 
00140 class IzAnimTarget
00141 {
00142 public:
00143     virtual bool    UpdateFromAnimation(CzAnimInstance *animation) = 0;
00144 };
00145 
00146 /**
00147  @class CzAnim
00148 
00149  @brief A collection of animation frames.
00150 
00151  <h1>Introduction</h1>
00152  There are plenty of great games and apps out there that do not feature any form of animation. However, most modern games do feature animations to enhance their 
00153  look and feel. Lets take "Angry Birds" as an example, Angry Birds uses animations all over the place, such as the animating birds  and pigs, even the menus 
00154  contain flashing and sweeping animations. 
00155 
00156  When we initially decided to implement an animation system we decided that it had to be very flexible and support any type of animation, be it animating the 
00157  position of an actor, animating the graphical frames of an actor or even animating a list of commands for an actor. From AppEasy's point of view, animation 
00158  refers to any variable or set of variables that can change over time.
00159 
00160  The AppEasy animation system currently supports the following features:
00161  - Time based frame and interpolated named animations
00162  - Delayed and looped animations
00163  - Support for boolean, float, vectors (2d, 3d and 4d), rect (for image frames), string and custom frame data types
00164  - Resource manager that tracks and manages sets of animations (scene local and global)
00165  - Animation data re-use using animation instances
00166  - Animation time lines to support multiple simultaneous animations that can target object specific properties such as the colour of a scene or the position 
00167  of an actor
00168  - Time line manager that tracks and manages sets of animation time lines
00169  - Callback notifications for animation instance started, stopped and looped events
00170  - Animations and animation time lines can be defined and attached to actors and scenes using XOML
00171  - Support for OnStart, OnEnd and OnRepeat events in code and in XOML
00172  - Linear, quadratic, quartic and cubic in and out easing
00173 
00174  The animation system is split into the following classes:
00175  - CzAnimFrame - Base animation frame class
00176  - IzAnimTarget - Interface for classes that act as an animtion target
00177  - CzAnim - A basic animation
00178  - CzAnimCreator - Class used to instsntiate an animation from XOML
00179  - CzAnimManager - Manages a collection of animations
00180  - CzAnimInstance - An instantiated running animation
00181  - CzAnimTimeline - A collection of running animation instances
00182  - CzAnimTimelineCreator - Class used to instantiate a collection of running animations from XOML
00183  - CzAnimTimelinesManager - Manages a collection of timelines
00184 
00185  <h1>Animation Frame Data</h1>
00186  Animation frame data is the backbone of all animations, it represents the actual discrete state of a variable at a given point in time (called a key frame). 
00187  An animation frame consists of two components:
00188  - Frame data - Frame data is the value or values of a specific variable at a specific point in time
00189  - Frame time - The time at which the frame has its value (in seconds)
00190 
00191  The base class for all animation frame data types is the CzAnimFrame. This class provides a means for the developer to implement their own custom animation 
00192  frame data types. The following animation frame data types are already implemented:
00193  - CzAnimFrameBool - Boolean variables such as actor visbility
00194  - CzAnimFrameFloat - Floating point variables such as angle and scale
00195  - CzAnimFrameVec2 - Floating point 2 parameter variables such as 2D position and velocity
00196  - CzAnimFrameVec3 - Floating point 2 parameter variables such as 3D position and velocity
00197  - CzAnimFrameVec4 - Floating point 4 parameter variables such as colour
00198  - CzAnimFrameRect - Integer 4 parameter variables such as image source rectangles
00199  - CzAnimFrameString - String based parameters such as narrative text, commands or even other timeline's
00200 
00201  <h1>Animations and the Resource Manager</h1>
00202  The resource manager is used to manage a group of resources (animations). The idea is that you create a group of animations then add them to the resource 
00203  manager and then forget about them. The resource manager will take care of cleaning them up when the scene or  main app is destroyed. The main app object 
00204  contains its own global resource manager whilst all scenes contain their own local resource manager.
00205 
00206  Note that when animations are created via XOML mark-up they are added to the resource manager. Animations that are created inside a scene will be added to the 
00207  scenes resource manager, whilst animations created outside of the scene will be added to the global resource manager.
00208 
00209  To find an animation within a scenes resource manager you would use could such as:
00210 
00211  @code
00212 CzAnim* anim = (CzAnim*)scene->getResourceManager()->findResource("Player1Anim", CzHashes::Animation_Hash);
00213  @endcode
00214 
00215  Note that if the animation is not found within the scene then the system will automatically search the global resource manager for the animation. You can 
00216  prevent this global search by passing false as the third parameter to findResource().
00217 
00218  Timelines are stored in the timelines manager of a scene, actor or the global time lines manager, depending on where they are declared.
00219 
00220  <h1>Animation Instances</h1>
00221  CzAnim is basically used as a means to store the animation data in a convenient place. With this in mind you do not play a CzAnim directly, instead you 
00222  create an instance of it using CzAnimInstance:
00223 
00224  @code
00225 // Create and set up an animation
00226 CzAnimInstance* face_anim = new CzAnimInstance();
00227 face_anim->setAnimation(anim);
00228 face_anim->setTarget(actor, "SrcRect");
00229  @endcode
00230 
00231  Note the following line of code:
00232 
00233  @code
00234 face_anim->setTarget(actor, "SrcRect");
00235  @endcode
00236 
00237  This line of code tells the animation to modify the "SrcRect" (the actors image atlas position) property of the actor object, causing the image to change.
00238 
00239  Animation instances can be played, paused, resumed, stopped and restarted. You can also tell an animation to delay playing for a finite period of time. 
00240 
00241  <h1>Animation Targets and Target properties</h1>
00242  
00243  AppEasy Core uses the concept of animation targets and animation target properties. An animation target is basically a class that contains a variable or 
00244  group of variables that can be targeted for modification by an animation. The actual variable or variables that are targeted are called target properties. 
00245  An example target would be an actor and example target property would be the actors position. When you create an instance of an animation you set the target 
00246  and target property that the animation will modify using code similar to that shown below:
00247 
00248  @code
00249 face_anim->setTarget(actor, "SrcRect");
00250  @endcode
00251 
00252  Any class can be used as a target for animation as long as it derives from the IzAnimTarget interface and implements the the following pure virtual method:
00253 
00254  @code
00255     virtual bool    UpdateFromAnimation(CzAnimInstance *animation) = 0;
00256  @endcode
00257 
00258  When the animation updates it will call back this method passing in its data asking the method to update the state of the object. Both scene and actor classes 
00259  already have this functionality implemented.
00260 
00261  Lets take a quick look at a small section of CzScene::UpdateFromAnimation() to see how the CzScene class has implemented this method:
00262 
00263  @code
00264 bool CzScene::UpdateFromAnimation(CzAnimInstance *animation)
00265 {
00266     unsigned int property_name = animation->getTargetPropertyHash();
00267     bool delta = animation->isDelta();
00268 
00269     if (Camera != NULL)
00270     {
00271         if (property_name == CzHashes::Position_Hash)
00272         {
00273             CzAnimFrameVec2* frame = (CzAnimFrameVec2*)animation->getCurrentData();
00274             if (delta)
00275             {
00276                 CzVec2 pos = Camera->getPosition();
00277                 pos.x += frame->data.x;
00278                 pos.y += frame->data.y;
00279                 Camera->setPosition(pos.x, pos.y);
00280             }
00281             else
00282                 Camera->setPosition(frame->data.x, frame->data.y);
00283             return true;
00284         }
00285         else
00286         if (property_name == CzHashes::Angle_Hash)
00287         {
00288             CzAnimFrameFloat* frame = (CzAnimFrameFloat*)animation->getCurrentData();
00289             if (delta)
00290                 Camera->setAngle(Camera->getAngle() + frame->data);
00291             else
00292                 Camera->setAngle(frame->data);
00293             return true;
00294         }
00295         else
00296         if (property_name == CzHashes::Scale_Hash)
00297         {
00298             CzAnimFrameFloat* frame = (CzAnimFrameFloat*)animation->getCurrentData();
00299             if (delta)
00300                 Camera->setScale(Camera->getScale() + frame->data);
00301             else
00302                 Camera->setScale(frame->data);
00303             return true;
00304         }
00305     }
00306 
00307     return false;
00308 }
00309  @endcode
00310 
00311  The logic is quite simple, we check the name of the property that was passed in by the animation instance then check that against known property names of 
00312  the class. If it matches then we move the animation data from the animation instance into our classes local variable.
00313 
00314  As you can see implementing your own custom animation targets is a simple case of:
00315  - Deriving your class from  IzAnimTarget
00316  - Implement the  UpdateFromAnimation(CzAnimInstance *animation) method
00317 
00318  <h1>Animation Timeline's</h1>
00319  
00320  An animation time line is basically a way to group together multiple animation instances and play, pause, stop and resume them all together. The general 
00321  idea is that you create an animation time line then create animation instances and add them to the time line. You then attach the time line to your destination 
00322  object, be that a scene or an actor. The animation system will then take care of the rest for you. Here is an example showing how to create and use a time line:
00323 
00324 @code
00325 // Find our face animation
00326 CzAnim* face_anim = (CzAnim*)scene->getResourceManager()->findResource("FaceAnim", CzHashes::Animation_Hash);
00327 
00328 // Create and set up our animation instance
00329 CzAnimInstance* instance = new CzAnimInstance();
00330 instance->setAnimation(face_anim);
00331 instance->setTarget(actor, "SrcRect");
00332 timeline->addAnimation(instance);
00333 timeline->play();
00334 
00335 // Create an animation timeline to hold our image animation
00336 CzAnimTimeline* timeline = new CzAnimTimeline();
00337 timeline->addAnimation(instance);
00338 
00339 // Attach timeline to the actor
00340 actor->setTimeline(timeline);
00341  @endcode
00342 
00343  Defining and attaching animations is much easier and more intuitive if done declaratively using XOML mark-up. More on this this later
00344 
00345  Note that when you attach an animation time line to a scene or an actor, the scene / actor will automatically take over updating it for you.
00346 
00347  Time lines can be played, paused, resumed and stopped. All animation instances within the animation time line will be affected. 
00348 
00349  <h1>Resource Manager and Timelines</h1>
00350  
00351  The resource manager is generally responsible for managing the lifetimes of animations and animation time lines, in particular those created from XOML mark-up. 
00352 
00353  Each scene has its own local resource manager as well as a global resource manager. 
00354 
00355  <h1>Working with Animations</h1>
00356  
00357  The general work flow when working with the animation system has two potential paths:
00358  - Manual definition - You manually create all of the animation frames, animation classes, instances, timelines etc in code
00359  - XOML definition - You load a XOML file that contains the definitions, find the time lines and attach
00360 
00361  The first method is more difficult as it does require creatng and setting up animation classes yourself. Heres the basic flow for manual animation setup:
00362  - Create a CzAnim object and give it a meaningful name
00363  - Create and set-up animation frames
00364  - Add animation frames to the CzAnim object
00365  - Add the CzAnim object to the scene or global CzAnimManager
00366  - Later when you need to create an instance of the animation, search the animation manager for the animation by name
00367  - Create a CzAnimTimeline object
00368  - Create a CzAnimInstance object and attach the  CzAnim object
00369  - Set up any additional paramaters for the time line object
00370  - Add the time line object to the scene or global time line manager (not essential as scenes and actors can clean them up for you)
00371  - Set the actor or scenes time line using setTimeline()
00372  - Call the time line's play() method to start the time line playing
00373 
00374  The second method using XOML is much simpler:
00375  - Create a XOML file 
00376  - Add Animation and Timeline definitions
00377  - If your scene / actor is also defined in XOML then you simply set the Timeline property to the name of the timline and you are done. If not then continue 
00378  onto the next step
00379  - Search the scenes timelines for our named time line
00380  - Set the actor or scenes time line using setTimeline()
00381  - Call the time line's play() method to start the time line playing
00382 
00383 
00384  <h1>Creating a Basic Animation in Code</h1>
00385  
00386  AppEasy supports a number of different types of animation as previously explained. In our example we are going to create a basic floating point animation 
00387  that animates the rotation property of an actor object. 
00388 
00389 @code
00390 // Create an animation
00391 CzAnim* anim = new CzAnim();
00392 anim->setName("TestAnim");
00393 anim->setDuration(3);
00394 anim->setType(CzAnimFrame::FT_Float);
00395 
00396 // Create and add frames
00397 CzAnimFrameFloat* frame = new CzAnimFrameFloat();
00398 frame->Time = 0;
00399 frame->data = 0;
00400 anim->addFrame(frame);
00401 frame = new CzAnimFrameFloat();
00402 frame->Time = 1;
00403 frame->data = 45;
00404 anim->addFrame(frame);
00405 frame = new CzAnimFrameFloat();
00406 frame->Time = 2;
00407 frame->data = 90;
00408 anim->addFrame(frame);
00409 
00410 // Create animation instance
00411 CzAnimInstance* instance = new CzAnimInstance();
00412 instance->setAnimation(anim);
00413 instance->setDelay(0);
00414 instance->setRepeatCount(0);
00415 instance->setTarget(actor, "Angle");
00416 
00417 // Creata a time line
00418 CzAnimTimeline* timeline = new CzAnimTimeline();
00419 timeline->setName("Timeline1");
00420 timeline->addAnimation(instance);
00421 
00422 // Play the timeline
00423 timeline->play();
00424 
00425 // Attach timeline to the actor
00426 actor->setTimeline(timeline);
00427  @endcode
00428 
00429  As you can see it is a little verbose, which is why we recommend using XOML mark-up for defining animations in particular.
00430 
00431  <h1>Creating a Basic Animation in XOML</h1>
00432  
00433  XOML is AppEasy's mark-up language that can be used to define and set-up actors, scenes, resource, animations and other game elements. Here is an example 
00434  showing how to set up the previous example using XOML syntax:
00435 
00436  @code
00437 <xml>
00438     <Animation Name="TestAnim" Type="float" Duration="3" >
00439         <Frame Value="0"   Time="0.0" />
00440         <Frame Value="45"  Time="1.0" />
00441         <Frame Value="90"  Time="2.0" />
00442     </Animation>
00443     <Timeline Name="Timeline1" AutoPlay="true">
00444         <Animation Anim="TestAnim" Target="Angle" Repeat="0" StartAtTime="0"/>
00445     </Timeline>
00446 </xml>
00447 
00448  @endcode
00449 
00450  As you can see it is incredibly easy to set up animations and time line's using XOML syntax.
00451 
00452  <b>XOML Anim tag properties</b>
00453  - Name (string) - Name of this animation resource
00454  - Tag (string) - Resource tag (used to group resources together)
00455  - Type (type) - The type of animation frame data, can be one of the following:
00456   - bool
00457   - float
00458   - vec2
00459   - vec3
00460   - vec4
00461   - rect
00462   - string
00463  - Duration (seconds) - The duration of the animation
00464 
00465  Type and Duration are required properties
00466 
00467  <b>XOML Anim Frame tag properties</b>
00468  - Time (seconds) - The time at which this frame is available
00469  - Value (any supported type) - The value of the frame at the above time. The value here depends on the type of animation that was defined. For example, 
00470  if you declared the animation as a string type then this value should contain a string. If you declared the animation as a vec2 then the value should 
00471  contain pairs of values
00472  - Easing (easing) - Type of easing to use, supported easing types include:
00473   - linear
00474   - quadin
00475   - quadout
00476   - cubicin
00477   - cubicout
00478   - quarticin
00479   - quarticout
00480 
00481  Time and Value are required properties
00482 
00483  <b>XOML Timeline tag properties</b>
00484  - Name (string) - Name of this animation timeline resource
00485  - Tag (string) - Resource tag (used to group resources together)
00486  - AutoPlay (boolean) - When set to true the timeline will begin animating as soon as it is attached to an actor or scene 
00487  - TimeScale (number) - This property can be used to change the speed at which the timelines animations are played back. For example, if we set this value 
00488  to 2.0 then the animations in the previous example would play back twice as quickly. This feature allows us to speed up and slow down animations without 
00489  having to create new instances of them
00490  - Local (boolean) - By default timelines declared inside an actor will be local to the actor and not the scene. By setting Local=”false” the timeline will 
00491  be placed into the containing scene instead. This is useful if you want to show a group of timeline across different actors but do not want to move the 
00492  timeline definition into the scene or global resource manager
00493 
00494  Timelines also contain child Animation tags which define which animations will appear in the timeline. Lets take a look at the properties of this inner tag:
00495  - Anim (animation) - Names an animation to be included into the timeline
00496  - Target - Sets the objects target property that should be updated by the animation. For example, Position would target an actor scene position updating 
00497  its position
00498  - Repeat (number) - The number of times that the animation should repeat before stopping (0 represents play forever, which is the default)
00499  - StartAtTime (seconds) - Setting this parameter will delay the start of the animation 
00500  - Delta (boolean) - When set to true, instead of directly setting the target objects property it adds to it instead (called delta animations)
00501  - Interpolate (boolean) - When set true (which id default) animation frames will be smoothly interpolated from one key frame to the next. When set to false 
00502  animation frames will suddenly switch when their time marker is reached. For most animation you will want to use interpolation, however some kinds of 
00503  animations are not suited to interpolation, for example, image sprite animations
00504  - OnStart (actions list) - Defines an actions list that will be called when this animation starts playing (only called for animations with a StartAtTime 
00505  value that is not 0
00506  - OnEnd (actions list) - Defines an actions list that will be called when this animation ends
00507  - OnRepeat (actions list) - Defines an actions list that will be called when this animation repeats
00508 
00509  Anim and Target are required properties
00510 
00511  Note that a time line can be assigned to as many objects you like but the time line will be played back the same on all objects. This is very useful if you 
00512  have a group of actors that need to run the same animations synchronously.
00513 
00514  <h1>Creating an Image Animation</h1>
00515  
00516  We are now going to take a look at creating an image based animation that we can attach to an actor:
00517 
00518  @code
00519 // Create an animation
00520 CzAnim* anim = new CzAnim();
00521 anim->setName("TestAnim");
00522 anim->setDuration(0.8f);
00523 anim->GenerateAtlasFrames(8, 36, 40, 0, 0, 512, 40, 512, 0.1f);
00524 
00525 // Create animation instance
00526 CzAnimInstance* instance = new CzAnimInstance();
00527 instance->setAnimation(anim);
00528 instance->setDelay(0);
00529 instance->setRepeatCount(0);
00530 instance->setTarget(actor, "SrcRect");
00531 
00532 // Creata a time line
00533 CzAnimTimeline* timeline = new CzAnimTimeline();
00534 timeline->setName("Timeline1");
00535 timeline->addAnimation(instance);
00536 
00537 // Play the timeline
00538 timeline->play();
00539 
00540 // Attach timeline to actor
00541 actor->setTimeline(timeline);
00542  @endcode
00543 
00544  Setting up an image based animation is a little simpler because the CzAnim::GenerateAtlasFrames() method() automates the generation of frames for us. 
00545 
00546  Although the same can also be done in XOML which is even simpler, e.g:
00547 
00548  @code
00549 <Animation Name="TestAnim" Type="rect" Duration="0.8" >
00550     <Atlas Count="8" Duration="0.1" Pitch="36, 40" Size="36, 40" Width="36" />
00551 </Animation>
00552 <Timeline Name="Timeline1" AutoPlay="true">
00553     <Animation Anim="TestAnim" Target="SrcRect" Repeat="0" StartAtTime="0"/>
00554 </Timeline>
00555  @endcode
00556 
00557  The properties for the Atlas tag are as follows:
00558  - Count (number) - Number of frames to generate
00559  - Duration (seconds) - The amount of time to display each frame
00560  - Pitch (x, y) - The amount to step across and and right to get to the next frame in pixels
00561  - Size (x, y) - The width and height of each animation frame in pixels
00562  - Width (number) - The width of the image atlas in pixels
00563  - Position (x, y) - The position on the atlas where frames should start being taken from
00564 
00565  */
00566 
00567 class CzAnim : public IzXomlResource
00568 {
00569 public:
00570 
00571     /**
00572      @enum  eAnimStatus
00573     
00574      @brief Values that represent the current state of the animation.
00575      */
00576     enum eAnimStatus
00577     {
00578         AS_Stopped, //< Animation has stopped playing
00579         AS_Playing, //< Animation is playing
00580         AS_Paused,  //< Animation is paused
00581     };
00582     typedef CzVector<CzAnimFrame*>::iterator _Iterator;
00583     _Iterator begin()                   { return Frames.begin(); }
00584     _Iterator end()                     { return Frames.end(); }
00585 
00586 protected:
00587     // Properties
00588     CzAnimFrame::eAnimType      Type;                       ///< Type of animation
00589     float                       Duration;                   ///< Duration of animation
00590     CzVector<CzAnimFrame*>      Frames;                     ///< Animation frames
00591     int                         Category;                   ///< User defined category
00592     bool                        AutoDelete;                 ///< If set to true thenm timeline will be deleted when finished
00593 
00594 public:
00595     void                        setType(CzAnimFrame::eAnimType type)            { Type = type; }
00596     CzAnimFrame::eAnimType      getType() const                                 { return Type; }
00597     float                       getDuration() const                             { return Duration; }
00598     void                        setDuration(float duration)                     { Duration = duration; }
00599     void                        addFrame(CzAnimFrame* frame);
00600     bool                        getCurrentFrame(CzAnimFrame** current, CzAnimFrame** next, float current_time);
00601     void                        CalculateCurrentData(float current_time, CzAnimFrame* current_data, bool interpolate = true);
00602     int                         getFrameCount()                                 { return Frames.size(); }
00603     CzAnimFrame*                getFrame(int index)                             { return Frames[index]; }
00604     void                        setCategory(int category)                       { Category = category; }
00605     int                         getCategory() const                             { return Category; }
00606     void                        setAutoDelete(bool enable)                      { AutoDelete = enable; }
00607     bool                        isAutoDelete() const                            { return AutoDelete; }
00608     // Properties end
00609 
00610 public:
00611     CzAnim() : IzXomlResource(), Duration(0), Category(0), AutoDelete(false) { setClassType("animation"); }
00612     virtual ~CzAnim()
00613     {
00614         for (_Iterator it = Frames.begin(); it != Frames.end(); it++)
00615         {
00616             delete (*it);
00617         }
00618         Frames.clear();
00619     }
00620 
00621     void                GenerateAtlasFrames(int count, int frame_w, int frame_h, int start_x, int start_y, int pitch_x, int pitch_y, int image_width, float frame_speed);
00622 
00623     // Implementation of IzXomlClass interface
00624     int                 LoadFromXoml(IzXomlResource* parebt, bool load_children, CzXmlNode* node);
00625 };
00626 
00627 /**
00628  @class CzAnimCreator
00629 
00630  @brief Creates an instance of an CzAnim object.
00631 
00632  CzAnimCreator enables animations to be instantiated from XOML.
00633 
00634  */
00635 
00636 class CzAnimCreator : public IzXomlClassCreator
00637 {
00638 public:
00639     CzAnimCreator()
00640     {
00641         setClassName("animation");
00642     }
00643     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzAnim(); }
00644 };
00645 
00646 /**
00647  @class CzAnimInstance
00648 
00649  @brief An instance of an animation object.
00650 
00651  CzAnim is not played directly, instead you create an instance of it using CzAnimInstance:
00652 
00653  @code
00654 // Create and set up an animation
00655 CzAnimInstance* face_anim = new CzAnimInstance();
00656 face_anim->setAnimation(anim);
00657 face_anim->setTarget(actor, "SrcRect");
00658  @endcode
00659 
00660  Note the following line of code:
00661 
00662  @code
00663 face_anim->setTarget(actor, "SrcRect");
00664  @endcode
00665 
00666  This line of code tells the animation to modify the "SrcRect" (the actors image atlas position) property of the actor object, causing the image to change.
00667 
00668  Animation instances can be played, paused, resumed, stopped and restarted. You can also tell an animation to delay playing for a finite period of time. 
00669 
00670  */
00671 
00672 class CzAnimInstance
00673 {
00674 public:
00675 protected:
00676     // Properties
00677     CzAnimTimeline*         Parent;                 ///< Parent timeline
00678     CzAnim*                 Animation;              ///< Animation to use
00679     bool                    Managed;                ///< True if managed by a CzAnimInstanceManager
00680     int                     RepeatCount;            ///< Number of times to replay the animation
00681     float                   CurrentTime;            ///< Current animation time (0 is start of animation)
00682     CzAnimFrame*            CurrentData;            ///< The current interpolated data for the current time
00683     CzAnim::eAnimStatus     Status;                 ///< Status of the animation
00684     bool                    Started;                ///< If set to true then the animation has started playing
00685     IzAnimTarget*           Target;                 ///< Target object to update
00686 #if defined(_DEBUG)
00687     CzString                TargetProperty;         ///< Target object property name to update
00688 #endif
00689     unsigned int            TargetPropertyHash;     ///< Target object property name as a string hash to update
00690     float                   Delay;                  ///< Amount of time to delay starting the animation
00691     bool                    DelayExpired;           ///< true if initial delay has expired
00692     CzCallback              StartedCallback;        ///< Callback which is called when the animation starts playing
00693     CzCallback              StoppedCallback;        ///< Callback which is called when the animation stops playing
00694     CzCallback              LoopedCallback;         ///< Callback which is called when the animation loops
00695     bool                    CurrentDataValid;       ///< True if current frame data is valid
00696     bool                    IsDelta;                ///< Delta animation should update the target variables value instead of replacing it
00697     bool                    Interpolate;            ///< If true then the interpolated valiue between key frames will be calculated and applied
00698     CzEventManager*         EventsManager;          ///< List of events that the animation handles
00699 
00700 public:
00701     void                setParent(CzAnimTimeline* parent)           { Parent = parent; }
00702     CzAnimTimeline*     getParent()                                 { return Parent; }
00703     CzAnim*             getAnimation()                              { return Animation; }
00704     void                setAnimation(CzAnim* anim);
00705     void                setManaged(bool managed)                    { Managed = managed; }
00706     bool                isManaged() const                           { return Managed; }
00707     int                 getRepeatCount() const                      { return RepeatCount; }
00708     void                setRepeatCount(int repeat_count)            { RepeatCount = repeat_count; }
00709     void                setCurrentTime(float current_time)          { CurrentTime = current_time; }
00710     float               getCurrentTime() const                      { return CurrentTime; }
00711     bool                isFinished() const                          { if (RepeatCount == 0) return false; else return RepeatedCount >= RepeatCount; }
00712     CzAnimFrame*        getCurrentData()                            { return CurrentData; }
00713 #if defined(_DEBUG)
00714     CzString&           getTargetProperty()                         { return TargetProperty; }
00715 #endif
00716     unsigned int        getTargetPropertyHash()                     { return TargetPropertyHash; }
00717     IzAnimTarget*       getTargetElement()                          { return Target; }
00718     void                setTarget(IzAnimTarget* element, const char* property_name)
00719     {
00720         Target = element;
00721 #if defined(_DEBUG)
00722         TargetProperty = property_name;
00723 #endif
00724         TargetPropertyHash = CzString::CalculateHash(property_name);
00725     }
00726     void                setTargetElement(IzAnimTarget* element) { Target = element; }
00727     float               getDelay() const                                { return Delay; }
00728     void                setDelay(float delay)                           { Delay = delay; }
00729     bool                isStarted() const                               { return Started; }
00730     bool                isStopped() const                               { return Status == CzAnim::AS_Stopped; }
00731     bool                isPlaying() const                               { return Status == CzAnim::AS_Playing; }
00732     bool                isPaused() const                                { return Status == CzAnim::AS_Paused; }
00733     bool                isDelayed() const                               { return !DelayExpired; }
00734     void                restart()                                       { Status = CzAnim::AS_Playing; CurrentTime = 0; DelayExpired = false; RepeatedCount = 0; Started = true; }
00735     void                play()                                          { Status = CzAnim::AS_Playing; Started = true; }
00736     void                stop()                                          { Status = CzAnim::AS_Stopped; CurrentTime = 0; DelayExpired = false; RepeatedCount = 0; }
00737     void                pause()                                         { Status = CzAnim::AS_Paused; }
00738     void                setStartedCallback(CzCallback callback)         { StartedCallback = callback; }
00739     void                setStoppedCallback(CzCallback callback)         { StoppedCallback = callback; }
00740     void                setLoopedCallback(CzCallback callback)          { LoopedCallback = callback; }
00741     bool                isCurrentDataValid() const                      { return CurrentDataValid; }
00742     void                setDelta(bool is_delta)                         { IsDelta = is_delta; }
00743     bool                isDelta() const                                 { return IsDelta; }
00744     void                setInterpolate(bool interpolate)                { Interpolate = interpolate; }
00745     bool                isInterpolated() const                          { return Interpolate; }
00746     void                addEventsManager();
00747     CzEventManager*     getEventsManager()                              { return EventsManager; }
00748     // Properties end
00749 
00750 protected:
00751     int                 RepeatedCount;
00752 
00753 public:
00754     CzAnimInstance() : Parent(NULL), Managed(false), Animation(NULL), RepeatCount(0), CurrentTime(0), RepeatedCount(0), Delay(0), DelayExpired(false), Started(false), Status(CzAnim::AS_Stopped), CurrentDataValid(false), 
00755                             StartedCallback(NULL), StoppedCallback(NULL), LoopedCallback(NULL), IsDelta(false), Interpolate(true), EventsManager(NULL), CurrentData(NULL), Target(NULL), TargetPropertyHash(0) { }
00756     virtual ~CzAnimInstance();
00757 
00758     virtual bool        Update(float dt, IzAnimTarget* target = NULL);  // Passing none NULL for target allows you to retarget the animation update to another object
00759     virtual void        UpdateTargetOnly(IzAnimTarget* target);
00760     virtual void        ForceUpdateTargetOnly(IzAnimTarget* target);
00761 
00762     // Event handlers
00763     virtual void        ProcessEventActions(unsigned int event_name);
00764     virtual void        NotifyStart();      ///< This event is called when this aimation instance is started
00765     virtual void        NotifyEnd();        ///< This event is called when this aimation instance stopped playing
00766     virtual void        NotifyRepeat();     ///< This event is called when this aimation instance repeats
00767 };
00768 
00769 /**
00770  @class CzAnimTimeline
00771 
00772  @brief CzAnimTimeline - An animation timeline.
00773 
00774  An animation time line is basically a way to group together multiple animation instances and play, pause, stop and resume them all together. The general 
00775  idea is that you create an animation time line then create animation instances and add them to the time line. You then attach the time line to your destination 
00776  object, be that a scene or an actor. The animation system will then take care of the rest for you. Here is an example showing how to create and use a time line:
00777 
00778  @par XOML Example
00779  @code
00780 <Animation Name="ang_anim" Duration="5" Type="float">
00781     <Frame Time="0" Value="0" />
00782     <Frame Time="2.5" Value="180" />
00783     <Frame Time="5" Value="0" />
00784 </Animation>
00785 <Timeline Name="spin_anim" AutoPlay="true">
00786     <Animation Anim="ang_anim" Repeat="0" Target="Angle" />
00787 </Timeline>
00788 <Label Font="serif" Text="Hello" Timeline="spin_anim" />
00789  @endcode
00790 
00791  @par Code Example
00792 @code
00793 // Create angle animation
00794 CZ_NEW_ANIM(ang_anim, "ang_anim", 5, CzAnimFrame::FT_Float);
00795 CZ_NEW_ANIM_FRAME_FLOAT(ang_anim, 0,    0,          CzAnimFrame::AT_Linear);
00796 CZ_NEW_ANIM_FRAME_FLOAT(ang_anim, 2.5,  180,        CzAnimFrame::AT_Linear);
00797 CZ_NEW_ANIM_FRAME_FLOAT(ang_anim, 5,    0,          CzAnimFrame::AT_Linear);
00798 scene->getResourceManager()->addResource(ang_anim);
00799 // Create animation timeline
00800 CZ_NEW_TIMELINE(spin_anim, "spin_anim", ang_anim, 0, true, 0, "Angle");
00801 label->getTimelinesManager()->addTimeline(spin_anim);
00802 
00803 // Assign timeline to scene and start the animation
00804 scene->setTimeline(spin_anim);
00805 spin_anim->restart();
00806   @endcode
00807 
00808  In the above examples we create an animation then assign it to a timeline. We then assign the timeline to the label which causes it to spin over 5 seconds.
00809 
00810  Defining and attaching animations is much easier and more intuitive if done declaratively using XOML mark-up. 
00811 
00812  Note that when you attach an animation time line to a scene or an actor, the scene / actor will automatically take over updating it for you.
00813 
00814  Time lines can be played, paused, resumed and stopped. All animation instances within the animation time line will be affected. 
00815 
00816  */
00817 
00818 class CzAnimTimeline : public IzXomlResource
00819 {
00820 public:
00821     typedef CzList<CzAnimInstance*>::iterator _Iterator;
00822     _Iterator begin()                       { return Animations.begin(); }
00823     _Iterator end()                         { return Animations.end(); }
00824 
00825 protected:
00826     // Properties
00827     CzAnimTimelinesManager*     Manager;        ///< Timeline manager that manages this timeline
00828     IzXomlResource*             Parent;         ///< Parent container TODO: REMOVE Parent, this is stored in Container in IzXomlResource
00829     CzList<CzAnimInstance*>     Animations;     ///< Animation intsnces
00830     float                       TimeScale;      ///< How to scale time (1 - no change, > 1 speed up time, < 1 slow down time)
00831     bool                        AutoDelete;     ///< If set to true thenm timeline will be deleted when finished
00832 public:
00833     void                        setManager(CzAnimTimelinesManager* manager) { Manager = manager; }
00834     CzAnimTimelinesManager*     getManager()                            { return Manager; }
00835     void                        setParent(IzXomlResource* parent)       { Parent = parent; }
00836     IzXomlResource*             getParent()                             { return Parent; }
00837     void                        addAnimation(CzAnimInstance* anim) { Animations.push_back(anim); anim->setManaged(true); anim->setParent(this); }
00838     void                        removeAnimation(CzAnimInstance* anim)
00839     {
00840         for (_Iterator it = begin(); it != end(); it++)
00841         {
00842             if (*it == anim)
00843             {
00844                 delete (*it);
00845                 Animations.erase(it);
00846                 break;
00847             }
00848         }
00849     }
00850     CzAnimInstance*         findAnimation(const char* name);
00851     CzAnimInstance*         findAnimation(unsigned int name_hash);
00852     void                    play();
00853     void                    stop();
00854     void                    pause();
00855     void                    restart();
00856     int                     getAnimationCount()                 { return Animations.size(); }
00857     void                    setTargetElement(IzAnimTarget* target)
00858     {
00859         for (_Iterator it = begin(); it != end(); it++)
00860             (*it)->setTargetElement(target);
00861     }
00862     bool                    isStopped();
00863     bool                    isPlaying();
00864     void                    setAutoDelete(bool enable)          { AutoDelete = enable; }
00865     bool                    isAutoDelete() const                { return AutoDelete; }
00866     void                    setTimeScale(float time_scale)      { TimeScale = time_scale; }
00867     float                   getTimeScale() const                { return TimeScale; }
00868     // Properties end
00869 
00870 private:
00871     static int              GlobalTimelineRunCount;         // Global timeline run count (used to prevent the same timeline being updated twice in one frame by different systems, which allows sharing of timeslines across objects)
00872     int                     TimelineRunCount;
00873 
00874 public:
00875     CzAnimTimeline() : IzXomlResource(), TimelineRunCount(-1), TimeScale(1.0f), AutoDelete(false), Manager(NULL) { setClassType("timeline"); }
00876     virtual ~CzAnimTimeline();
00877 
00878     virtual void        ForceUpdateTargetOnly(IzAnimTarget* target = NULL);
00879     virtual void        UpdateTargetOnly(IzAnimTarget* target = NULL);
00880     virtual bool        Update(float time_delta, IzAnimTarget* target = NULL);  // target will override the current set target for the animation only if the animation was not updated by some other ojject this frame
00881 
00882     // Implementation of IzXomlClass interface
00883     int                 LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00884 
00885     static void         UpdateRunCount()
00886     {
00887         GlobalTimelineRunCount++;
00888     }
00889     void                SetCurrentTime(float current_time)
00890     {
00891         for (_Iterator it = begin(); it != end(); it++)
00892             (*it)->setCurrentTime(current_time);
00893     }
00894     void                Remove();
00895 };
00896 
00897 /**
00898  @class CzAnimTimelineCreator
00899 
00900  @brief Creates an instance of an animation object.
00901 
00902  CzAnimTimelineCreator enables animation timelines to be instantiated from XOML.
00903 
00904  */
00905 
00906 class CzAnimTimelineCreator : public IzXomlClassCreator
00907 {
00908 public:
00909     CzAnimTimelineCreator()
00910     {
00911         setClassName("timeline");
00912     }
00913     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzAnimTimeline(); }
00914 };
00915 
00916 /**
00917  @class CzAnimTimelinesManager
00918 
00919  @brief Manages a collection of timelines.
00920 
00921  The timelines manager manages a group of of timelines. Actors and Scenes each have their own timelines manager as well as a global timelines manager that is 
00922  used for global timelines.
00923 
00924  To retrieve an actors timelines manager you call CzActor::getTimelinesManager() and for a scene you would call CzScene::getTimelinesManager(). To retrieve 
00925  the global timelines manager you would use the CZ_GLOBAL_TIMELINE_MANAGER macro.
00926 
00927  */
00928 
00929 class CzAnimTimelinesManager
00930 {
00931 public:
00932     // Public access to iteration
00933     typedef CzList<CzAnimTimeline*>::iterator _Iterator;
00934     _Iterator               begin()     { return Timelines.begin(); }
00935     _Iterator               end()       { return Timelines.end(); }
00936 
00937 protected:
00938     // Properties
00939     CzList<CzAnimTimeline*> Timelines;          // A collection of timelines
00940     IzXomlResource*         Parent;             // Parent container
00941 public:
00942     void                    addTimeline(CzAnimTimeline* timeline);
00943     void                    removeTimeline(CzAnimTimeline* timeline);
00944     void                    removeTimeline(unsigned int name_hash);
00945     CzAnimTimeline*         findTimeline(unsigned int name_hash);
00946     CzAnimTimeline*         findTimeline(const char* name);
00947     void                    clearTimelines();
00948     void                    setParent(IzXomlResource* scene)        { Parent = scene; }
00949     IzXomlResource*         getParent()                             { return Parent; }
00950     // Properties end
00951 
00952 public:
00953     CzAnimTimelinesManager() : Parent(NULL) {}
00954     virtual ~CzAnimTimelinesManager() { clearTimelines(); }
00955 
00956     // Utility
00957     static CzAnimTimeline*  FindTimeline(const char* name, IzXomlResource* container);
00958     static CzAnimTimeline*  FindTimeline(unsigned int name_hash, IzXomlResource* container);
00959     static CzAnimTimeline*  FindTimeline(unsigned int name_hash, CzScene* container, unsigned int actor_hash);
00960     static CzAnimTimeline*  FindTimeline(const char* name, CzScene* container, const char* actor_name);
00961 };
00962 
00963 /**
00964  @class CzAnimUtil
00965 
00966  @brief Animation utility class.
00967 
00968  Static utility methods that can be used to create simple animations.
00969 
00970  */
00971 
00972 class CzAnimUtil
00973 {
00974 public:
00975     static CzAnim*          CreateFloatAnim(const char* name, float source, float target, float duration, CzAnimFrame::eAnimEase easing, int category = 0);
00976     static CzAnim*          CreateVec2Anim(const char* name, const CzVec2& source, const CzVec2& target, float duration, CzAnimFrame::eAnimEase easing, int category = 0);
00977     static CzAnim*          CreateVec3Anim(const char* name, const CzVec3& source, const CzVec3& target, float duration, CzAnimFrame::eAnimEase easing, int category = 0);
00978     static CzAnim*          CreateVec4Anim(const char* name, const CzVec4& source, const CzVec4& target, float duration, CzAnimFrame::eAnimEase easing, int category = 0);
00979     static CzAnim*          CreateRectAnim(const char* name, const CzIRect& source, const CzIRect& target, float duration, CzAnimFrame::eAnimEase easing, int category = 0);
00980     static CzAnimTimeline*  CreateTimeline(const char* name, CzAnim* anim, IzAnimTarget* target, const char* target_property, int repeat = 1, bool delta = false, float start_at_time = 0, bool interpolate = true);
00981 
00982 };
00983 
00984 //
00985 //
00986 //
00987 //
00988 //  Helper macros
00989 //
00990 //
00991 //
00992 //
00993 
00994 /**
00995  @def   CZ_NEW_ANIM(anim, name, duration, type)
00996 
00997  @brief A macro that creates a simple animation
00998 
00999  @param anim        The animation.
01000  @param name        The name of the animation.
01001  @param duration    The duration of the animation in seconds.
01002  @param type        The type of animation.
01003  */
01004 
01005 #define CZ_NEW_ANIM(anim, name, duration, type)                 \
01006     CzAnim* anim = new CzAnim();                                \
01007     anim->setName(name);                                        \
01008     anim->setDuration(duration);                                \
01009     anim->setType(type);
01010 
01011 /**
01012  @def   CZ_NEW_ANIM_FRAME_VEC2(anim, time, _x, _y, easing)
01013 
01014  @brief A macro that creates a vec2 animation frame.
01015 
01016  @param anim    The animation where the frame will be added.
01017  @param time    The time of the frame in seconds.
01018  @param _x      The x coordinate.
01019  @param _y      The y coordinate.
01020  @param easing  The easing method.
01021  */
01022 
01023 #define CZ_NEW_ANIM_FRAME_VEC2(anim, time, _x, _y, easing)          \
01024     {                                                               \
01025         CzAnimFrameVec2* frame = new CzAnimFrameVec2();             \
01026         frame->Time = time;                                         \
01027         frame->data.x = _x;                                         \
01028         frame->data.y = _y;                                         \
01029         frame->setEasing(easing);                                   \
01030         anim->addFrame(frame);                                      \
01031     }
01032 
01033 /**
01034  @def   CZ_NEW_ANIM_FRAME_VEC3(anim, time, _x, _y, _z, easing)
01035 
01036  @brief A macro that creates a vec3 animation frame.
01037 
01038  @param anim    The animation where the frame will be added.
01039  @param time    The time of the frame in seconds.
01040  @param _x      The x coordinate.
01041  @param _y      The y coordinate.
01042  @param _z      The z coordinate.
01043  @param easing  The easing method.
01044  */
01045 
01046 #define CZ_NEW_ANIM_FRAME_VEC3(anim, time, _x, _y, _z, easing)      \
01047     {                                                               \
01048         CzAnimFrameVec3* frame = new CzAnimFrameVec3();             \
01049         frame->Time = time;                                         \
01050         frame->data.x = _x;                                         \
01051         frame->data.y = _y;                                         \
01052         frame->data.z = _z;                                         \
01053         frame->setEasing(easing);                                   \
01054         anim->addFrame(frame);                                      \
01055     }
01056 
01057 /**
01058  @def   CZ_NEW_ANIM_FRAME_VEC4(anim, time, _x, _y, _z, _w, easing)
01059 
01060 @brief  A macro that creates a vec4 animation frame.
01061 
01062  @param anim    The animation where the frame will be added.
01063  @param time    The time of the frame in seconds.
01064  @param _x      The x coordinate.
01065  @param _y      The y coordinate.
01066  @param _z      The z coordinate.
01067  @param _w      The w coordinate.
01068  @param easing  The easing method.
01069   */
01070 
01071 #define CZ_NEW_ANIM_FRAME_VEC4(anim, time, _x, _y, _z, _w, easing)  \
01072     {                                                               \
01073         CzAnimFrameVec4* frame = new CzAnimFrameVec4();             \
01074         frame->Time = time;                                         \
01075         frame->data.x = _x;                                         \
01076         frame->data.y = _y;                                         \
01077         frame->data.z = _z;                                         \
01078         frame->data.w = _w;                                         \
01079         frame->setEasing(easing);                                   \
01080         anim->addFrame(frame);                                      \
01081     }
01082 
01083 /**
01084  @def   CZ_NEW_ANIM_FRAME_RECT(anim, time, _x, _y, _w, _h, easing)
01085 
01086 @brief  A macro that creates a rect animation frame.
01087 
01088  @param anim    The animation where the frame will be added.
01089  @param time    The time of the frame in seconds.
01090  @param _x      The x coordinate.
01091  @param _y      The y coordinate.
01092  @param _w      The width.
01093  @param _h      The height.
01094  @param easing  The easing method.
01095  */
01096 
01097 #define CZ_NEW_ANIM_FRAME_RECT(anim, time, _x, _y, _w, _h, easing)  \
01098     {                                                               \
01099         CzAnimFrameRect* frame = new CzAnimFrameRect();             \
01100         frame->Time = time;                                         \
01101         frame->data.x = _x;                                         \
01102         frame->data.y = _y;                                         \
01103         frame->data.w = _w;                                         \
01104         frame->data.h = _h;                                         \
01105         frame->setEasing(easing);                                   \
01106         anim->addFrame(frame);                                      \
01107     }
01108 
01109 /**
01110  @def   CZ_NEW_ANIM_FRAME_FLOAT(anim, time, _d, easing)
01111 
01112 @brief  A macro that creates a floating point animation frame.
01113 
01114  @param anim    The animation where the frame will be added.
01115  @param time    The time of the frame in seconds.
01116  @param _d      The data.
01117  @param easing  The easing method.
01118  */
01119 
01120 #define CZ_NEW_ANIM_FRAME_FLOAT(anim, time, _d, easing)             \
01121     {                                                               \
01122         CzAnimFrameFloat* frame = new CzAnimFrameFloat();           \
01123         frame->Time = time;                                         \
01124         frame->data = _d;                                           \
01125         frame->setEasing(easing);                                   \
01126         anim->addFrame(frame);                                      \
01127     }
01128 
01129 /**
01130  @def   CZ_NEW_ANIM_FRAME_BOOL(anim, time, _d, easing)
01131 
01132 @brief  A macro that creates a boolean animation frame.
01133 
01134  @param anim    The animation where the frame will be added.
01135  @param time    The time of the frame in seconds.
01136  @param _d      The data.
01137  @param easing  The easing method.
01138  */
01139 
01140 #define CZ_NEW_ANIM_FRAME_BOOL(anim, time, _d, easing)              \
01141     {                                                               \
01142         CzAnimFrameBool* frame = new CzAnimFrameBool();             \
01143         frame->Time = time;                                         \
01144         frame->data = _d;                                           \
01145         frame->setEasing(easing);                                   \
01146         anim->addFrame(frame);                                      \
01147     }
01148 
01149 /**
01150  @def   CZ_NEW_ANIM_FRAME_STRING(anim, time, _d, easing)
01151 
01152 @brief  A macro that creates a string animation frame.
01153 
01154  @param anim    The animation where the frame will be added.
01155  @param time    The time of the frame in seconds.
01156  @param _d      The data.
01157  @param easing  The easing method.
01158  */
01159 
01160 #define CZ_NEW_ANIM_FRAME_STRING(anim, time, _d, easing)            \
01161     {                                                               \
01162         CzAnimFrameString* frame = new CzAnimFrameString();         \
01163         frame->Time = time;                                         \
01164         frame->data = _d;                                           \
01165         frame->setEasing(easing);                                   \
01166         anim->addFrame(frame);                                      \
01167     }
01168 
01169 /**
01170  @def   CZ_NEW_TIMELINE(timeline, name, animation, delay, interpolate, repeat, target_property)
01171 
01172  @brief A macro that creates a new animation instance then adds it to a new timeline.
01173 
01174  @param timeline        The timeline.
01175  @param name            The name of the timeline.
01176  @param animation       The animation to attach.
01177  @param delay           The start delay in seconds.
01178  @param interpolate     The interpolate option.
01179  @param repeat          The repeat count.
01180  @param target_property Target property name.
01181  */
01182 
01183 #define CZ_NEW_TIMELINE(timeline, name, animation, delay, interpolate, repeat, target_property) \
01184     CzAnimTimeline* timeline = new CzAnimTimeline();                                            \
01185     {                                                                                           \
01186         CzAnimInstance* inst = new CzAnimInstance();                                            \
01187         inst->setAnimation(animation);                                                          \
01188         inst->setDelay(delay);                                                                  \
01189         inst->setInterpolate(interpolate);                                                      \
01190         inst->setRepeatCount(repeat);                                                           \
01191         inst->setTarget(NULL, target_property);                                                 \
01192         timeline->setName(name);                                                                \
01193         timeline->addAnimation(inst);                                                           \
01194     }
01195 
01196 /**
01197  @def   CZ_ADD_TIMELINE(timeline, animation, delay, interpolate, repeat, target_property)
01198 
01199  @brief A macro that creates a new animation instance then adds its to an existing timeline.
01200 
01201  @param timeline        The timeline.
01202  @param animation       The animation to attach.
01203  @param delay           The start delay in seconds.
01204  @param interpolate     The interpolate option.
01205  @param repeat          The repeat count.
01206  @param target_property Target property name.
01207  */
01208 
01209 #define CZ_ADD_TIMELINE(timeline, animation, delay, interpolate, repeat, target_property)       \
01210     {                                                                                           \
01211         CzAnimInstance* inst = new CzAnimInstance();                                            \
01212         inst->setAnimation(animation);                                                          \
01213         inst->setDelay(delay);                                                                  \
01214         inst->setInterpolate(interpolate);                                                      \
01215         inst->setRepeatCount(repeat);                                                           \
01216         inst->setTarget(NULL, target_property);                                                 \
01217         timeline->addAnimation(inst);                                                           \
01218     }
01219 
01220 /// @}
01221 
01222 
01223 #endif  // _CANIM_H_