Oxygine  1
2g game engine
AtlasTool.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include "math/Rect.h"
4 #include "AnimationFrame.h"
5 #include <deque>
6 #include <list>
7 
8 namespace oxygine
9 {
10  class AtlasNode
11  {
12  public:
13  AtlasNode(AtlasNode* parent, const Rect& rect);
14  ~AtlasNode();
15 
16  AtlasNode* insert(int width, int height);
17 
18  const Rect& getRect()const {return _rc;}
19  void setID(int id) {_id = id;}
20 
21  private:
22  AtlasNode* _parent;
23  AtlasNode* _child[2];
24  Rect _rc;
25 
26  int _id;
27  };
28 
29  DECLARE_SMART(Texture, spTexture);
30 
31  class AnimationFrame;
32  typedef std::vector<AnimationFrame> frames;
33 
34  class Atlas
35  {
36  public:
37  Atlas();
38  ~Atlas();
39 
40  void init(int w, int h);
41  bool add(Texture* dest, const ImageData& src, Rect& srcRect);
42 
43  spTexture getTexture();
44  const Rect& getBounds() const {return _bounds;}
45 
46  void clean();
47 
48  private:
49  Rect _bounds;
50  AtlasNode* _tree;
51  };
52 
53 
54 
55  class Atlas2
56  {
57  public:
58  Atlas2();
59 
60  void init(int w, int h, int skipSize = 3);
61  void clean();
62 
63  bool add(Texture* dest, const ImageData& src, Rect& srcRect, const Point& offset);
64 
65  const Rect& getBounds() const { return _bounds; }
66 
67  protected:
68  typedef std::deque<Rect> rects;
69  Rect _bounds;
70  rects _free;
71  int _skipSize;
72  };
73 
74 
75 
76  class MultiAtlas
77  {
78  public:
79  typedef Closure<spTexture(int w, int h)> createTextureCallback;
80 
81  MultiAtlas(createTextureCallback);
82 
83  void init(int skipSize = 3);
84  void clean();
85 
86  bool add(const ImageData& src, Rect& srcRect, spTexture& t);
87 
88  const Rect& getBounds() const { return _bounds; }
89 
90  protected:
91  struct rect
92  {
93  spTexture texture;
94  Rect rct;
95  };
96 
97  createTextureCallback _cb;
98 
99  void place(const rect& dest, int w, int h, const ImageData& src, spTexture& t, Rect& srcRect);
100 
101  typedef std::deque<rect> rects;
102  Rect _bounds;
103  rects _free;
104  int _skipSize;
105  static bool sortRects(const rect& a, const rect& b);
106  };
107 }
Definition: Texture.h:24
Definition: AtlasTool.h:10
Definition: ImageData.h:54
Definition: AtlasTool.h:76
Definition: AnimationFrame.h:28
–oxgl-end–!
Definition: Actor.h:14
Definition: AtlasTool.h:91
Definition: AtlasTool.h:34
Definition: AtlasTool.h:55