LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 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)
 
int lg_get_win_w (LG_Window *win)
 
int lg_get_win_h (LG_Window *win)
 
void lg_set_fonts (TTF_Font *small_f, TTF_Font *medium_f, TTF_Font *large_f, TTF_Font *big_f, TTF_Font *big_papyrus_f, TTF_Font *very_big_papyrus_f, TTF_Font *large_intelone_mono_f)
 
TTF_Font * lg_get_small_font ()
 
TTF_Font * lg_get_medium_font ()
 
TTF_Font * lg_get_large_font ()
 
TTF_Font * lg_get_big_font ()
 
TTF_Font * lg_get_big_papyrus_font ()
 
TTF_Font * lg_get_very_big_papyrus_font ()
 
TTF_Font * lg_get_large_intelone_mono_font ()
 
LG_WinColorslg_get_win_colors ()
 
void lg_set_default_win_colors ()
 
char * lg_wrap_lines (const char *txt, TTF_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_get_win_w()

int lg_get_win_w ( LG_Window win)
Parameters
win
Returns
win->w

◆ lg_get_win_h()

int lg_get_win_h ( LG_Window win)
Parameters
win
Returns
win->h

◆ lg_set_fonts()

void lg_set_fonts ( TTF_Font *  small_f,
TTF_Font *  medium_f,
TTF_Font *  large_f,
TTF_Font *  big_f,
TTF_Font *  big_papyrus_f,
TTF_Font *  very_big_papyrus_f,
TTF_Font *  large_intelone_mono_f 
)

Set fonts

◆ lg_get_small_font()

TTF_Font* lg_get_small_font ( )

Get that font

Returns
Required font

◆ lg_get_medium_font()

TTF_Font* lg_get_medium_font ( )

Get that font

Returns
Required font

◆ lg_get_large_font()

TTF_Font* lg_get_large_font ( )

Get that font

Returns
Required font

◆ lg_get_big_font()

TTF_Font* lg_get_big_font ( )

Get that font

Returns
Required font

◆ lg_get_big_papyrus_font()

TTF_Font* lg_get_big_papyrus_font ( )

Get that font

Returns
Required font

◆ lg_get_very_big_papyrus_font()

TTF_Font* lg_get_very_big_papyrus_font ( )

Get that font

Returns
Required font

◆ lg_get_large_intelone_mono_font()

TTF_Font* lg_get_large_intelone_mono_font ( )

Get that font

Returns
Required font

◆ lg_get_win_colors()

LG_WinColors* lg_get_win_colors ( )

Get win colors

Returns
Addr of a 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

Parameters
txt
font
Returns
New string