PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
pk::Text Class Reference

Drawable text using a Texture as its drawable resource. Part of the Decorator pattern along with the Drawable class. More...

#include <Text.hpp>

Inheritance diagram for pk::Text:
Inheritance graph
Collaboration diagram for pk::Text:
Collaboration graph

Public Types

enum  renderMode { solid, shaded, blended, blendedWrapped }
 Render mode used by SDL internally to draw the Text. More...
 

Public Member Functions

 Text (Font *const font, const char *text)
 
 Text (Font *const font, Texture *const texture, const char *text)
 
 Text (Font *const font, Texture *const texture, const SDL_Rect &rect, const char *text)
 
 Text (textData td)
 Construct a Text from a textData struct. More...
 
virtual ~Text ()
 
void setTextData (textData &t)
 Set the data for the Text object. More...
 
textDatagetTextData ()
 Get the current text data for the Text object. More...
 
void setFont (Font *const font)
 Set the Font for the Text object. More...
 
FontgetFont ()
 Get the Font from the Text object. More...
 
void setTexture (Texture *const texture)
 Set the Texture for the Text object. More...
 
TexturegetTexture ()
 Get the Texture from the Text object. More...
 
void setBoundsRect (SDL_Rect &rect)
 Set the bounding rectangle for the Text. More...
 
const SDL_Rect & getBoundsRect ()
 Get the current bounding rectangle of the Text. More...
 
void setPosition (glm::vec2 pos)
 
glm::vec2 getPosition ()
 
void setString (const char *str)
 Set the string for the Text object. More...
 
const char * getString ()
 Get the string for the Text object. More...
 
void setColor (const SDL_Color &color)
 Set the color of the Font for the Text object. More...
 
SDL_Color & getColor ()
 Get the color of the Font for the Text object (default is white). More...
 
void setBackgroundColor (SDL_Color c)
 Set the color of the Text bounding box (background). More...
 
const SDL_Color & getBackgroundColor ()
 Get the SDL_Color corresponding to the Text background color (bounding box). More...
 
void setRenderMode (Uint32 mode, Uint32 length=0)
 Set the mode for rendering the Text (renderMode::solid, renderMode::shaded, or renderMode::blended). More...
 
Uint32 getRenderMode ()
 Get the current render mode for the Text (default is renderMode::solid). More...
 
void setCenter (SDL_Point &point)
 Set the center point for the Text. More...
 
const SDL_Point & getCenter ()
 Get the current center point of the Text. More...
 
void setFlip (SDL_RendererFlip &type)
 Set the flip type for the Text (SDL_FLIP_NONE, SDL_FLIP_HORIZONTAL, SDL_FLIP_VERTICAL). More...
 
const SDL_RendererFlip & getFlip ()
 Get the current flip type for the Text (default is SDL_FLIP_NONE). More...
 
void draw (SDL_Renderer *const renderTarget, SDL_Rect *const renderTargetRect) override
 Draw the Sprite to a render target. More...
 
- Public Member Functions inherited from pk::Drawable
 Drawable ()
 Drawable constructor. Call explicitly in inherited classes. More...
 
virtual ~Drawable ()
 

Private Member Functions

 Text ()
 Inaccessible - Text needs a Font at a minimum. More...
 
void updateTexture ()
 Used internally when the render mode is initialized or changed. Never call this in a loop unless you want memory leaks!!! This function calls SDL_CreateTextureFromSurface(...) which will keep allocating memory on each call. More...
 

Private Attributes

textData m_data
 Data important to the construction and state maintenance of a Text. More...
 
Uint32 m_wrapLength
 If text is rendered in blended and wrapped mode, the width at which lines wrap is required. More...
 

Detailed Description

Drawable text using a Texture as its drawable resource. Part of the Decorator pattern along with the Drawable class.

Member Enumeration Documentation

◆ renderMode

Render mode used by SDL internally to draw the Text.

Enumerator
solid 
shaded 
blended 
blendedWrapped 

Constructor & Destructor Documentation

◆ Text() [1/5]

pk::Text::Text ( )
inlineprivate

Inaccessible - Text needs a Font at a minimum.

◆ Text() [2/5]

pk::Text::Text ( Font *const  font,
const char *  text 
)

◆ Text() [3/5]

pk::Text::Text ( Font *const  font,
Texture *const  texture,
const char *  text 
)

◆ Text() [4/5]

pk::Text::Text ( Font *const  font,
Texture *const  texture,
const SDL_Rect &  rect,
const char *  text 
)

◆ Text() [5/5]

pk::Text::Text ( textData  td)

Construct a Text from a textData struct.

Parameters
textDatatd - a struct with key data components of a Text.

◆ ~Text()

virtual pk::Text::~Text ( )
virtual

Member Function Documentation

◆ draw()

void pk::Text::draw ( SDL_Renderer *const  renderTarget,
SDL_Rect *const  renderTargetRect 
)
overridevirtual

Draw the Sprite to a render target.

Parameters
SDL_Renderer* const renderTarget - the renderer to draw with.
SDL_Rect* const renderTargetRect - the area of the render target to draw to.

Implements pk::Drawable.

◆ getBackgroundColor()

const SDL_Color & pk::Text::getBackgroundColor ( )
inline

