PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
Sprite.hpp
Go to the documentation of this file.
1 #ifndef SPRITE_HPP
2 #define SPRITE_HPP
3 
4 #include "graphics/Drawable.hpp"
5 #include "graphics/Texture.hpp"
6 #include "graphics/Transform.hpp"
7 
8 namespace pk
9 {
10 
15 struct spriteData
16 {
18  SDL_Rect d_boundsRect;
19  SDL_Point d_center;
20  SDL_RendererFlip d_flip;
21  SDL_Color d_backgroundColor;
23  int d_width;
24  int d_height;
25 };
26 
32 class Sprite : public Drawable
33 {
34  private:
40  void updateSprite();
41 
42  public:
47  Sprite();
48 
54  Sprite(Texture * const texture);
55 
62  Sprite(Texture * const texture, const SDL_Rect &rect);
63 
64  virtual ~Sprite();
65 
71  void setSpriteData(spriteData &s){ m_data = s; };
72 
79 
85  void setTexture(Texture * const texture){ m_data.d_texture = texture; };
86 
91  Texture * const getTexture(){ return m_data.d_texture; };
92 
98  void setBoundsRect(SDL_Rect &rect)
99  {
100  m_data.d_transform.setPosition({rect.x, rect.y});
101  m_data.d_width = rect.w;
102  m_data.d_height = rect.h;
103  m_data.d_boundsRect = {rect.x, rect.y, rect.w, rect.h};
104  updateSprite();
105  };
106 
112  const SDL_Rect & getBoundsRect()
113  {
115  return m_data.d_boundsRect;
116  };
117 
123  const SDL_Point &getCenter()
124  {
126  return m_data.d_center;
127  };
128 
134  void setFlip(SDL_RendererFlip &type){ m_data.d_flip = type; };
135 
141  const SDL_RendererFlip & getFlip(){ return m_data.d_flip; };
142 
149  void draw(SDL_Renderer * const renderTarget, SDL_Rect * const renderTargetRect) override;
150 
151  private:
153 };
154 
155 } //end namespace pk
156 
157 #endif // SPRITE_HPP
int d_height
The height of the Text object.
Definition: Sprite.hpp:24
void setPosition(glm::vec2 position)
Set the position of the transformable in the Window.
Definition: Transform.hpp:84
glm::vec2 getPosition()
Get the current position of the transformable.
Definition: Transform.hpp:91
void setFlip(SDL_RendererFlip &type)
Set the flip type for the Sprite (SDL_FLIP_NONE, SDL_FLIP_HORIZONTAL, SDL_FLIP_VERTICAL).
Definition: Sprite.hpp:134
const SDL_Point & getCenter()
Get the current center point of the Sprite.
Definition: Sprite.hpp:123
Transform used to manipulate the position, scale, center, and rotation of objects.
Definition: Transform.hpp:26
void setTexture(Texture *const texture)
Set the Sprite texture.
Definition: Sprite.hpp:85
Definition: Game.hpp:7
const glm::vec2 & getCenter()
Get the current center point of the transformable.
Definition: Transform.hpp:63
spriteData m_data
Data important to the construction and state maintenance of a Sprite.
Definition: Sprite.hpp:152
Data necessary for representing the Sprite.
Definition: Sprite.hpp:15
void setBoundsRect(SDL_Rect &rect)
Set the bounding rectangle for the Sprite.
Definition: Sprite.hpp:98
const SDL_RendererFlip & getFlip()
Get the current flip type for the Sprite (default is SDL_FLIP_NONE).
Definition: Sprite.hpp:141
Texture * d_texture
Pointer to a Texture object (memory NOT managed in this class!).
Definition: Sprite.hpp:17
Texture *const getTexture()
Get the Sprite texture.
Definition: Sprite.hpp:91
Drawable sprite using a Texture as its drawable resource. Part of the Decorator pattern along with th...
Definition: Sprite.hpp:32
int d_width
The width of the Text object.
Definition: Sprite.hpp:23
SDL_Color d_backgroundColor
The color of the background (bounding box) of the Text.
Definition: Sprite.hpp:21
void draw(SDL_Renderer *const renderTarget, SDL_Rect *const renderTargetRect) override
Draw the Sprite to a render target.
Definition: Sprite.hpp:141
SDL_Rect d_boundsRect
SDL_Rect setting the bounding rectangle for the Sprite object.
Definition: Sprite.hpp:18
const SDL_Rect & getBoundsRect()
Get the current bounding rectangle of the Sprite.
Definition: Sprite.hpp:112
SDL_Point d_center
An SDL_Point used to set the center of the Text object.
Definition: Sprite.hpp:19
Interface for creating drawable entities. Part of the Decorator pattern for drawable objects used in ...
Definition: Drawable.hpp:15
SDL_RendererFlip d_flip
An SDL_RendererFlip value setting how to flip the Text (default is SDL_FLIP_NONE).
Definition: Sprite.hpp:20
virtual ~Sprite()
spriteData & getSpriteData()
Get the current spriteData for the Sprite object.
Definition: Sprite.hpp:78
Transform d_transform
The raw transform data for the Text object.
Definition: Sprite.hpp:22
Sprite()
Default constructor.
void setSpriteData(spriteData &s)
Set the data for the Sprite object.
Definition: Sprite.hpp:71
void updateSprite()
Used internally when the render mode is initialized or changed.
A class implemented using the Facade pattern used for loading SDL_Texture data.
Definition: Texture.hpp:16