TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_graphic.hpp
1 
9 #ifndef TurtleBrains_Graphic_hpp
10 #define TurtleBrains_Graphic_hpp
11 
12 #include <turtle_brains/graphics/tb_color.hpp>
13 #include <turtle_brains/graphics/tb_texture_manager.hpp>
14 
15 #include <turtle_brains/math/tb_vector.hpp>
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 
149  const tbMath::Vector2& GetOrigin(void) const;
150 
156  void SetOrigin(const AnchorLocation& anchor, const tbMath::Vector2& offset = tbMath::Vector2::Zero());
157 
164  inline void SetOrigin(const float originX, const float originY) { mOrigin.x = originX; mOrigin.y = originY; }
165 
172  inline void SetOrigin(const tbMath::Vector2& origin) { mOrigin = origin; }
173 
177  float GetDepth(void) const;
178 
186  void SetDepth(const float newDepth);
187 
192  inline const tbMath::Vector2& GetScale(void) const { return mScale; }
193 
202  void SetScale(const float scale);
203 
213  void SetScale(const tbMath::Vector2& scale);
214 
225  void SetScale(const float scaleX, const float scaleY);
226 
230  inline float GetRotation(void) const { return mOrientation; }
231 
238  inline void SetRotation(const float rotation) { mOrientation = rotation; }
239 
245  inline void SetScroll(const float scroll) { mScroll.x = scroll; mScroll.y = scroll; }
246 
255  inline void SetScroll(const float scrollX, const float scrollY) { mScroll.x = scrollX; mScroll.y = scrollY; }
256 
262  bool IsRelative(void) const;
263 
264  //
265  // @details TODO: TurtleBrains: Implementation: Currently this is unimplemented and undocumented, all Graphics
266  // are currently relative.
267  //
268  //void SetRelative(const bool isRelative);
269 
274  const Color& GetColor(void) const;
275 
280  virtual void SetColor(const tbGraphics::Color& newColor);
281 
286  virtual PixelSpace GetPixelWidth(void) const { return 0; }
287 
292  virtual PixelSpace GetPixelHeight(void) const { return 0; }
293 
298  float GetWidth(void) const { return static_cast<float>(GetPixelWidth()); }
299 
304  float GetHeight(void) const { return static_cast<float>(GetPixelHeight()); }
305 
309  float GetScaledWidth(void) const { return GetWidth() * GetScale().x; }
310 
314  float GetScaledHeight(void) const { return GetHeight() * GetScale().y; }
315 
316  bool UnstableIsPointContained(const tbMath::Vector2& point) const;
317 
318  protected:
327  virtual void OnUpdate(const float deltaTime);
328 
336  virtual void OnRender(void) const = 0;
337 
342  virtual void ApplyTransform(void) const;
343 
348  virtual void PopTransform(void) const;
349 
350  private:
351  tbMath::Vector2 mPosition;
352  tbMath::Vector2 mScroll;
353  tbMath::Vector2 mOrigin; //0,0 = top-left, 1/2w, 1/2h = center.
354  tbMath::Vector2 mScale;
355  float mOrientation;
356  float mDepthZ;
357  bool mIsActive;
358  bool mIsVisible;
359  bool mIsRelative;
360  Color mColor;
361  };
362 
363  }; /* namespace Graphics */
364 }; /* namespace TurtleBrains */
365 
367 
368 #endif /* TurtleBrains_Graphic_hpp */
Definition: tb_vector.hpp:48
void SetPosition(const float x, const float y)
Definition: tb_graphic.hpp:61
virtual void PopTransform(void) const
float GetHeight(void) const
Definition: tb_graphic.hpp:304
void SetScroll(const float scrollX, const float scrollY)
Definition: tb_graphic.hpp:255
This anchor will set the origin to the top and horizontal center of the Sprite.
Definition: tb_graphic.hpp:48
AnchorLocation
Definition: tb_graphic.hpp:44
virtual void OnRender(void) const =0
virtual PixelSpace GetPixelWidth(void) const
Definition: tb_graphic.hpp:286
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.hpp: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.hpp: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.hpp:49
void SetOrigin(const tbMath::Vector2 &origin)
Definition: tb_graphic.hpp:172
This anchor will set the origin to the bottom and left most corner of the Sprite. ...
Definition: tb_graphic.hpp:52
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
static Vector2 Zero(void)
Definition: tb_vector.hpp:54
const tbMath::Vector2 & GetScale(void) const
Definition: tb_graphic.hpp:192
This anchor will set the origin to the bottom edge and horizontal center of the Sprite.
Definition: tb_graphic.hpp:53
Definition: tb_color.hpp:24
void SetScroll(const float scroll)
Definition: tb_graphic.hpp:245
float GetScaledWidth(void) const
Definition: tb_graphic.hpp:309
This anchor will set the origin to the bottom and right most corner of the Sprite.
Definition: tb_graphic.hpp:54
void SetOrigin(const float originX, const float originY)
Definition: tb_graphic.hpp:164
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.hpp:36
float ScreenAspectRatio(void)
void SetDepth(const float newDepth)
void SetScale(const float scale)
const Color & GetColor(void) const
void Update(const float deltaTime)
float GetRotation(void) const
Definition: tb_graphic.hpp:230
float GetScaledHeight(void) const
Definition: tb_graphic.hpp:314
virtual PixelSpace GetPixelHeight(void) const
Definition: tb_graphic.hpp:292
This anchor will set the origin to the top-left corner, effectively: SetOrigin(0.0f, 0.0f).
Definition: tb_graphic.hpp:47
void SetRotation(const float rotation)
Definition: tb_graphic.hpp:238
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.hpp:51
void SetOrigin(const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero())
tbMath::Vector2 ScreenCenter(void)
float GetWidth(void) const
Definition: tb_graphic.hpp:298
const tbMath::Vector2 & GetOrigin(void) const
virtual void OnUpdate(const float deltaTime)