HoverRace  2.0
Public Member Functions | Private Attributes | List of all members
HoverRace::Display::SDL::SdlSurfaceText Class Reference

A fragment of text rendered on an SDL surface. More...

#include <SdlSurfaceText.h>

Public Member Functions

 SdlSurfaceText (SdlDisplay &display)
 Constructor. More...
 
 SdlSurfaceText (SdlDisplay &display, const UiFont &font, const Color color=COLOR_WHITE)
 Constructor with initial font and color. More...
 
 ~SdlSurfaceText ()
 
int GetHeight () const
 
int GetWidth () const
 
int MeasureLineHeight ()
 Calculate the line-height of text using the current font. More...
 
SdlSurfaceTextoperator= (const SdlSurfaceText &)=delete
 
SDL_Surface * RenderToNewSurface (const std::string &s)
 Create a new SDL surface and render text onto it. More...
 
SDL_Surface * RenderToSurface (SDL_Surface *dest, int x, int y, const std::string &s)
 Render text onto an existing surface. More...
 
void SetColor (const Color color)
 
void SetFixedScale (bool fixedScale)
 
void SetFont (const UiFont &font)
 
void SetWrapWidth (int wrapWidth)
 

Private Attributes

Color color
 
SdlDisplaydisplay
 
bool fixedScale
 
UiFont font
 
int height
 
int width
 
int wrapWidth
 

Detailed Description

A fragment of text rendered on an SDL surface.

This class does not manage the SDL surface itself, since the surface may be shared amongst multiple instances (e.g. to only use one texture for multiple text fragments). Instead, this class handles rendering the text onto a surface and keeps track of the properties needed for a display renderer or post-processor to use the rendered text.

Note that since this class deals directly with surfaces, no UI scaling is taken into account; users of this class must pre-scale all values that are passed in (if necessary).

Author
Michael Imamura

Constructor & Destructor Documentation

HoverRace::Display::SDL::SdlSurfaceText::SdlSurfaceText ( SdlDisplay display)

Constructor.

Parameters
displayThe current display.
HoverRace::Display::SDL::SdlSurfaceText::SdlSurfaceText ( SdlDisplay display,
const UiFont font,
const Color  color = COLOR_WHITE 
)

Constructor with initial font and color.

Parameters
displayThe current display.
fontThe font to render with.
colorThe text foreground color.
HoverRace::Display::SDL::SdlSurfaceText::~SdlSurfaceText ( )
inline

Member Function Documentation

int HoverRace::Display::SDL::SdlSurfaceText::GetHeight ( ) const
inline
int HoverRace::Display::SDL::SdlSurfaceText::GetWidth ( ) const
inline
int HoverRace::Display::SDL::SdlSurfaceText::MeasureLineHeight ( )

Calculate the line-height of text using the current font.

This is useful when needing to treat an empty string as if it were being rendered, since normally an empty string would be a zero-by-zero size.

This will set the height to the line-height and the width to 1.

Returns
The line-height (also available via GetHeight).
SdlSurfaceText& HoverRace::Display::SDL::SdlSurfaceText::operator= ( const SdlSurfaceText )
delete
SDL_Surface * HoverRace::Display::SDL::SdlSurfaceText::RenderToNewSurface ( const std::string &  s)

Create a new SDL surface and render text onto it.

The new SDL surface will be sized to fit the rendered text.

Parameters
sThe text to render (may not be blank).
Returns
The newly-created surface.
SDL_Surface * HoverRace::Display::SDL::SdlSurfaceText::RenderToSurface ( SDL_Surface *  dest,
int  x,
int  y,
const std::string &  s 
)

Render text onto an existing surface.

Parameters
destThe destination surface (may not be nullptr).
xThe horizontal offset.
yThe vertical offset.
sThe text to render (may not be blank).
Returns
The same surface.
void HoverRace::Display::SDL::SdlSurfaceText::SetColor ( const Color  color)
inline
void HoverRace::Display::SDL::SdlSurfaceText::SetFixedScale ( bool  fixedScale)
inline
void HoverRace::Display::SDL::SdlSurfaceText::SetFont ( const UiFont font)
inline
void HoverRace::Display::SDL::SdlSurfaceText::SetWrapWidth ( int  wrapWidth)
inline

Member Data Documentation

Color HoverRace::Display::SDL::SdlSurfaceText::color
private
SdlDisplay& HoverRace::Display::SDL::SdlSurfaceText::display
private
bool HoverRace::Display::SDL::SdlSurfaceText::fixedScale
private
UiFont HoverRace::Display::SDL::SdlSurfaceText::font
private
int HoverRace::Display::SDL::SdlSurfaceText::height
private
int HoverRace::Display::SDL::SdlSurfaceText::width
private
int HoverRace::Display::SDL::SdlSurfaceText::wrapWidth
private

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