A simple interface to manage the active font used by GFX Draw.
More...
|
int | gfxFontLoadFont (char *font_name, ssize_t size) |
| Loads a font with the given font name from the FONTS_DIRECTORY directory, by default this is in resources/fonts More...
|
|
int | gfxFontInit (char *path) |
| Initializes the font backend, the executing binary path is required, this is usually already passed to gfx_Draw init and subsequently to gfxFontInit. More...
|
|
void | gfxFontExit (void) |
| Exits the font backend. More...
|
|
TTF_Font * | gfxFontGetCurFont (void) |
| Retrieved a reference to the current SDL2 TTF font, increasing the reference count of the respective gfx_font object. Objects can not be free'd until all references have been put, this for each call to gfxFontGetCurFont() a call to gfxFontPutFont() must be made, passing in the SDL2 TTF font reference returned from this function. More...
|
|
void | gfxFontPutFont (const TTF_Font *font) |
| Finds the gfx_font object associated with the loaded SDL2 TFF font, decreasing the reference count to the object with each call, once an object's reference count has reached zero and the font backed has flagged the gfx_font object as no longer being needed it is then free'd. More...
|
|
void | gfxFontPutFontHandle (font_handle_t font) |
| Finds the gfx_font object associated with the loaded SDL2 TFF font, decreasing the reference count to the object with each call, once an object's reference count has reached zero and the font backed has flagged the gfx_font object as no longer being needed it is then free'd. More...
|
|
font_handle_t | gfxFontGetCurFontHandle (void) |
| Retrieved a handle to the current font, unlike gfxFontGetCurFont() the handle contains the gfx_Font's metadata structure for the font instance where as gfxFontGetCurFont() returns a SDL2 TTF Font reference. More...
|
|
ssize_t | gfxFontGetCurFontSize (void) |
| Returns the size of the currently active font. More...
|
|
char * | gfxFontGetCurFontName (void) |
| Retrieved the string name of the currently active font. More...
|
|
int | gfxFontSelectFontFromName (char *font_name) |
| Sets the active font from a string of the font's filename. The filename is not the absolute file but the font's name within the FONT_DIRECTORY directory. The font is only able to be made active if it was firstly loaded using gfxFontLoadFont(). More...
|
|
int | gfxFontSelectFontFromHandle (font_handle_t font_handle) |
| Sets the active font based off of a font handle. More...
|
|
int | gfxFontSetSize (ssize_t font_size) |
| Sets the size of the current font to be used. The font is set by making a copy of the current font if the current font's configuration (font + size) is being referenced by pending draw jobs. All subsequent text draw jobs will use the currently active font and the specified size until the size and/or font are changed again. More...
|
|
A simple interface to manage the active font used by GFX Draw.
The GFX Draw API functions on the premise that that is always only a single font active as the "active font" when using the drawing API. String draw calls draw strings using the active font and this API allows for the changing, saving, restoring and scaling of the currently active font.
◆ DEFAULT_FONT
#define DEFAULT_FONT "IBMPlexSans-Medium.ttf" |
Default font to be used by the SDL TTF library
◆ DEFAULT_FONT_SIZE
#define DEFAULT_FONT_SIZE 15 |
Defines the default font size used by the SDL TTF library
◆ FONTS_DIR
◆ FONTS_DIRECTORY
#define FONTS_DIRECTORY "/../resources/fonts/" |
Location of font TTF files
◆ MAX_FONT_NAME_LENGTH
#define MAX_FONT_NAME_LENGTH 256 |
Maximum length of allowed font file names, helps to prevent memory overflows
◆ font_handle_t
◆ gfxFontExit()
void gfxFontExit |
( |
void |
| ) |
|
◆ gfxFontGetCurFont()
TTF_Font* gfxFontGetCurFont |
( |
void |
| ) |
|
Retrieved a reference to the current SDL2 TTF font, increasing the reference count of the respective gfx_font object. Objects can not be free'd until all references have been put, this for each call to gfxFontGetCurFont() a call to gfxFontPutFont() must be made, passing in the SDL2 TTF font reference returned from this function.
- Returns
- A reference to the SDL2 TTF font currently loaded as the font backend's active font
◆ gfxFontGetCurFontHandle()
Retrieved a handle to the current font, unlike gfxFontGetCurFont() the handle contains the gfx_Font's metadata structure for the font instance where as gfxFontGetCurFont() returns a SDL2 TTF Font reference.
- Returns
- Handle to the currently active font
◆ gfxFontGetCurFontName()
char* gfxFontGetCurFontName |
( |
void |
| ) |
|
Retrieved the string name of the currently active font.
- Returns
- A string copy of the currently active font, allocated using malloc, must be free'd
◆ gfxFontGetCurFontSize()
ssize_t gfxFontGetCurFontSize |
( |
void |
| ) |
|
Returns the size of the currently active font.
- Returns
- The size of the currently active font
◆ gfxFontInit()
int gfxFontInit |
( |
char * |
path | ) |
|
Initializes the font backend, the executing binary path is required, this is usually already passed to gfx_Draw init and subsequently to gfxFontInit.
- Parameters
-
path | Executing binary's directory path |
- Returns
- 0 on success
◆ gfxFontLoadFont()
int gfxFontLoadFont |
( |
char * |
font_name, |
|
|
ssize_t |
size |
|
) |
| |
Loads a font with the given font name from the FONTS_DIRECTORY directory, by default this is in resources/fonts
- Parameters
-
font_name | A string representation of the fonts filename, including suffix (.ttf) |
size | The size that the font should have, if 0 is passed then the default font size will be used, defined by DEFAULT_FONT_SIZE |
- Returns
- 0 on success
◆ gfxFontPutFont()
void gfxFontPutFont |
( |
const TTF_Font * |
font | ) |
|
Finds the gfx_font object associated with the loaded SDL2 TFF font, decreasing the reference count to the object with each call, once an object's reference count has reached zero and the font backed has flagged the gfx_font object as no longer being needed it is then free'd.
- Parameters
-
◆ gfxFontPutFontHandle()
Finds the gfx_font object associated with the loaded SDL2 TFF font, decreasing the reference count to the object with each call, once an object's reference count has reached zero and the font backed has flagged the gfx_font object as no longer being needed it is then free'd.
- Parameters
-
◆ gfxFontSelectFontFromHandle()
Sets the active font based off of a font handle.
- Parameters
-
- Returns
- 0 on success
◆ gfxFontSelectFontFromName()
int gfxFontSelectFontFromName |
( |
char * |
font_name | ) |
|
Sets the active font from a string of the font's filename. The filename is not the absolute file but the font's name within the FONT_DIRECTORY directory. The font is only able to be made active if it was firstly loaded using gfxFontLoadFont().
- Parameters
-
font_name | A string of the .ttf file to be loaded, including suffix |
- Returns
- 0 on success
◆ gfxFontSetSize()
int gfxFontSetSize |
( |
ssize_t |
font_size | ) |
|
Sets the size of the current font to be used. The font is set by making a copy of the current font if the current font's configuration (font + size) is being referenced by pending draw jobs. All subsequent text draw jobs will use the currently active font and the specified size until the size and/or font are changed again.
- Parameters
-
font_size | New size that the currently active font should take |
- Returns
- 0 on success