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>
|
| 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< Texture > | renderText (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< Texture > | 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.
|
|
std::shared_ptr< Texture > | 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.
|
|
std::string | getResourceTypeName_ () const override |
| Get the resource type string for this resource.
|
|
virtual | ~IResource ()=default |
| Destroy the IResource object.
|
|
|
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< Texture > | MakeTexture (SDL_Surface *surface) |
| Utility function for converting an SDL surface into a Texture resource.
|
|
|
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.
|
|
A wrapper class over SDL_ttf, providing methods to generate text textures from text using a font as a resource.
◆ TextFont()
TextFont::TextFont |
( |
const std::string & | fontPath, |
|
|
uint16_t | pointSize ) |
|
explicit |
Constructs a new Text Font object.
- Parameters
-
fontPath | The path to the TTF file containing the desired font. |
pointSize | The point size to load the font with, whose purpose I don't quite understand yet. |
◆ 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
-
fontPath | The path of the font being loaded. |
pointSize | The 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
-
surface | The 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
-
text | The text to be rendered. |
textColor | The color of the text. |
backgroundColor | The 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
-
text | The text to be rendered. |
textColor | The 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
-
text | The text being rendered. |
textColor | The color of the text once rendered. |
wrapLength | The 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: