Woopsi 1.0
GUI Framework for Nintendo DS Homebrew

animation.h

00001 #ifndef _ANIMATION_H_
00002 #define _ANIMATION_H_
00003 
00004 #include <nds.h>
00005 #include "woopsiarray.h"
00006 
00007 namespace WoopsiUI {
00008 
00009         class BitmapBase;
00010 
00014         class Animation {
00015         public:
00016 
00020                 enum Status {
00021                         ANIMATION_STATUS_STOPPED = 0,   
00022                         ANIMATION_STATUS_PLAYING = 1,   
00023                         ANIMATION_STATUS_PAUSED = 2             
00024                 };
00025 
00029                 enum LoopType {
00030                         ANIMATION_LOOPTYPE_NONE = 0,    
00031                         ANIMATION_LOOPTYPE_LOOP = 1,    
00032                         ANIMATION_LOOPTYPE_PINGPONG = 2 
00033                 };
00034 
00038                 typedef struct {
00039                         const BitmapBase* bitmap;               
00040                         u8 delay;                                               
00041                 } AnimFrame;
00042 
00050                 Animation(const u8 speed, const LoopType loopType, const u16 loops);
00051                 
00055                 inline ~Animation() { };
00056 
00061                 inline const AnimFrame* getCurrentFrame() const { return &_frames[_currentFrame]; };
00062                 
00067                 inline const BitmapBase* getCurrentBitmap() const { return _frames[_currentFrame].bitmap; };
00068                 
00073                 inline const Status getStatus() const { return _status; };
00074                 
00079                 inline const u8 getSpeed() const { return _speed; };
00080                 
00085                 inline const LoopType getLoopType() const { return _loopType; };
00086                 
00092                 inline const u16 getTimeToNextFrame() const { return _frameTimer; };
00093                 
00098                 inline const u16 getFrameCount() const { return _frames.size(); };
00099 
00104                 inline void setSpeed(const u8 speed) { _speed = speed; };
00105                 
00110                 inline void setLoopType(const LoopType loopType) { _loopType = loopType; };
00111 
00118                 void addFrame(const BitmapBase* bitmap, const u8 delay);
00119 
00123                 void run();
00124                 
00128                 void play();
00129                 
00134                 void stop();
00135                 
00139                 inline void pause() { _status = ANIMATION_STATUS_PAUSED; }
00140                 
00145                 void goToFrame(u16 frame);
00146 
00147         private:
00148                 WoopsiArray<AnimFrame> _frames;                         
00149                 u8 _speed;                                                                      
00150                 u16 _frameTimer;                                                        
00151                 u16 _currentFrame;                                                      
00152                 s8 _frameInc;                                                           
00153                 u16 _requestedLoops;                                            
00154                 u16 _loopCount;                                                         
00156                 LoopType _loopType;                                                     
00157                 Status _status;                                                         
00163                 bool loop();
00164         };
00165 }
00166 
00167 #endif