UGDK
|
00001 #ifndef UGDK_GRAPHIC_SPRITESHEET_H_ 00002 #define UGDK_GRAPHIC_SPRITESHEET_H_ 00003 00004 #include <string> 00005 #include <list> 00006 #include <vector> 00007 #include <utility> 00008 00009 #include <ugdk/base/types.h> 00010 #include <ugdk/graphic.h> 00011 #include <ugdk/math/vector2D.h> 00012 00013 #ifdef SWIG 00014 #pragma SWIG nowarn=325 00015 #endif 00016 #ifndef __GL_H__ 00017 extern "C" { 00018 typedef unsigned int GLuint; 00019 } 00020 #endif 00021 00022 namespace ugdk { 00023 namespace graphic { 00024 00025 struct PixelSurface; 00026 00028 class SpritesheetData { 00029 public: 00030 struct SpritesheetFrame { 00031 PixelSurface* surface; 00032 Vector2D hotspot; 00033 00034 SpritesheetFrame(PixelSurface* _surface, const Vector2D& _hotspot) 00035 : surface(_surface), hotspot(_hotspot) {} 00036 }; 00037 00039 SpritesheetData(const std::string& filename); 00040 SpritesheetData(const std::list<std::string>& filenames); 00041 ~SpritesheetData(); 00042 00044 void AddFrame(int topleft_x, int topleft_y, int width, int height, const Vector2D& hotspot, size_t file = 0); 00045 00047 void FillWithFramesize(int width, int height, const Vector2D& hotspot, size_t file = 0); 00048 00050 void FillWithFramesizeFromAllFiles(int width, int height, const Vector2D& hotspot); 00051 00053 const std::list<SpritesheetFrame>& frames() const { return frames_; } 00054 00055 private: 00056 std::vector<PixelSurface*> file_data_; 00057 std::list<SpritesheetFrame> frames_; 00058 }; 00059 00060 class Spritesheet { 00061 public: 00063 Spritesheet(const SpritesheetData& data); 00064 virtual ~Spritesheet(); 00065 00066 size_t frame_count() const { 00067 return frame_sizes_.size(); 00068 } 00069 00070 const Vector2D& frame_size(size_t frame_number) const; 00071 00074 void Draw(int frame_number, const Vector2D& hotspot) const; 00075 00076 private: 00077 void createList(GLuint id, Texture* texture, const Vector2D& hotspot); 00078 00079 GLuint lists_base_; 00080 00081 std::vector<Texture*> frames_; 00082 std::vector<Vector2D> frame_sizes_; 00083 }; 00084 00085 Spritesheet* CreateSpritesheetFromTag(const std::string&); 00086 00087 } // namespace graphic 00088 } // namespace ugdk 00089 00090 #endif // UGDK_GRAPHIC_SPRITESHEET_H_