Get the SDL_Color corresponding to the Text background color (bounding box).

Returns
SDL_Color - an SDL_Color struct corresponding to the Text background color.

◆ getBoundsRect()

const SDL_Rect & pk::Text::getBoundsRect ( )
inline

Get the current bounding rectangle of the Text.

Returns
SDL_Point - an SDL_Rect corresponding to the bounding rectangle of the Text.
Here is the call graph for this function:

◆ getCenter()

SDL_Point pk::Text::getCenter ( )
inline

Get the current center point of the Text.

Returns
SDL_Point - an SDL_Point corresponding to the current center point of the Text.
Here is the call graph for this function:

◆ getColor()

SDL_Color & pk::Text::getColor ( )
inline

Get the color of the Font for the Text object (default is white).

Returns
SDL_Color & - a reference to an SDL_Color.

◆ getFlip()

const SDL_RendererFlip & pk::Text::getFlip ( )
inline

Get the current flip type for the Text (default is SDL_FLIP_NONE).

Returns
SDL_RendererFlip & - a const reference to an SDL_RendererFlip constant (SDL_FLIP_NONE, SDL_FLIP_HORIZONTAL, SDL_FLIP_VERTICAL).

◆ getFont()

const Font * pk::Text::getFont ( )
inline

Get the Font from the Text object.

Returns
const Font * - a const pointer to a Font object.

◆ getPosition()

glm::vec2 pk::Text::getPosition ( )
inline
Here is the call graph for this function:

◆ getRenderMode()

Uint32 pk::Text::getRenderMode ( )
inline

Get the current render mode for the Text (default is renderMode::solid).

Returns
Uint32 - a plain integer corresponding to a renderMode:: enum value.

◆ getString()

const char * pk::Text::getString ( )
inline

Get the string for the Text object.

Returns
const char * - a C-style string.

◆ getTextData()

textData & pk::Text::getTextData ( )
inline

Get the current text data for the Text object.

Returns
textData & - text data for the Text object.

◆ getTexture()

const Texture * pk::Text::getTexture ( )
inline

Get the Texture from the Text object.

Returns
const Texture * - a const pointer to a Texture object.

◆ setBackgroundColor()

void pk::Text::setBackgroundColor ( SDL_Color  c)
inline

Set the color of the Text bounding box (background).

Parameters
SDL_Colorc - an SDL_Color struct corresponding to the background color of the Text.

◆ setBoundsRect()

void pk::Text::setBoundsRect ( SDL_Rect &  rect)
inline

Set the bounding rectangle for the Text.

Parameters
SDL_Rect&rect - an SDL_Rect you want to set the bounding rectangle of the Text to.
Here is the call graph for this function:

◆ setCenter()

void pk::Text::setCenter ( SDL_Point &  point)
inline

Set the center point for the Text.

Parameters
SDL_Point&point - an SDL_Point you want to set the center point of the Text to.

◆ setColor()

void pk::Text::setColor ( const SDL_Color &  color)

Set the color of the Font for the Text object.

Parameters
constSDL_Color &color - a const reference to an SDL_Color.

◆ setFlip()

void pk::Text::setFlip ( SDL_RendererFlip &  type)
inline

Set the flip type for the Text (SDL_FLIP_NONE, SDL_FLIP_HORIZONTAL, SDL_FLIP_VERTICAL).

Parameters
SDL_RendererFliptype - an integer corresponding to an SDL_RendererFlip constant.

◆ setFont()

void pk::Text::setFont ( Font *const  font)
inline

Set the Font for the Text object.

Parameters
Font* const font - a const pointer to a Font.
Here is the call graph for this function:

◆ setPosition()

void pk::Text::setPosition ( glm::vec2  pos)
inline
Here is the call graph for this function:

◆ setRenderMode()

void pk::Text::setRenderMode ( Uint32  mode,
Uint32  length = 0 
)
inline

Set the mode for rendering the Text (renderMode::solid, renderMode::shaded, or renderMode::blended).

Parameters
Uint32mode - a plain integer corresponding to a renderMode:: enum value.
Here is the call graph for this function:

◆ setString()

void pk::Text::setString ( const char *  str)
inline

Set the string for the Text object.

Parameters
constchar * str - a C-style string.
Here is the call graph for this function:

◆ setTextData()

void pk::Text::setTextData ( textData t)
inline

Set the data for the Text object.

Parameters
textData&t - a textData struct to set for the Text object.

◆ setTexture()

void pk::Text::setTexture ( Texture *const  texture)
inline

Set the Texture for the Text object.

Parameters
Texture* const texture - a const pointer to a Texture.
Here is the call graph for this function:

◆ updateTexture()

pk::Text::updateTexture ( )
private

Used internally when the render mode is initialized or changed. Never call this in a loop unless you want memory leaks!!! This function calls SDL_CreateTextureFromSurface(...) which will keep allocating memory on each call.

Member Data Documentation

◆ m_data

textData pk::Text::m_data
private

Data important to the construction and state maintenance of a Text.

◆ m_wrapLength

Uint32 pk::Text::m_wrapLength
private

If text is rendered in blended and wrapped mode, the width at which lines wrap is required.


The documentation for this class was generated from the following file: