PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
Text.hpp
Go to the documentation of this file.
1 #ifndef TEXT_HPP
2 #define TEXT_HPP
3 
4 #include "graphics/Texture.hpp"
5 #include "graphics/Font.hpp"
6 #include "graphics/Drawable.hpp"
7 #include "graphics/Transform.hpp"
8 
9 namespace pk
10 {
11 
16 struct textData
17 {
20  SDL_Rect d_boundsRect;
21  const char* d_text;
22  SDL_Color d_color;
23  Uint32 d_renderMode;
24  SDL_Point d_center;
25  SDL_RendererFlip d_flip;
26  SDL_Color d_backgroundColor;
28  int d_width;
29  int d_height;
30 };
31 
37 class Text : public Drawable
38 {
39  private:
40  //inaccessible - use another constructor!
45  Text(){};
46 
55  void updateTexture();
56  public:
57 
64  Text(Font * const font, const char * text);
65 
73  Text(Font * const font, Texture * const texture, const char * text);
74 
83  Text(Font * const font, Texture * const texture, const SDL_Rect &rect, const char * text);
84 
90  Text(textData td);
91 
92  virtual ~Text();
93 
99  void setTextData(textData &t){ m_data = t; };
100 
106  textData &getTextData(){ return m_data; };
107 
113  void setFont(Font * const font){ m_data.d_font = font; updateTexture(); };
114 
120  Font * getFont(){ return m_data.d_font; };
121 
127  void setTexture(Texture * const texture){ m_data.d_texture = texture; updateTexture(); };
128 
135 
141  void setBoundsRect(SDL_Rect &rect)
142  {
143  m_data.d_transform.setPosition({rect.x, rect.y});
144  m_data.d_width = rect.w;
145  m_data.d_height = rect.h;
146  m_data.d_boundsRect = {rect.x, rect.y, rect.w, rect.h};
147  updateTexture();
148  };
149 
155  const SDL_Rect & getBoundsRect()
156  {
158  return m_data.d_boundsRect;
159  };
160 
161 
162  void setPosition(glm::vec2 pos){ m_data.d_transform.setPosition(pos); };
163 
164 
165  glm::vec2 getPosition(){ return m_data.d_transform.getPosition(); };
166 
172  void setString(const char * str){ m_data.d_text = str; updateTexture(); };
173 
179  const char * getString(){ return m_data.d_text; };
180 
186  void setColor(const SDL_Color &color);
187 
193  SDL_Color &getColor(){ return m_data.d_color; };
194 
200  void setBackgroundColor(SDL_Color c){ m_data.d_backgroundColor = c; };
201 
207  const SDL_Color &getBackgroundColor(){ return m_data.d_backgroundColor; };
208 
214  {
219  };
220 
226  void setRenderMode(Uint32 mode, Uint32 length = 0){ m_data.d_renderMode = mode; m_wrapLength = length; updateTexture(); };
227 
233  Uint32 getRenderMode(){ return m_data.d_renderMode;};
234 
240  void setCenter(SDL_Point &point){ m_data.d_center = point; };
241 
247  const SDL_Point &getCenter()
248  {
250  return m_data.d_center;
251  };
252 
258  void setFlip(SDL_RendererFlip &type){ m_data.d_flip = type; };
259 
265  const SDL_RendererFlip & getFlip(){ return m_data.d_flip; };
266 
273  void draw(SDL_Renderer * const renderTarget, SDL_Rect * const renderTargetRect) override;
274 
275  private:
277  Uint32 m_wrapLength;
278 };
279 
280 } //end namespace pk
281 
282 #endif // TEXT_HPP
SDL_Rect d_boundsRect
SDL_Rect setting the bounding rectangle for the Text object.
Definition: Text.hpp:20
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
A class implemented using the Facade pattern used for loading SDL TTF_Font data.
Definition: Font.hpp:17
Transform used to manipulate the position, scale, center, and rotation of objects.
Definition: Transform.hpp:26
int d_width
The width of the Text object.
Definition: Text.hpp:28
void setFlip(SDL_RendererFlip &type)
Set the flip type for the Text (SDL_FLIP_NONE, SDL_FLIP_HORIZONTAL, SDL_FLIP_VERTICAL).
Definition: Text.hpp:258
Definition: Game.hpp:7
const glm::vec2 & getCenter()
Get the current center point of the transformable.
Definition: Transform.hpp:63
void setColor(const SDL_Color &color)
Set the color of the Font for the Text object.
Definition: Text.hpp:179
void setRenderMode(Uint32 mode, Uint32 length=0)
Set the mode for rendering the Text (renderMode::solid, renderMode::shaded, or renderMode::blended).
Definition: Text.hpp:226
Font * getFont()
Get the Font from the Text object.
Definition: Text.hpp:120
void setString(const char *str)
Set the string for the Text object.
Definition: Text.hpp:172
SDL_Color d_backgroundColor
The color of the background (bounding box) of the Text.
Definition: Text.hpp:26
Definition: Text.hpp:215
renderMode
Render mode used by SDL internally to draw the Text.
Definition: Text.hpp:213
Uint32 d_renderMode
The rendering mode used to render the Text (default is renderMode::blendedWrapped).
Definition: Text.hpp:23
Text()
Inaccessible - Text needs a Font at a minimum.
Definition: Text.hpp:45
Definition: Text.hpp:216
void setFont(Font *const font)
Set the Font for the Text object.
Definition: Text.hpp:113
Transform d_transform
The raw transform data for the Text object.
Definition: Text.hpp:27
void setTextData(textData &t)
Set the data for the Text object.
Definition: Text.hpp:99
Texture * getTexture()
Get the Texture from the Text object.
Definition: Text.hpp:134
const SDL_Point & getCenter()
Get the current center point of the Text.
Definition: Text.hpp:247
void setPosition(glm::vec2 pos)
Definition: Text.hpp:162
void updateTexture()
Used internally when the render mode is initialized or changed. Never call this in a loop unless you ...
Definition: Text.hpp:45
void draw(SDL_Renderer *const renderTarget, SDL_Rect *const renderTargetRect) override
Draw the Sprite to a render target.
Definition: Text.hpp:265
Definition: Text.hpp:218
void setCenter(SDL_Point &point)
Set the center point for the Text.
Definition: Text.hpp:240
Drawable text using a Texture as its drawable resource. Part of the Decorator pattern along with the ...
Definition: Text.hpp:37
Font * d_font
Pointer to a Font object (memory NOT managed in this class!).
Definition: Text.hpp:18
glm::vec2 getPosition()
Definition: Text.hpp:165
const SDL_Color & getBackgroundColor()
Get the SDL_Color corresponding to the Text background color (bounding box).
Definition: Text.hpp:207
const char * d_text
The character string to render to the texture.
Definition: Text.hpp:21
Interface for creating drawable entities. Part of the Decorator pattern for drawable objects used in ...
Definition: Drawable.hpp:15
Definition: Text.hpp:217
textData & getTextData()
Get the current text data for the Text object.
Definition: Text.hpp:106
const char * getString()
Get the string for the Text object.
Definition: Text.hpp:179
Uint32 m_wrapLength
If text is rendered in blended and wrapped mode, the width at which lines wrap is required...
Definition: Text.hpp:277
Uint32 getRenderMode()
Get the current render mode for the Text (default is renderMode::solid).
Definition: Text.hpp:233
SDL_Color & getColor()
Get the color of the Font for the Text object (default is white).
Definition: Text.hpp:193
int d_height
The height of the Text object.
Definition: Text.hpp:29
Texture * d_texture
Pointer to a Texture object (memory NOT managed in this class!).
Definition: Text.hpp:19
const SDL_Rect & getBoundsRect()
Get the current bounding rectangle of the Text.
Definition: Text.hpp:155
SDL_RendererFlip d_flip
An SDL_RendererFlip value setting how to flip the Text (default is SDL_FLIP_NONE).
Definition: Text.hpp:25
void setTexture(Texture *const texture)
Set the Texture for the Text object.
Definition: Text.hpp:127
void setBackgroundColor(SDL_Color c)
Set the color of the Text bounding box (background).
Definition: Text.hpp:200
void setBoundsRect(SDL_Rect &rect)
Set the bounding rectangle for the Text.
Definition: Text.hpp:141
const SDL_RendererFlip & getFlip()
Get the current flip type for the Text (default is SDL_FLIP_NONE).
Definition: Text.hpp:265
SDL_Point d_center
An SDL_Point used to set the center of the Text object.
Definition: Text.hpp:24
Data necessary for representing the Text.
Definition: Text.hpp:16
textData m_data
Data important to the construction and state maintenance of a Text.
Definition: Text.hpp:276
SDL_Color d_color
The color set to the font of the Text string (default is white).
Definition: Text.hpp:22
A class implemented using the Facade pattern used for loading SDL_Texture data.
Definition: Texture.hpp:16
virtual ~Text()