00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_CSANIM2D_H__
00021 #define __CS_CSANIM2D_H__
00022
00023 #include "csutil/array.h"
00024 #include "csutil/parray.h"
00025 #include "cstool/cspixmap.h"
00026
00027 struct iGraphics3D;
00028 class csPixmap;
00029 class csAnimatedPixmap;
00030
00032 class csAnimationTemplate
00033 {
00034 private:
00036 csPDelArray<csPixmap> Frames;
00041 csArray<csTicks> FinishTimes;
00042
00043 public:
00045 csAnimationTemplate();
00047 ~csAnimationTemplate();
00048
00050 inline int GetFrameCount() const
00051 {return Frames.Length();}
00053 inline csTicks GetLength() const
00054 {return (GetFrameCount()==0)?0:FinishTimes[GetFrameCount()-1];}
00056 inline void AddFrame(csTicks Delay, csPixmap *s)
00057 {FinishTimes.Push(GetLength() + Delay); Frames.Push (s);}
00059 inline void AddFrame(csTicks Delay, iTextureHandle *Tex)
00060 {AddFrame(Delay, new csSimplePixmap(Tex));}
00062 inline void AddFrame(csTicks Delay, iTextureHandle *Tex, int x, int y,
00063 int w, int h)
00064 {AddFrame(Delay, new csSimplePixmap(Tex, x, y, w, h));}
00065
00067 inline csPixmap *GetFrame(int n) const
00068 {return Frames.Get(n);}
00070 csPixmap *GetFrameByTime(csTicks Time);
00071
00073 csAnimatedPixmap *CreateInstance();
00074 };
00075
00076
00078 class csAnimatedPixmap : public csPixmap
00079 {
00080 public:
00082 csAnimatedPixmap(csAnimationTemplate *tpl);
00084 virtual ~csAnimatedPixmap();
00085
00086
00087 virtual int Width();
00088 virtual int Height();
00089 virtual iTextureHandle *GetTextureHandle();
00090 virtual void DrawScaled (iGraphics3D* g3d, int sx, int sy, int sw, int sh,
00091 uint8 Alpha = 0);
00092 virtual void DrawTiled (iGraphics3D* g3d, int sx, int sy, int sw, int sh,
00093 int orgx, int orgy, uint8 Alpha = 0);
00094 virtual void Advance(csTicks ElapsedTime);
00095
00096 private:
00097 csAnimationTemplate *Template;
00098 csTicks CurrentTime;
00099 csPixmap *CurrentFrame;
00100 };
00101
00102 #endif // __CS_CSANIM2D_H__