Building Game Engines
TextDisplay Class Reference

Define the functions and variables required to display texts. More...

#include <TextDisplay.hpp>

Inheritance diagram for TextDisplay:
Inheritance graph
Collaboration diagram for TextDisplay:
Collaboration graph

Public Member Functions

 TextDisplay (Vec2 position, SDL_Renderer *renderer, TTF_Font *font, std::string text)
 
void setText (std::string const &textToDisplay)
 
 ~TextDisplay ()
 
void Update (int x, int y, std::string text)
 
void Draw ()
 
- Public Member Functions inherited from Component
 Component ()
 
 ~Component ()
 

Public Attributes

Vec2 position {}
 The in-game position of this text. More...
 
SDL_Renderer * renderer
 Reference to SDL renderer. More...
 
TTF_Font * font
 Reference to the font object we loaded. More...
 
SDL_Surface * surface {}
 Reference to SDL text surface. More...
 
SDL_Texture * texture {}
 Reference to SDL text texture. More...
 
SDL_Rect rect {}
 The box area that will contain the generated text area. More...
 

Detailed Description

Define the functions and variables required to display texts.

Constructor & Destructor Documentation

◆ TextDisplay()

TextDisplay::TextDisplay ( Vec2  position,
SDL_Renderer *  renderer,
TTF_Font *  font,
std::string  text 
)

Constructor

Parameters
positionThe in-game position of this text.
rendererReference to SDL renderer.
fontReference to the font object.
textThe content of this text.

◆ ~TextDisplay()

TextDisplay::~TextDisplay ( )

Destructor

Member Function Documentation

◆ Draw()

void TextDisplay::Draw ( )

Render the text on the screen.

◆ setText()

void TextDisplay::setText ( std::string const &  textToDisplay)

Modify the content of this text.

◆ Update()

void TextDisplay::Update ( int  x,
int  y,
std::string  text 
)

Update position and text

Member Data Documentation

◆ font

TTF_Font* TextDisplay::font

Reference to the font object we loaded.

◆ position

Vec2 TextDisplay::position {}

The in-game position of this text.

◆ rect

SDL_Rect TextDisplay::rect {}

The box area that will contain the generated text area.

◆ renderer

SDL_Renderer* TextDisplay::renderer

Reference to SDL renderer.

◆ surface

SDL_Surface* TextDisplay::surface {}

Reference to SDL text surface.

◆ texture

SDL_Texture* TextDisplay::texture {}

Reference to SDL text texture.