Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

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_ANIM2D_H__
00021 #define __CS_ANIM2D_H__
00022 
00023 #include "csutil/csvector.h"
00024 #include "cstool/cspixmap.h"
00025 
00026 struct iGraphics3D;
00027 class csPixmap;
00028 class csAnimatedPixmap;
00029 
00031 class csAnimationTemplate {
00032 private:
00034   csVector Frames;
00039   csVector FinishTimes;
00040 
00041 public:
00043   csAnimationTemplate();
00045   ~csAnimationTemplate();
00046 
00048   inline int GetFrameCount() const
00049     {return Frames.Length();}
00051   inline csTicks GetLength() const
00052     {return (GetFrameCount()==0)?0:(csTicks)FinishTimes.Get(GetFrameCount()-1);}
00054   inline void AddFrame(csTicks Delay, csPixmap *s)
00055     {FinishTimes.Push((csSome)(GetLength() + Delay)); Frames.Push(s);}
00057   inline void AddFrame(csTicks Delay, iTextureHandle *Tex)
00058     {AddFrame(Delay, new csSimplePixmap(Tex));}
00060   inline void AddFrame(csTicks Delay, iTextureHandle *Tex, int x, int y, int w, int h)
00061     {AddFrame(Delay, new csSimplePixmap(Tex, x, y, w, h));}
00062 
00064   inline csPixmap *GetFrame(int n) const
00065     {return (csPixmap*)(Frames.Get(n));}
00067   csPixmap *GetFrameByTime(csTicks Time);
00068 
00070   csAnimatedPixmap *CreateInstance();
00071 };
00072 
00073 
00075 class csAnimatedPixmap : public csPixmap {
00076 public:
00078   csAnimatedPixmap(csAnimationTemplate *tpl);
00080   virtual ~csAnimatedPixmap();
00081 
00082   // implementation of csPixmap
00083   virtual int Width();
00084   virtual int Height();
00085   virtual iTextureHandle *GetTextureHandle();
00086   virtual void DrawScaled (iGraphics3D* g3d, int sx, int sy, int sw, int sh,
00087     uint8 Alpha = 0);
00088   virtual void DrawTiled (iGraphics3D* g3d, int sx, int sy, int sw, int sh,
00089     int orgx, int orgy, uint8 Alpha = 0);
00090   virtual void Advance(csTicks ElapsedTime);
00091 
00092 private:
00093   csAnimationTemplate *Template;
00094   csTicks CurrentTime;
00095   csPixmap *CurrentFrame;
00096 };
00097 
00098 #endif // __CS_ANIM2D__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000