cstool/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/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 // Implementation of csPixmap. 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__
Generated for Crystal Space by doxygen 1.2.18