CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File 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_CSANIM2D_H__
00021 #define __CS_CSANIM2D_H__
00022 
00023 #include "csutil/csvector.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   csVector 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:(csTicks)FinishTimes.Get(GetFrameCount()-1);}
00056   inline void AddFrame(csTicks Delay, csPixmap *s)
00057     {FinishTimes.Push((void*) (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, int w, int h)
00063     {AddFrame(Delay, new csSimplePixmap(Tex, x, y, w, h));}
00064 
00066   inline csPixmap *GetFrame(int n) const
00067     {return Frames.Get(n);}
00069   csPixmap *GetFrameByTime(csTicks Time);
00070 
00072   csAnimatedPixmap *CreateInstance();
00073 };
00074 
00075 
00077 class csAnimatedPixmap : public csPixmap
00078 {
00079 public:
00081   csAnimatedPixmap(csAnimationTemplate *tpl);
00083   virtual ~csAnimatedPixmap();
00084 
00085   // implementation of csPixmap
00086   virtual int Width();
00087   virtual int Height();
00088   virtual iTextureHandle *GetTextureHandle();
00089   virtual void DrawScaled (iGraphics3D* g3d, int sx, int sy, int sw, int sh,
00090     uint8 Alpha = 0);
00091   virtual void DrawTiled (iGraphics3D* g3d, int sx, int sy, int sw, int sh,
00092     int orgx, int orgy, uint8 Alpha = 0);
00093   virtual void Advance(csTicks ElapsedTime);
00094 
00095 private:
00096   csAnimationTemplate *Template;
00097   csTicks CurrentTime;
00098   csPixmap *CurrentFrame;
00099 };
00100 
00101 #endif // __CS_CSANIM2D_H__

Generated for Crystal Space by doxygen 1.2.14