LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_wins.c File Reference

Functions

void lg_info_win_no_block (const char *text, zboolean with_frame, zboolean swap_fb)
 
void lg_info_win (const char *text, zboolean with_frame, zboolean swap_fb)
 
int lg_question_win (const char *text)
 
void lg_warning_win (const char *text)
 
void lg_error_win (const char *text)
 
char * lg_entry_win (const char *label, int x, int y)
 
int lg_win_open_centered (LG_Window *win)
 
LG_Window lg_win (const char *text, LG_Color_u text_color, zboolean with_frame, LG_Color_u bg_color, LG_Color_u border_color, TTF_Font *font)
 
int lg_win_open (LG_Window *win, int x, int y)
 
int lg_win_close (LG_Window *win)
 
void lg_win_free_tex (LG_Window *win)
 
zboolean lg_win_check (LG_Window *win)
 
int lg_get_win_w (LG_Window *win)
 
int lg_get_win_h (LG_Window *win)
 
LG_WinColorslg_get_win_colors ()
 
void lg_set_default_win_colors ()
 
char * lg_wrap_lines (const char *txt, TTF_Font *font)
 
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)
 
void lg_font_free (const char *name)
 
void lg_font_free_all ()
 
void lg_font_list_all ()
 
void lg_font_info (LG_Font *font)
 

Detailed Description

 === GUI windows implementation ===

Function Documentation

◆ lg_info_win_no_block()

void lg_info_win_no_block ( const char *  text,
zboolean  with_frame,
zboolean  swap_fb 
)

Window at screen bottom, horiz. centered - Free but don't close win

Parameters
text
with_frame
swap_fb

◆ lg_info_win()

void lg_info_win ( const char *  text,
zboolean  with_frame,
zboolean  swap_fb 
)

Window is centered

TODO: Which font size on Android ? TODO #2: Should warn if win text is over 12 lines

Parameters
text
with_frame
swap_fb

◆ lg_question_win()

int lg_question_win ( const char *  text)

Window is centered

On Android: left tap = no / right tap = yes

=== WARNING: Also swap framebuffer ===

TODO: Which font size on Android ?

You should always clear or render to bg just before calling this func (with lg_clear_bg() or lg_read_and_render_screen_back() or ...)

Parameters
text
Returns
YES or NO

◆ lg_warning_win()

void lg_warning_win ( const char *  text)

=== WARNING: Also swap framebuffer ===

You should always clear or render to bg just before calling this func

TODO: Which font size on Android ?

Parameters
text

◆ lg_error_win()

void lg_error_win ( const char *  text)

=== WARNING: Also swap framebuffer ===

You should always clear or render to bg just before calling this func

TODO: Which font size on Android ?

Parameters
text

◆ lg_entry_win()

char* lg_entry_win ( const char *  label,
int  x,
int  y 
)

TODO: check/test/update

(-1, -1) for centered win, same colors as lg_question_win()

If not NULL (<esc> pressed), returned str must be freed

=== WARNING: Also swap framebuffer ===

You should always clear or render to bg just before calling this func

Parameters
label
x
y
Returns
Entered text

◆ lg_win_open_centered()

int lg_win_open_centered ( LG_Window win)
Parameters
winA LG_Window instance
Returns
LG_OK if OK

◆ lg_win()

LG_Window lg_win ( const char *  text,
LG_Color_u  text_color,
zboolean  with_frame,
LG_Color_u  bg_color,
LG_Color_u  border_color,
TTF_Font *  font 
)

Create a new LG_Window

|------------win_rect------------|
| |--------padding_rect--------| |
| | |-------layout_rect------| | |
| | | layout_texture | | |
| | |------------------------| | |
| |----------------------------| |
|--------------------------------|

WARNING: for frameless wins, the background/border colors are still used, so you MUST set them (ie, DO use either a fully/partially transparent color or an opaque color)

For instance, use lg_color_u(0, 0, 0, 0) for a fully transparent bg

Max lines num inside window is LG_WIN_N_LINES_MAX, defined in lg_win.h

H_PADDING, V_PADDING, and BORDER_WIDTH are also defined in lg_win.h

TODO: add text overflow check

Params are self-explanatory

Parameters
text
text_color
with_frame
bg_color
border_color
font
Returns
A new LG_Window, with id set to 0 -> OK / -1 -> invalid win (TODO: need to find sth better)

◆ lg_win_open()

int lg_win_open ( LG_Window win,
int  x,
int  y 
)

Open a LG_Window instance

Set: x = -1, y = -1 for a centered window

Parameters
win
x
y
Returns
LG_OK if OK

◆ lg_win_close()

int lg_win_close ( LG_Window win)

Close a LG_Window instance

=== This func is DEPRECATED and now a NO-OP ===

Parameters
win
Returns
LG_OK if OK

◆ lg_win_free_tex()

void lg_win_free_tex ( LG_Window win)

Free resources (texture atlas actually) of a LG_Window instance

Parameters
win

◆ lg_win_check()

zboolean lg_win_check ( LG_Window win)

Check win is valid

Parameters
win

◆ lg_get_win_w()

int lg_get_win_w ( LG_Window win)
Parameters
win
Returns
win->w or -1 on error

◆ lg_get_win_h()

int lg_get_win_h ( LG_Window win)
Parameters
win
Returns
win->h or -1 on error

◆ lg_get_win_colors()

LG_WinColors* lg_get_win_colors ( )

Get win colors

Returns
Addr of a static filled LG_WinColors

◆ lg_set_default_win_colors()

void lg_set_default_win_colors ( )

Set default win colors

◆ lg_wrap_lines()

char* lg_wrap_lines ( const char *  txt,
TTF_Font *  font 
)

Line and word wrapping: Insert newline(s) if one string (ie between 2 newlines) is too long (ie > max_line_len)

max_line_len is set (very roughly) depending on font size

Returned string must be freed afterwards

TODO: improve the algo, need sth better

Parameters
txt
font
Returns
New string

◆ 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

#define N_FONTS_MAX 64
typedef struct {
LG_String *name;
LG_String *relative_path;
int size;
TTF_Font *f;
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
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_free()

void lg_font_free ( const char *  name)

Find font by name and free all associated resources

Doesn't enable to add extra fonts, only free all font resources

Parameters
nameFont used-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
Definition: lg_wins.h:114
LG_String
Definition: lg_string.h:15