CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

csanim2d.h

00001 /*
00002     Copyright (C) 2000 by Jorrit Tyberghein
00003     Copyright (C) 2001 by W.C.A. Wijngaards
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_CSANIM2D_H__
00021 #define __CS_CSANIM2D_H__
00022 
00023 #include "csextern.h"
00024 
00025 #include "csutil/array.h"
00026 #include "csutil/parray.h"
00027 #include "cstool/cspixmap.h"
00028 
00029 struct iGraphics3D;
00030 class csPixmap;
00031 class csAnimatedPixmap;
00032 
00034 class CS_CSTOOL_EXPORT csAnimationTemplate
00035 {
00036 private:
00038   csPDelArray<csPixmap> Frames;
00043   csArray<csTicks> FinishTimes;
00044 
00045 public:
00047   csAnimationTemplate();
00049   ~csAnimationTemplate();
00050 
00052   inline size_t GetFrameCount() const
00053   {return Frames.Length();}
00055   inline csTicks GetLength() const
00056   {return (GetFrameCount()==0)?0:FinishTimes[GetFrameCount()-1];}
00058   inline void AddFrame(csTicks Delay, csPixmap *s)
00059   {FinishTimes.Push(GetLength() + Delay); Frames.Push (s);}
00061   inline void AddFrame(csTicks Delay, iTextureHandle *Tex)
00062   {AddFrame(Delay, new csSimplePixmap(Tex));}
00064   inline void AddFrame(csTicks Delay, iTextureHandle *Tex, int x, int y,
00065         int w, int h)
00066   {AddFrame(Delay, new csSimplePixmap(Tex, x, y, w, h));}
00067 
00069   inline csPixmap *GetFrame(size_t n) const
00070   {return Frames.Get(n);}
00072   csPixmap *GetFrameByTime(csTicks Time);
00073 
00075   csAnimatedPixmap *CreateInstance();
00076 };
00077 
00078 
00080 class CS_CSTOOL_EXPORT csAnimatedPixmap : public csPixmap
00081 {
00082 public:
00084   csAnimatedPixmap(csAnimationTemplate *tpl);
00086   virtual ~csAnimatedPixmap();
00087 
00088   // Implementation of csPixmap.
00089   virtual int Width();
00090   virtual int Height();
00091   virtual iTextureHandle *GetTextureHandle();
00092   virtual void DrawScaled (iGraphics3D* g3d, int sx, int sy, int sw, int sh,
00093     uint8 Alpha = 0);
00094   virtual void DrawTiled (iGraphics3D* g3d, int sx, int sy, int sw, int sh,
00095     int orgx, int orgy, uint8 Alpha = 0);
00096   virtual void Advance(csTicks ElapsedTime);
00097 
00098 private:
00099   csAnimationTemplate *Template;
00100   csTicks CurrentTime;
00101   csPixmap *CurrentFrame;
00102 };
00103 
00104 #endif // __CS_CSANIM2D_H__

Generated for Crystal Space by doxygen 1.3.9.1