Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches

A wrapper class over SDL_ttf, providing methods to generate text textures from text using a font as a resource. More...

#include <text_render.hpp>

Inheritance diagram for ToyMaker::TextFont:
ToyMaker::Resource< TextFont > ToyMaker::IResource

Public Member Functions

 TextFont (const std::string &fontPath, uint16_t pointSize)
 Constructs a new Text Font object.
 
std::string getFontPath () const
 Gets the path of the TTF font file from which this resource was loaded.
 
uint16_t getPointSize () const
 Gets the point size with which the font was loaded.
 
std::shared_ptr< TexturerenderText (const std::string &text, glm::u8vec3 textColor, glm::u8vec3 backgroundColor) const
 Uses this font to render some text against a solid background.
 
std::shared_ptr< TexturerenderTextArea (const std::string &text, glm::u8vec4 textColor, uint32_t wrapLength=0) const
 Renders a texture for some text with a transparent background, which may run multiple lines, using this font.
 
std::shared_ptr< TexturerenderText (const std::string &text, glm::u8vec4 textColor) const
 Renders a texture for some text with a transparent background on a single line using this font.
 
- Public Member Functions inherited from ToyMaker::Resource< TextFont >
std::string getResourceTypeName_ () const override
 Get the resource type string for this resource.
 
- Public Member Functions inherited from ToyMaker::IResource
virtual ~IResource ()=default
 Destroy the IResource object.
 

Static Public Member Functions

static std::string getResourceTypeName ()
 Gets the resource type string for this class.
 

Static Private Member Functions

static TTF_Font * LoadFont (const std::string &fontPath, uint16_t pointSize)
 The function responsible for actually loading the font from the path specified.
 
static std::shared_ptr< TextureMakeTexture (SDL_Surface *surface)
 Utility function for converting an SDL surface into a Texture resource.
 

Private Attributes

TTF_Font * mFont
 A pointer to the underlying SDL_ttf font resource.
 
std::string mFontPath
 The path from which this font was loaded.
 
uint16_t mPointSize
 The point size with which the font was loaded.
 

Additional Inherited Members

- Protected Member Functions inherited from ToyMaker::Resource< TextFont >
 Resource (int explicitlyInitializeMe)
 Construct a new resource object.
 
- Protected Member Functions inherited from ToyMaker::IResource
 IResource ()=default
 Construct a new IResource object.
 
- Static Protected Member Functions inherited from ToyMaker::IResource
template<typename TResource>
static void RegisterResource ()
 Registers this resource as a Resource type with the ResourceDatabase.
 

Detailed Description

A wrapper class over SDL_ttf, providing methods to generate text textures from text using a font as a resource.

Constructor & Destructor Documentation

◆ TextFont()

TextFont::TextFont ( const std::string & fontPath,
uint16_t pointSize )
explicit

Constructs a new Text Font object.

Parameters
fontPathThe path to the TTF file containing the desired font.
pointSizeThe point size to load the font with, whose purpose I don't quite understand yet.

Member Function Documentation

◆ getFontPath()

std::string ToyMaker::TextFont::getFontPath ( ) const
inline

Gets the path of the TTF font file from which this resource was loaded.

Returns
std::string The path to this resource's font.

◆ getPointSize()

uint16_t ToyMaker::TextFont::getPointSize ( ) const
inline

Gets the point size with which the font was loaded.

Returns
uint16_t The point size this font was loaded with.

◆ getResourceTypeName()

static std::string ToyMaker::TextFont::getResourceTypeName ( )
inlinestatic

Gets the resource type string for this class.

Returns
std::string The resource type string for this class.

◆ LoadFont()

TTF_Font * TextFont::LoadFont ( const std::string & fontPath,
uint16_t pointSize )
staticprivate

The function responsible for actually loading the font from the path specified.

Parameters
fontPathThe path of the font being loaded.
pointSizeThe point size with which to load the font.
Returns
TTF_Font* A pointer to the underlying SDL_ttf font data.

◆ MakeTexture()

std::shared_ptr< Texture > TextFont::MakeTexture ( SDL_Surface * surface)
staticprivate

Utility function for converting an SDL surface into a Texture resource.

Parameters
surfaceThe input surface.
Returns
std::shared_ptr<Texture> The Texture Resource.

◆ renderText() [1/2]

std::shared_ptr< Texture > TextFont::renderText ( const std::string & text,
glm::u8vec3 textColor,
glm::u8vec3 backgroundColor ) const

Uses this font to render some text against a solid background.

Parameters
textThe text to be rendered.
textColorThe color of the text.
backgroundColorThe color of the text's background.
Returns
std::shared_ptr<Texture> The generated text texture.

◆ renderText() [2/2]

std::shared_ptr< Texture > TextFont::renderText ( const std::string & text,
glm::u8vec4 textColor ) const

Renders a texture for some text with a transparent background on a single line using this font.

Parameters
textThe text to be rendered.
textColorThe color of the text once rendered.
Returns
std::shared_ptr<Texture> The rendered text.
Todo
Unnecessary; remove.

◆ renderTextArea()

std::shared_ptr< Texture > TextFont::renderTextArea ( const std::string & text,
glm::u8vec4 textColor,
uint32_t wrapLength = 0 ) const

Renders a texture for some text with a transparent background, which may run multiple lines, using this font.

Parameters
textThe text being rendered.
textColorThe color of the text once rendered.
wrapLengthThe number of pixels beyond which text should be wrapped to the next line.
Returns
std::shared_ptr<Texture> The text texture generated.

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