TurtleBrains  0.2.1
High quality, portable, C++ API for native application and game development.
tb_sprite.h
1 
9 #ifndef _TurtleBrains_Sprite_h_
10 #define _TurtleBrains_Sprite_h_
11 
12 #include "tb_graphic.h"
13 #include "tb_texture_manager.h"
14 #include "tb_color.h"
15 
16 namespace TurtleBrains
17 {
18  namespace Graphics
19  {
20 
29  struct SpriteFrame
30  { //TODO: TIM: Planning: These may turn into PixelSpace values, (int), that is what they are, but they are used as float.
31  float x;
32  float y;
33  float w;
34  float h;
40 
44  PixelSpace GetPixelTop(void) const;
45 
49  PixelSpace GetPixelLeft(void) const;
50 
54  PixelSpace GetPixelRight(void) const;
55 
59  PixelSpace GetPixelBottom(void) const;
60 
64  PixelSpace GetPixelWidth(void) const;
65 
69  PixelSpace GetPixelHeight(void) const;
70 
74  TexelSpace GetTexelTop(void) const;
75 
79  TexelSpace GetTexelLeft(void) const;
80 
84  TexelSpace GetTexelRight(void) const;
85 
89  TexelSpace GetTexelBottom(void) const;
90 
94  TexelSpace GetTexelWidth(void) const;
95 
99  TexelSpace GetTexelHeight(void) const;
100 
106  static SpriteFrame CreateWith(const TextureHandle& textureHandle);
107 
119  static SpriteFrame CreateWith(const TextureHandle& textureHandle, const PixelSpace& frameX, const PixelSpace& frameY,
120  const PixelSpace& frameWidth, const PixelSpace& frameHeight);
121  };
122 
128  class Sprite : public Graphic
129  {
130  public:
135  explicit Sprite(const SpriteFrame& spriteFrame);
136 
149  explicit Sprite(const tbCore::tbString& textureFile, const PixelSpace& frameX = 0, const PixelSpace& frameY = 0,
150  const PixelSpace& frameWidth = 0, const PixelSpace& frameHeight = 0);
151 
164  explicit Sprite(const TextureHandle& textureHandle, const PixelSpace& frameX = 0, const PixelSpace& frameY = 0,
165  const PixelSpace& frameWidth = 0, const PixelSpace& frameHeight = 0);
166 
177  Sprite(const tbCore::tbString& spriteSheet, const tbCore::tbString& spriteName);
178 
185  Sprite(const Sprite& other);
186 
190  virtual ~Sprite(void);
191 
198  Sprite& operator=(const Sprite& other);
199 
203  virtual PixelSpace GetPixelWidth(void) const override;
204 
208  virtual PixelSpace GetPixelHeight(void) const override;
209 
210  protected:
217  virtual void OnRender(void) const override;
218 
226  void SetSpriteFrame(const SpriteFrame& spriteFrame);
227 
231  const SpriteFrame& GetSpriteFrame(void) const;
232 
233  private:
234  SpriteFrame mSpriteFrame;
235  };
236 
237  }; /* namespace Graphics */
238 }; /* namespace TurtleBrains */
239 
241 
242 #endif /* _TurtleBrains_Sprite_h_ */
TexelSpace uvy
Definition: tb_sprite.h:36
Definition: tb_graphic.h:61
virtual PixelSpace GetPixelHeight(void) const override
TexelSpace uvh
Definition: tb_sprite.h:38
float w
Definition: tb_sprite.h:33
Sprite(const SpriteFrame &spriteFrame)
virtual void OnRender(void) const override
Give the GameScene and Entities something to display, Text, Sprites and AnimatedSprites help bring th...
PixelSpace GetPixelTop(void) const
Definition: tb_sprite.h:29
unsigned int TextureHandle
Definition: tb_texture_manager.h:41
TexelSpace GetTexelTop(void) const
void SetSpriteFrame(const SpriteFrame &spriteFrame)
TexelSpace GetTexelHeight(void) const
Contains all functions, classes and helpers related to game/application development written by Tim "B...
Definition: tb_application_dialog.h:21
TextureHandle mTexture
Definition: tb_sprite.h:39
Sprite & operator=(const Sprite &other)
TexelSpace uvw
Definition: tb_sprite.h:37
PixelSpace GetPixelBottom(void) const
PixelSpace GetPixelWidth(void) const
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.h:33
virtual PixelSpace GetPixelWidth(void) const override
float y
Definition: tb_sprite.h:32
TexelSpace GetTexelRight(void) const
TexelSpace GetTexelWidth(void) const
TexelSpace GetTexelLeft(void) const
PixelSpace GetPixelLeft(void) const
float x
Definition: tb_sprite.h:31
TexelSpace GetTexelBottom(void) const
const SpriteFrame & GetSpriteFrame(void) const
float TexelSpace
Definition: tb_texture_manager.h:27
std::string tbString
Definition: tb_string.h:335
PixelSpace GetPixelRight(void) const
static SpriteFrame CreateWith(const TextureHandle &textureHandle)
float h
Definition: tb_sprite.h:34
TexelSpace uvx
Definition: tb_sprite.h:35
PixelSpace GetPixelHeight(void) const
Definition: tb_sprite.h:128