![]() |
LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
|
Functions | |
| void | lg_info_win (LG_Win_Style *style, const char *format,...) |
| void | lg_info_win_no_block (zboolean with_frame, zboolean swap_fb, const char *text) |
| void | lg_error_win (LG_Win_Style *style, zboolean log, const char *format,...) |
| int | lg_question_win (LG_Win_Style *style, const char *format,...) |
| char * | lg_entry_win (LG_Win_Style *style, int x, int y, const char *label) |
| int | lg_win_open_centered (LG_Window *win, uint32_t v_shift) |
| LG_Window | lg_win (const char *text, LG_Color_u text_color, LG_Color_u bg_color, zboolean with_frame, LG_Color_u border_color, TTF_Font *font, int index, LG_Color_u hightlight_text_color, LG_Color_u hightlight_bg_color) |
| LG_MenuWinParams * | lg_get_menu_wins_params () |
| int | lg_menu_win (const char *text, LG_Color_u text_c, LG_Color_u bg_c, LG_Color_u h_text_c, LG_Color_u h_bg_c, TTF_Font *font, int starting_index, int x, int y) |
| char * | lg_action_func_to_str (LG_ActionFunc actions_funcs[]) |
| char * | lg_action_func_to_str2 (LG_ActionFunc2 actions_funcs[]) |
| void | lg_scrollable_win (LG_Win_Style *style, int display_n_lines, const char *text) |
| void | lg_win_show_annoying_errors () |
| void | lg_win_no_annoying_errors () |
| int | lg_win_open (LG_Window *win, int x, int y, uint32_t v_shift) |
| void | lg_win_free_tex (LG_Window *win) |
| zboolean | is_lg_win (LG_Window *win) |
| Rec2Di | lg_get_centered_win_rec (LG_Window *win) |
| int | lg_win_get_w (LG_Window *win) |
| int | lg_win_get_h (LG_Window *win) |
| int | lg_text_get_n_lines (const char *text) |
| char * | lg_text_format_for_win (const char *text, TTF_Font *font) |
| char * | lg_wrap_lines (const char *text, TTF_Font *font, int max_width) |
Variables | |
| static LG_Color_u | fully_transparent_c = (LG_Color_u){0, 0, 0, 0} |
| static zboolean | no_annoying_errors = FALSE |
=== GUI windows implementation === You may use these helper macros: - WITH_FRAME / NO_FRAME - BLOCK / NO_BLOCK - SWAP_FB / NO_SWAP
| void lg_info_win | ( | LG_Win_Style * | style, |
| const char * | format, | ||
| ... | |||
| ) |
Create and open a styled centered INFO LG_Window
If only one line of text, line is surrounded by newlines, ie \nLINE\n\n
=== WARNING: Also swap framebuffer ===
=== WARNING2: This one uses WAIT_FOR_PRESS_OR_CLICK_OR_TOUCH === Also don't output "Press any key ..."
You should always clear or render to bg just before calling this func (with lg_clear_bg() or lg_read_and_render_screen_back() / lg_read_screen() / lg_render_screen_back())
| style | Pointer to a LG_Win_Style instance |
| format | Format |
| ... | Extra args |
| void lg_info_win_no_block | ( | zboolean | with_frame, |
| zboolean | swap_fb, | ||
| const char * | text | ||
| ) |
Create and open a non-blocking INFO LG_Window
Window at screen bottom, horiz. centered - free win->tex
=== WARNING: May swap framebuffer ===
Use default font 'dejavu_sans_bold_18' - should be a param
TODO: really need to make a stylised variadic version
(Params are self-explanatory)
| with_frame | |
| swap_fb | |
| text | A NULL-terminated string with lines separated by newlines ('\n') |
| void lg_error_win | ( | LG_Win_Style * | style, |
| zboolean | log, | ||
| const char * | format, | ||
| ... | |||
| ) |
Create and open a styled centered ERROR LG_Window
If only one line of text, line is surrounded by newlines, ie \nLINE\n\n
=== WARNING: Also swap framebuffer ===
You should always clear or render to bg just before calling this func (with lg_clear_bg() or lg_read_and_render_screen_back() / lg_read_screen() / lg_render_screen_back())
| style | Pointer to a LG_Win_Style instance |
| log | If set to TRUE, also output to STR_ERR |
| format | Format |
| ... | Extra args |
| int lg_question_win | ( | LG_Win_Style * | style, |
| const char * | format, | ||
| ... | |||
| ) |
Create and open a styled centered QUESTION LG_Window
On Android: left tap = NO / right tap = YES
Text is always surrounded by newlines, ie \nTEXT\n\n
=== WARNING: Also swap framebuffer ===
TODO: Which font size on Android ?
TODO2: This func use a dirty hack to support multiple (up to 4) ending newlines - should implement sth more robust
You should always clear or render to bg just before calling this func (with lg_clear_bg() or lg_read_and_render_screen_back() / lg_read_screen() / lg_render_screen_back())
| style | Pointer to a LG_Win_Style instance |
| format | Format |
| ... | Extra args |
| char * lg_entry_win | ( | LG_Win_Style * | style, |
| int | x, | ||
| int | y, | ||
| const char * | label | ||
| ) |
Create and open a styled ENTRY LG_Window
(-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 (with lg_clear_bg() or lg_read_and_render_screen_back() / lg_read_screen() / lg_render_screen_back())
(Most params are self-explanatory)
| style | Pointer to a LG_Win_Style instance |
| x | |
| y | |
| label |
| int lg_win_open_centered | ( | LG_Window * | win, |
| uint32_t | v_shift | ||
| ) |
| LG_Window lg_win | ( | const char * | text, |
| LG_Color_u | text_color, | ||
| LG_Color_u | bg_color, | ||
| zboolean | with_frame, | ||
| LG_Color_u | border_color, | ||
| TTF_Font * | font, | ||
| int | index, | ||
| LG_Color_u | hightlight_text_color, | ||
| LG_Color_u | hightlight_bg_color | ||
| ) |
Create a new LG_Window
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) or UNUSED_LG_COLOR_U for a fully transparent bg
Max lines num inside window is LG_WIN_N_LINES_MAX, defined in lg_wins.h
H_PADDING, V_PADDING, and BORDER_WIDTH are also defined in lg_wins.h
| text | A NULL-terminated string with lines separated by newlines ('\n') |
| text_color | Text color as a LG_Color_u |
| with_frame | Create a window with a frame, ie add H_PADDING, V_PADDING, and BORDER_WIDTH to win dims |
| bg_color | Backgroung color as a LG_Color_u |
| border_color | Border color as a LG_Color_u |
| font | Pointer to a TTF_Font |
| index | If in range [0, LG_WIN_N_LINES_MAX - 1], will (eventually) hightlight (index + 1)th line |
| hightlight_text_color | Highlighted line text color as a LG_Color_u |
| hightlight_bg_color | Highlighted line background color as a LG_Color_u |
| LG_MenuWinParams * lg_get_menu_wins_params | ( | ) |
Get pointer to global params for all lg_menu_win() instances
| int lg_menu_win | ( | const char * | text, |
| LG_Color_u | text_c, | ||
| LG_Color_u | bg_c, | ||
| LG_Color_u | h_text_c, | ||
| LG_Color_u | h_bg_c, | ||
| TTF_Font * | font, | ||
| int | starting_index, | ||
| int | x, | ||
| int | y | ||
| ) |
Create and open a LG_Window with a menu (line highlighting enabled)
Take a string of lines separated by newlines ('\n')
Each line must be short enough as to not trigger wrapping which would break functionnality, as the number of lines is 'guessed' from the number of newlines in the string
Return the index (in range [0, n_lines - 1]) of the selected line (ENTER / left-click) or one of these negative values:
Set: x = -1, y = -1 for a centered window
You can use lg_get_menu_wins_params() to get and set other params
Usage example from LibGame scene_editor/main_menu.c:
=== WARNING: May also swap framebuffer ===
| text | A NULL-terminated string with lines separated by newlines ('\n') |
| text_c | Text color |
| bg_c | Background color |
| h_text_c | Hightlight text color |
| h_bg_c | Hightlight bg color |
| font | A TTF_Font |
| starting_index | (self-explanatory enough) |
| x | Horizontally centered if -1 |
| y | Vertically centered if -1 |
| char * lg_action_func_to_str | ( | LG_ActionFunc | actions_funcs[] | ) |
Get a string with all actions separated by newlines ('\n') from the address of a NULL-terminated array of LG_ActionFunc
| Address | of a NULL-terminated array of LG_ActionFunc |
| char * lg_action_func_to_str2 | ( | LG_ActionFunc2 | actions_funcs[] | ) |
Get a string with all actions separated by newlines ('\n') from the address of a NULL-terminated array of LG_ActionFunc2
| Address | of a NULL-terminated array of LG_ActionFunc2 |
| void lg_scrollable_win | ( | LG_Win_Style * | style, |
| int | display_n_lines, | ||
| const char * | text | ||
| ) |
Create and open a LG_Window with vertically scrollable content
Suitable for an emulated terminal
| style | Pointer to a LG_Win_Style instance |
| display_n_lines | Num of lines to display, ie height in lines of the emulated terminal |
| text | A NULL-terminated string with lines separated by newlines ('\n') |
| void lg_win_show_annoying_errors | ( | ) |
Enable output of annoying, not-critical errors (default)
| void lg_win_no_annoying_errors | ( | ) |
Disable output of annoying, not-critical errors
| int lg_win_open | ( | LG_Window * | win, |
| int | x, | ||
| int | y, | ||
| uint32_t | v_shift | ||
| ) |
Open a LG_Window instance
Set: x = -1, y = -1 for a centered window
| win | |
| x | Horizontally centered if -1 |
| y | Vertically centered if -1 |
| v_shift | <Not sure yet> |
| void lg_win_free_tex | ( | LG_Window * | win | ) |
Free resources (texture atlas actually) of a LG_Window instance
| win |
| zboolean is_lg_win | ( | LG_Window * | win | ) |
Check win is valid
| win |
Return win rectangle of centered win
| win | A pointer to a LG_Windox |
| int lg_win_get_w | ( | LG_Window * | win | ) |
Get win width
| win |
| int lg_win_get_h | ( | LG_Window * | win | ) |
Get win height
| win |
| int lg_text_get_n_lines | ( | const char * | text | ) |
Get num of lines of a text by scanning newlines ('\n')
Num of lines = 1 + num of newlines
| text | A NULL-terminated string |
| char * lg_text_format_for_win | ( | const char * | text, |
| TTF_Font * | font | ||
| ) |
Format text for display in LG_Window
Returned string must be freed when done
| text | A NULL-terminated string |
| font | Pointer to a TTF_Font |
| char * lg_wrap_lines | ( | const char * | text, |
| TTF_Font * | font, | ||
| int | max_width | ||
| ) |
Line and word wrapping: Insert newline(s) if one string (ie between 2 newlines) is too long (ie > max_width)
Returned string must be freed when done
TODO: keep improving the algo
| style | Pointer to a LG_Win_Style instance |
| font | Pointer to a TTF_Font |
| max_width | In pixels |