cstool/csanim2d.h
Go to the documentation of this file.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 00027 #include "csextern.h" 00028 00029 #include "cstool/cspixmap.h" 00030 #include "csutil/array.h" 00031 #include "csutil/parray.h" 00032 00033 struct iGraphics3D; 00034 struct iTextureHandle; 00035 00036 class csPixmap; 00037 class csAnimatedPixmap; 00038 00040 class CS_CRYSTALSPACE_EXPORT csAnimationTemplate 00041 { 00042 private: 00044 csPDelArray<csPixmap> Frames; 00049 csArray<csTicks> FinishTimes; 00050 00051 public: 00053 csAnimationTemplate(); 00055 ~csAnimationTemplate(); 00056 00058 inline size_t GetFrameCount() const 00059 {return Frames.Length();} 00061 inline csTicks GetLength() const 00062 { 00063 if (GetFrameCount() == 0) 00064 return 0; 00065 else 00066 return (csTicks)(FinishTimes.Get (GetFrameCount()-1)); 00067 } 00069 inline void AddFrame(csTicks Delay, csPixmap *s) 00070 {FinishTimes.Push(GetLength() + Delay); Frames.Push (s);} 00072 inline void AddFrame(csTicks Delay, iTextureHandle *Tex) 00073 {AddFrame(Delay, new csSimplePixmap(Tex));} 00075 inline void AddFrame(csTicks Delay, iTextureHandle *Tex, int x, int y, 00076 int w, int h) 00077 {AddFrame(Delay, new csSimplePixmap(Tex, x, y, w, h));} 00078 00080 inline csPixmap *GetFrame(size_t n) const 00081 {return Frames.Get(n);} 00083 csPixmap *GetFrameByTime(csTicks Time); 00084 00086 csAnimatedPixmap *CreateInstance(); 00087 }; 00088 00089 00091 class CS_CRYSTALSPACE_EXPORT csAnimatedPixmap : public csPixmap 00092 { 00093 public: 00095 csAnimatedPixmap(csAnimationTemplate *tpl); 00097 virtual ~csAnimatedPixmap(); 00098 00099 // Implementation of csPixmap. 00100 virtual int Width(); 00101 virtual int Height(); 00102 virtual iTextureHandle *GetTextureHandle(); 00103 virtual void DrawScaled (iGraphics3D* g3d, int sx, int sy, int sw, int sh, 00104 uint8 Alpha = 0); 00105 virtual void DrawTiled (iGraphics3D* g3d, int sx, int sy, int sw, int sh, 00106 int orgx, int orgy, uint8 Alpha = 0); 00107 virtual void Advance(csTicks ElapsedTime); 00108 00109 private: 00110 csAnimationTemplate *Template; 00111 csTicks CurrentTime; 00112 csPixmap *CurrentFrame; 00113 }; 00114 00115 #endif // __CS_CSANIM2D_H__
Generated for Crystal Space by doxygen 1.4.7