BARE2D
BARE2D::Font Class Reference

Essentially just a wrapper for the SDL TTF_Font type. More...

#include <Font.hpp>

+ Collaboration diagram for BARE2D::Font:

Public Member Functions

 Font ()
 
 ~Font ()
 
void init (const char *fontFile, int size)
 Creates font resources. More...
 
void dispose ()
 Destroys font resources. More...
 
unsigned int getHeight () const
 
CharacterGlyphgetGlyph (int &index)
 Gets a character glyph. Does no checking to make sure it exists! More...
 
GLuint getTextureID () const
 
unsigned int getCharacters () const
 
glm::vec2 measure (const char *s)
 Measures the dimensions of some given text. More...
 

Static Private Member Functions

static std::vector< int > * createRows (glm::ivec4 *rectangles, int rectanglesLength, int rows, int padding, int &width)
 

Private Attributes

GLuint m_textureID = 0
 
unsigned int m_height
 
unsigned int m_regStart
 
unsigned int m_regLength
 
CharacterGlyphm_characterGlyphs = nullptr
 

Detailed Description

Essentially just a wrapper for the SDL TTF_Font type.

Definition at line 29 of file Font.hpp.

Constructor & Destructor Documentation

◆ Font()

BARE2D::Font::Font ( )

Definition at line 24 of file Font.cpp.

◆ ~Font()

BARE2D::Font::~Font ( )

Definition at line 27 of file Font.cpp.

Member Function Documentation

◆ createRows()

std::vector< int > * BARE2D::Font::createRows ( glm::ivec4 *  rectangles,
int  rectanglesLength,
int  rows,
int  padding,
int &  width 
)
staticprivate

Definition at line 322 of file Font.cpp.

Referenced by init().

+ Here is the caller graph for this function:

◆ dispose()

void BARE2D::Font::dispose ( )

Destroys font resources.

Definition at line 261 of file Font.cpp.

References m_characterGlyphs, and m_textureID.

◆ getCharacters()

unsigned int BARE2D::Font::getCharacters ( ) const
inline
Returns
The number of characters in the font. Generally LAST_PRINTABLE_CHAR - FIRST_PRINTABLE_CHAR

Definition at line 74 of file Font.hpp.

References m_regLength.

Referenced by BARE2D::FontRenderer::draw().

+ Here is the caller graph for this function:

◆ getGlyph()

CharacterGlyph* BARE2D::Font::getGlyph ( int &  index)
inline

Gets a character glyph. Does no checking to make sure it exists!

Parameters
indexThe index of the glyph
Returns
A pointer to the glyph.

Definition at line 58 of file Font.hpp.

References m_characterGlyphs.

Referenced by BARE2D::FontRenderer::draw().

+ Here is the caller graph for this function:

◆ getHeight()

unsigned int BARE2D::Font::getHeight ( ) const
inline

Definition at line 48 of file Font.hpp.

References m_height.

Referenced by BARE2D::FontRenderer::draw().

+ Here is the caller graph for this function:

◆ getTextureID()

GLuint BARE2D::Font::getTextureID ( ) const
inline
Returns
The GL-provided texture ID

Definition at line 66 of file Font.hpp.

References m_textureID.

Referenced by BARE2D::FontRenderer::draw().

+ Here is the caller graph for this function:

◆ init()

void BARE2D::Font::init ( const char *  fontFile,
int  size 
)

Creates font resources.

Parameters
fontFileThe file to load the font from. Should be .ttf
sizeThe size of the font (in points). This is basically just the quality of the font loaded. Has nothing to do with rendered size.

Definition at line 30 of file Font.cpp.

References BARE2D::GLContext::bindTexture(), BARE2D::CharacterGlyph::character, closestPow2(), createRows(), FIRST_PRINTABLE_CHAR, BARE2D::FONT_FAILURE, BARE2D::GLContextManager::getContext(), LAST_PRINTABLE_CHAR, m_characterGlyphs, m_height, m_regLength, m_regStart, m_textureID, MAX_TEXTURE_RES, BARE2D::CharacterGlyph::size, BARE2D::throwFatalError(), and BARE2D::CharacterGlyph::uvRect.

Referenced by BARE2D::ResourceManager::loadFont().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ measure()

glm::vec2 BARE2D::Font::measure ( const char *  s)

Measures the dimensions of some given text.

Parameters
sThe text to be measured
Returns
The dimensions of the text

Definition at line 277 of file Font.cpp.

References m_characterGlyphs, m_height, m_regLength, m_regStart, and BARE2D::CharacterGlyph::size.

Referenced by BARE2D::FontRenderer::draw().

+ Here is the caller graph for this function:

Field Documentation

◆ m_characterGlyphs

CharacterGlyph* BARE2D::Font::m_characterGlyphs = nullptr
private

Definition at line 103 of file Font.hpp.

Referenced by dispose(), getGlyph(), init(), and measure().

◆ m_height

unsigned int BARE2D::Font::m_height
private

Definition at line 97 of file Font.hpp.

Referenced by getHeight(), init(), and measure().

◆ m_regLength

unsigned int BARE2D::Font::m_regLength
private

Definition at line 100 of file Font.hpp.

Referenced by getCharacters(), init(), and measure().

◆ m_regStart

unsigned int BARE2D::Font::m_regStart
private

Definition at line 100 of file Font.hpp.

Referenced by init(), and measure().

◆ m_textureID

GLuint BARE2D::Font::m_textureID = 0
private

Definition at line 94 of file Font.hpp.

Referenced by dispose(), getTextureID(), and init().


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