LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_fonts.c File Reference

Functions

void lg_fonts_list_init ()
 
zboolean lg_fonts_list_is_initialized ()
 
zboolean lg_font_add_to_list (const char *name, const char *relative_path, int size)
 
LG_Fontlg_font_get (const char *name)
 
TTF_Font * lg_font_get_ttf (const char *name)
 
TTF_Font * lg_font_get_ttf_fallback (const char *name)
 
void lg_font_free (const char *name)
 
void lg_font_free_all ()
 
void lg_font_list_all ()
 
void lg_font_info (LG_Font *font)
 
zboolean lg_font_load_array (LG_Font_Des fonts[], int n_fonts)
 
void lg_font_list_array (LG_Font_Des fonts[], int n_fonts)
 

Detailed Description

 === Fonts things ===

 TODO: using a simple list, should use a doubly-linked one to remove some stupid limitations

Function Documentation

◆ lg_fonts_list_init()

void lg_fonts_list_init ( )

Initialize the global fonts list

We use a simple list at the moment

TODO: should use a doubly-linked one

◆ lg_fonts_list_is_initialized()

zboolean lg_fonts_list_is_initialized ( )

Check if the global fonts list has been initialized

Returns
TRUE if the global fonts list has been initialized, FALSE otherwise

◆ lg_font_add_to_list()

zboolean lg_font_add_to_list ( const char *  name,
const char *  relative_path,
int  size 
)

Add a font to the global fonts list

Load a font once from file and register it with a user-defined name, so that it's easy later on to use it just by name

Max number of fonts is N_FONTS_MAX, defined in lg_wins.h

To check out game engine preloaded fonts, see: lg_load_engine_fonts()

=== TODO: using a simple list, should use a doubly-linked one to remove some stupid limitations ===

#define N_FONTS_MAX 64
typedef struct {
LG_String *name;
LG_String *relative_path; // Path inside the fonts folder, not relative if symlink
int size;
TTF_Font *f;
Definition lg_fonts.h:13
Definition lg_string.h:17
Parameters
nameA user-defined font name - whatever you want but you should pick sth short but descriptive and not confusing
relative_pathPath inside the fonts folder, not relative if symlink
sizeFont size
Returns
TRUE if OK, FALSE otherwise

◆ lg_font_get()

LG_Font * lg_font_get ( const char *  name)

Retrieve a LG_Font from the global fonts list - search by name

Parameters
nameA user-defined font name
Returns
A pointer to a LG_Font, NULL on error

◆ lg_font_get_ttf()

TTF_Font * lg_font_get_ttf ( const char *  name)

Retrieve a TTF_Font from the global fonts list - search by name

Parameters
nameA user-defined font name
Returns
A pointer to a TTF_Font, NULL on error

◆ lg_font_get_ttf_fallback()

TTF_Font * lg_font_get_ttf_fallback ( const char *  name)

Retrieve a TTF_Font from the global fonts list - search by name

Do the same as the above func then, if the requested font is not found, fall back to 'IntelOneMono-Bold.ttf' 18, which is (should) always be available

Parameters
nameA user-defined font name
Returns
A pointer to a TTF_Font, NULL on error

◆ lg_font_free()

void lg_font_free ( const char *  name)

Find font by name and free all associated resources

You should probably not use this func because:

WARNING1: Removing a TTF font will likely remove all registered sizes

WARNING2: Doesn't enable to add extra fonts, only free all font resources (because the fonts list is not a doubly-linked one)

Parameters
nameFont user-defined name

◆ lg_font_free_all()

void lg_font_free_all ( )

Free all fonts and associated resources from the list

To use the list again, you should first initialize it

WARNING:

  • This func should probably never be called directly, unless you know exactly what you are doing
  • This func is always called by lg_quit()

◆ lg_font_list_all()

void lg_font_list_all ( )

List all loaded fonts

◆ lg_font_info()

void lg_font_info ( LG_Font font)

Print out LG_Font info

◆ lg_font_load_array()

zboolean lg_font_load_array ( LG_Font_Des  fonts[],
int  n_fonts 
)

Load an array of LG_Font_Des and add them to the global fonts list

// Font description
typedef struct {
const char *name;
const char *relative_path; // Path inside the fonts folder, not relative if symlink
int size;
Definition lg_fonts.h:21
Parameters
fontsAn array of LG_Font_Des
n_fontsNum of fonts
Returns
TRUE if OK, FALSE otherwise

◆ lg_font_list_array()

void lg_font_list_array ( LG_Font_Des  fonts[],
int  n_fonts 
)

Print out nicely an array of LG_Font_Des

Parameters
fontsAn array of LG_Font_Des
n_fontsNum of fonts