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 #include "../math/tb_math.h"
16 
17 namespace TurtleBrains
18 {
19  namespace Graphics
20  {
21 
30  struct SpriteFrame
31  { //TODO: TIM: Planning: These may turn into PixelSpace values, (int), that is what they are, but they are used as float.
32  float x;
33  float y;
34  float w;
35  float h;
41 
45  PixelSpace GetPixelTop(void) const;
46 
50  PixelSpace GetPixelLeft(void) const;
51 
55  PixelSpace GetPixelRight(void) const;
56 
60  PixelSpace GetPixelBottom(void) const;
61 
65  PixelSpace GetPixelWidth(void) const;
66 
70  PixelSpace GetPixelHeight(void) const;
71 
75  TexelSpace GetTexelTop(void) const;
76 
80  TexelSpace GetTexelLeft(void) const;
81 
85  TexelSpace GetTexelRight(void) const;
86 
90  TexelSpace GetTexelBottom(void) const;
91 
95  TexelSpace GetTexelWidth(void) const;
96 
100  TexelSpace GetTexelHeight(void) const;
101 
107  static SpriteFrame CreateWith(const TextureHandle& textureHandle);
108 
120  static SpriteFrame CreateWith(const TextureHandle& textureHandle, const PixelSpace& frameX, const PixelSpace& frameY,
121  const PixelSpace& frameWidth, const PixelSpace& frameHeight);
122  };
123 
128  {
138  };
139 
145  class Sprite : public Graphic
146  {
147  public:
152  explicit Sprite(const SpriteFrame& spriteFrame);
153 
166  explicit Sprite(const tbCore::tbString& textureFile, const PixelSpace& frameX = 0, const PixelSpace& frameY = 0,
167  const PixelSpace& frameWidth = 0, const PixelSpace& frameHeight = 0);
168 
181  explicit Sprite(const TextureHandle& textureHandle, const PixelSpace& frameX = 0, const PixelSpace& frameY = 0,
182  const PixelSpace& frameWidth = 0, const PixelSpace& frameHeight = 0);
183 
190  Sprite(const Sprite& other);
191 
195  virtual ~Sprite(void);
196 
203  Sprite& operator=(const Sprite& other);
204 
210  void SetOrigin(const AnchorLocation& anchor);
211 
218  inline void SetOrigin(const float originX, const float originY) { mOrigin.x = originX; mOrigin.y = originY; }
219 
225  inline void SetScale(const float scale) { mScale.x = mScale.y = scale; }
226 
233  inline void SetScale(const float scaleX, const float scaleY) { mScale.x = scaleX; mScale.y = scaleY; }
234 
241  inline void SetRotation(const float rotation) { mOrientation = rotation; }
242 
243  protected:
250  virtual void OnRender(void) const override;
251 
259  void SetSpriteFrame(const SpriteFrame& spriteFrame);
260 
264  const SpriteFrame& GetSpriteFrame(void) const;
265 
266  private:
267  tbMath::Vector2 mOrigin; //0,0 = top-left, 1/2w, 1/2h = center.
268  tbMath::Vector2 mScale;
269  float mOrientation;
270  SpriteFrame mSpriteFrame;
271  };
272 
273  }; /* namespace Graphics */
274 }; /* namespace TurtleBrains */
275 
277 
278 #endif /* _TurtleBrains_Sprite_h_ */
Definition: tb_vector.h:48
TexelSpace uvy
Definition: tb_sprite.h:37
Definition: tb_graphic.h:24
TexelSpace uvh
Definition: tb_sprite.h:39
This anchor will set the origin to the top and horizontal center of the Sprite.
Definition: tb_sprite.h:131
AnchorLocation
Definition: tb_sprite.h:127
float w
Definition: tb_sprite.h:34
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
This anchor will set the origin to the center vertically and left most edge of the Sprite...
Definition: tb_sprite.h:133
Definition: tb_sprite.h:30
This anchor will set the origin to the center of the Sprite horizontally and vertically.
Definition: tb_sprite.h:129
unsigned int TextureHandle
Definition: tb_texture_manager.h:41
TexelSpace GetTexelTop(void) const
void SetSpriteFrame(const SpriteFrame &spriteFrame)
This anchor will set the origin to the top and right most corner of the Sprite.
Definition: tb_sprite.h:132
TexelSpace GetTexelHeight(void) const
This anchor will set the origin to the bottom and left most corner of the Sprite. ...
Definition: tb_sprite.h:135
Contains all functions, classes and helpers related to game/application development written by Tim "B...
Definition: tb_application_dialog.h:21
void SetScale(const float scale)
Definition: tb_sprite.h:225
TextureHandle mTexture
Definition: tb_sprite.h:40
This anchor will set the origin to the bottom edge and horizontal center of the Sprite.
Definition: tb_sprite.h:136
void SetScale(const float scaleX, const float scaleY)
Definition: tb_sprite.h:233
Sprite & operator=(const Sprite &other)
TexelSpace uvw
Definition: tb_sprite.h:38
void SetRotation(const float rotation)
Definition: tb_sprite.h:241
This anchor will set the origin to the bottom and right most corner of the Sprite.
Definition: tb_sprite.h:137
void SetOrigin(const float originX, const float originY)
Definition: tb_sprite.h:218
PixelSpace GetPixelBottom(void) const
PixelSpace GetPixelWidth(void) const
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.h:33
void SetOrigin(const AnchorLocation &anchor)
float y
Definition: tb_sprite.h:33
TexelSpace GetTexelRight(void) const
This anchor will set the origin to the top-left corner, effectively: SetOrigin(0.0f, 0.0f).
Definition: tb_sprite.h:130
TexelSpace GetTexelWidth(void) const
TexelSpace GetTexelLeft(void) const
PixelSpace GetPixelLeft(void) const
float x
Definition: tb_sprite.h:32
TexelSpace GetTexelBottom(void) const
const SpriteFrame & GetSpriteFrame(void) const
float TexelSpace
Definition: tb_texture_manager.h:27
This anchor will set the origin to the center vertically and right most edge of the Sprite...
Definition: tb_sprite.h:134
std::string tbString
Definition: tb_string.h:293
PixelSpace GetPixelRight(void) const
static SpriteFrame CreateWith(const TextureHandle &textureHandle)
float h
Definition: tb_sprite.h:35
TexelSpace uvx
Definition: tb_sprite.h:36
PixelSpace GetPixelHeight(void) const
Definition: tb_sprite.h:145