UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
spritesheet.h
Go to the documentation of this file.
1 #ifndef UGDK_GRAPHIC_SPRITESHEET_H_
2 #define UGDK_GRAPHIC_SPRITESHEET_H_
3 
4 #include <string>
5 #include <list>
6 #include <vector>
7 #include <utility>
8 
9 #include <ugdk/base/types.h>
10 #include <ugdk/graphic.h>
11 #include <ugdk/math/vector2D.h>
12 
13 #ifdef SWIG
14 #pragma SWIG nowarn=325
15 #endif
16 #ifndef __GL_H__
17 extern "C" {
18 typedef unsigned int GLuint;
19 }
20 #endif
21 
22 namespace ugdk {
23 namespace graphic {
24 
25 struct PixelSurface;
26 
29  public:
31  PixelSurface* surface;
33 
34  SpritesheetFrame(PixelSurface* _surface, const Vector2D& _hotspot)
35  : surface(_surface), hotspot(_hotspot) {}
36  };
37 
39  SpritesheetData(const std::string& filename);
40  SpritesheetData(const std::list<std::string>& filenames);
42 
44  void AddFrame(int topleft_x, int topleft_y, int width, int height, const Vector2D& hotspot, size_t file = 0);
45 
47  void FillWithFramesize(int width, int height, const Vector2D& hotspot, size_t file = 0);
48 
50  void FillWithFramesizeFromAllFiles(int width, int height, const Vector2D& hotspot);
51 
53  const std::list<SpritesheetFrame>& frames() const { return frames_; }
54 
55  private:
56  std::vector<PixelSurface*> file_data_;
57  std::list<SpritesheetFrame> frames_;
58 };
59 
60 class Spritesheet {
61  public:
63  Spritesheet(const SpritesheetData& data);
64  virtual ~Spritesheet();
65 
66  size_t frame_count() const {
67  return frame_sizes_.size();
68  }
69 
70  const Vector2D& frame_size(size_t frame_number) const;
71 
74  void Draw(int frame_number, const Vector2D& hotspot) const;
75 
76  private:
77  void createList(GLuint id, Texture* texture, const Vector2D& hotspot);
78 
79  GLuint lists_base_;
80 
81  std::vector<Texture*> frames_;
82  std::vector<Vector2D> frame_sizes_;
83 };
84 
85 Spritesheet* CreateSpritesheetFromTag(const std::string&);
86 
87 } // namespace graphic
88 } // namespace ugdk
89 
90 #endif // UGDK_GRAPHIC_SPRITESHEET_H_