TurtleBrains  0.2.1
High quality, portable, C++ API for native application and game development.
tb_graphic.h
1 
9 #ifndef _TurtleBrains_Graphic_h_
10 #define _TurtleBrains_Graphic_h_
11 
12 #include "tb_color.h"
13 #include "tb_texture_manager.h"
14 
15 #include "../math/tb_vector.h"
16 
17 namespace TurtleBrains
18 {
19  namespace Graphics
20  {
24  PixelSpace ScreenWidth(void);
25 
30 
34  float ScreenAspectRatio(void);
35 
40 
45  {
55  };
56 
61  class Graphic
62  {
63  public:
68  Graphic(void);
69 
75  Graphic(const Graphic& other);
76 
80  virtual ~Graphic(void);
81 
86  bool IsActive(void) const;
87 
93  void SetActive(const bool isActive);
94 
99  void Update(const float deltaTime);
100 
105  bool IsVisible(void) const;
106 
112  void SetVisible(const bool isVisible);
113 
118  void Render(void) const;
119 
123  const tbMath::Vector2& GetPosition(void) const;
124 
133  void SetPosition(const float x, const float y);
134 
143  void SetPosition(const tbMath::Vector2& position);
144 
150  void SetOrigin(const AnchorLocation& anchor);
151 
158  inline void SetOrigin(const float originX, const float originY) { mOrigin.x = originX; mOrigin.y = originY; }
159 
163  float GetDepth(void) const;
164 
172  void SetDepth(const float newDepth);
173 
179  inline void SetScale(const float scale) { mScale.x = mScale.y = scale; }
180 
187  inline void SetScale(const float scaleX, const float scaleY) { mScale.x = scaleX; mScale.y = scaleY; }
188 
195  inline void SetRotation(const float rotation) { mOrientation = rotation; }
196 
200  inline float GetRotation(void) const { return mOrientation; }
201 
207  inline void SetScroll(const float scroll) { mScroll.x = scroll; mScroll.y = scroll; }
208 
217  inline void SetScroll(const float scrollX, const float scrollY) { mScroll.x = scrollX; mScroll.y = scrollY; }
218 
224  bool IsRelative(void) const;
225 
226  //
227  // @details TODO: TIM: Implementation: Currently this is unimplemented and undocumented, all Graphics
228  // are currently relative.
229  //
230  //void SetRelative(const bool isRelative);
231 
236  virtual void SetColor(const tbGraphics::Color& newColor);
237 
242  virtual PixelSpace GetPixelWidth(void) const { return 0; }
243 
248  virtual PixelSpace GetPixelHeight(void) const { return 0; }
249 
254  float GetWidth(void) const { return static_cast<float>(GetPixelWidth()); }
255 
260  float GetHeight(void) const { return static_cast<float>(GetPixelHeight()); }
261 
262  protected:
271  virtual void OnUpdate(const float deltaTime);
272 
280  virtual void OnRender(void) const = 0;
281 
286  const Color& GetColor(void) const;
287 
292  virtual void ApplyTransform(void) const;
293 
298  virtual void PopTransform(void) const;
299 
300  private:
301  tbMath::Vector2 mPosition;
302  tbMath::Vector2 mScroll;
303  tbMath::Vector2 mOrigin; //0,0 = top-left, 1/2w, 1/2h = center.
304  tbMath::Vector2 mScale;
305  float mOrientation;
306  float mDepthZ;
307  bool mIsActive;
308  bool mIsVisible;
309  bool mIsRelative;
310  Color mColor;
311  };
312 
313  }; /* namespace Graphics */
314 }; /* namespace TurtleBrains */
315 
317 
318 #endif /* _TurtleBrains_Graphic_h_ */
Definition: tb_vector.h:47
void SetPosition(const float x, const float y)
Definition: tb_graphic.h:61
virtual void PopTransform(void) const
float GetHeight(void) const
Definition: tb_graphic.h:260
void SetScroll(const float scrollX, const float scrollY)
Definition: tb_graphic.h:217
This anchor will set the origin to the top and horizontal center of the Sprite.
Definition: tb_graphic.h:48
AnchorLocation
Definition: tb_graphic.h:44
virtual void OnRender(void) const =0
virtual PixelSpace GetPixelWidth(void) const
Definition: tb_graphic.h:242
const tbMath::Vector2 & GetPosition(void) const
Give the GameScene and Entities something to display, Text, Sprites and AnimatedSprites help bring th...
This anchor will set the origin to the center vertically and left most edge of the Sprite...
Definition: tb_graphic.h:50
void SetVisible(const bool isVisible)
void SetActive(const bool isActive)
This anchor will set the origin to the center of the Sprite horizontally and vertically.
Definition: tb_graphic.h:46
PixelSpace ScreenWidth(void)
PixelSpace ScreenHeight(void)
virtual void ApplyTransform(void) const
This anchor will set the origin to the top and right most corner of the Sprite.
Definition: tb_graphic.h:49
This anchor will set the origin to the bottom and left most corner of the Sprite. ...
Definition: tb_graphic.h:52
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 scaleX, const float scaleY)
Definition: tb_graphic.h:187
This anchor will set the origin to the bottom edge and horizontal center of the Sprite.
Definition: tb_graphic.h:53
Definition: tb_color.h:23
void SetScroll(const float scroll)
Definition: tb_graphic.h:207
This anchor will set the origin to the bottom and right most corner of the Sprite.
Definition: tb_graphic.h:54
void SetOrigin(const float originX, const float originY)
Definition: tb_graphic.h:158
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.h:33
float ScreenAspectRatio(void)
void SetDepth(const float newDepth)
void SetScale(const float scale)
Definition: tb_graphic.h:179
const Color & GetColor(void) const
void Update(const float deltaTime)
float GetRotation(void) const
Definition: tb_graphic.h:200
virtual PixelSpace GetPixelHeight(void) const
Definition: tb_graphic.h:248
This anchor will set the origin to the top-left corner, effectively: SetOrigin(0.0f, 0.0f).
Definition: tb_graphic.h:47
void SetRotation(const float rotation)
Definition: tb_graphic.h:195
virtual void SetColor(const tbGraphics::Color &newColor)
This anchor will set the origin to the center vertically and right most edge of the Sprite...
Definition: tb_graphic.h:51
void SetOrigin(const AnchorLocation &anchor)
tbMath::Vector2 ScreenCenter(void)
float GetWidth(void) const
Definition: tb_graphic.h:254
virtual void OnUpdate(const float deltaTime)