LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_wins.h
1/*
2 * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2026
3 * All rights reserved
4 */
5
6#ifndef LG_WIN_H
7#define LG_WIN_H
8
9/* A few helpers for wins funcs: */
10#define BLOCK TRUE
11#define NO_BLOCK (!BLOCK)
12
13#define WITH_FRAME TRUE
14#define FRAMELESS (!WITH_FRAME)
15
16#define SWAP_FB TRUE
17#define NO_SWAP (!SWAP_FB)
18
19#if defined(LINUX_V) || defined(WIN32_V)
20 #define PRESS_OR_TAP_ANYTHING "Press any key ..."
21#elif defined(ANDROID_V)
22 #define PRESS_OR_TAP_ANYTHING "Tap anywhere to continue ..."
23#endif
24
25/* Fully transparent colors actually */
26#define UNUSED_SDL_COLOR ((SDL_Color){0, 0, 0, 0})
27#define UNUSED_LG_COLOR_U ((LG_Color_u){0, 0, 0, 0})
28
29#define TMP_STR_MAXLEN 1023
30
31#define H_PADDING 12
32#define V_PADDING 8
33#define BORDER_WIDTH 2
34
35#define LG_WIN_TXT_NBSP '~'
36
37/* TODO: what if win text is over 24 lines ? */
38#define LG_WIN_N_LINES_MAX 24
39
40#define LG_LEFT_MARGIN 5
41#define LG_BOTTOM_MARGIN 5
42
43#define TIMESTAMP_MAXLEN (64 - 1)
44
45typedef struct {
46 int id; /* (So far) 0 -> OK, -1 -> invalid win */
47 LG_Texture *tex; /* Used inside new/open/close/free_win(), don't modify elsewhere */
48 uint32_t tex_w;
49 uint32_t tex_h;
50 int last_open_x; /* Set by lg_win_open() */
51 int last_open_y; /* Set by lg_win_open() */
52 Rec2Di layout_rect[LG_WIN_N_LINES_MAX]; /* Clickable areas for menu items */
53 char timestamp[TIMESTAMP_MAXLEN + 1];
54} LG_Window;
55
56typedef struct {
57 zboolean with_frame;
58 LG_Color_u text_color;
59 LG_Color_u bg_color;
60 LG_Color_u border_color;
61 LG_Color_u highlight_text_color;
62 LG_Color_u highlight_bg_color;
63 int frame_line; /* NONE, TZW_RECTANGLE, or TZW_RECT_CORNERS */
64 LG_Color_u frame_line_color;
65 const char *font;
67
68/* lg_menu_win() global extra params, all initialized to FALSE or NULL */
69typedef struct {
70 zboolean with_frame;
71 zboolean loop;
72 zboolean no_swap; /* No swap and no bg draw */
73 LG_Texture *orig_bg; /* (if !no_swap) lg_take_screenshot(); */
74 zboolean disable_h_arrows; /* Left and right arrows */
76
77typedef struct {
78 const char *str;
79 void (*func)();
81
82typedef struct {
83 const char *str;
84 int (*func)();
86
87#define MENUWIN_KEY_ESC (-1)
88#define MENUWIN_KEY_LEFT (-2)
89#define MENUWIN_KEY_RIGHT (-3)
90#define MENUWIN_KEY_SPACE (-4)
91
92typedef enum {MENUWIN_CONTINUE, MENUWIN_CLOSE, MENUWIN_EXIT, MENUWIN_SPACE_PRESSED} menuwin_exit;
93
94/* TZW stuff used in lg_ui.c/h */
95#define N_TZW_MAX 1024
96
97typedef struct {
98 LG_Window win;
99 LG_Color_u color;
100 Rec2Di area;
102
103/* Array of all TZ wins for one frame */
104typedef struct {
105 LG_TouchZoneWindow *tzw[N_TZW_MAX];
107
108/* Wins colors */
109#define ALL_WINS_BG_COLOR "darker-grey"
110#define ALL_WINS_BORDER_COLOR "darker-grey"
111
112#define INFO_WIN_TEXT_COLOR "white"
113#define INFO_WIN_BG_COLOR ALL_WINS_BG_COLOR
114#define INFO_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
115#define INFO_WIN_FONT
116#define INFO_WIN_STYLE
117
118#define QUESTION_WIN_TEXT_COLOR "white"
119#define QUESTION_WIN_BG_COLOR ALL_WINS_BG_COLOR
120#define QUESTION_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
121#define QUESTION_WIN_FONT
122#define QUESTION_WIN_STYLE
123
124#define WARNING_WIN_TEXT_COLOR "orange"
125#define WARNING_WIN_BG_COLOR ALL_WINS_BG_COLOR
126#define WARNING_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
127#define WARNING_WIN_FONT
128#define WARNING_WIN_STYLE
129
130#define ERROR_WIN_TEXT_COLOR "red"
131#define ERROR_WIN_BG_COLOR ALL_WINS_BG_COLOR
132#define ERROR_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
133#define ERROR_WIN_FONT
134#define ERROR_WIN_STYLE
135
136/*
137 * Default, modifiable colors
138 * Never used:
139 * win_colors.warning[BG_I]
140 * win_colors.warning[BORDER_I]
141 * win_colors.error[BG_I],
142 * win_colors.error[BORDER_I]
143 * Almost never used:
144 * win_colors.question[BG_I]
145 * win_colors.question[BORDER_I]
146 */
147
148typedef struct {
149 LG_Color_u info[3]; /* Text, bg, and border */
152 LG_Color_u error[3];
154
155/* and for each their indices */
156enum {TEXT_I, BG_I, BORDER_I};
157
158/* Fonts things */
159#define N_FONTS_MAX 256
160
161typedef struct {
162 LG_String *name;
163 LG_String *relative_path; /* Path inside the fonts folder, not relative if symlink */
164 int size;
165 TTF_Font *f;
166} LG_Font;
167
168/* Font description */
169typedef struct {
170 const char *name;
171 const char *relative_path; /* Path inside the fonts folder, not relative if symlink */
172 int size;
174
175void lg_info_win_no_block(const char *, zboolean, zboolean);
176
177void lg_info_win(const char *, zboolean, zboolean);
178
179void lg_info_win_s(const char *, LG_Win_Style *); /* swap_fb */
180
181int lg_question_win(const char *); /* swap_fb */
182
183int lg_question_win_s(const char *, LG_Win_Style *); /* swap_fb */
184
185void lg_warning_win(const char *); /* swap_fb */
186
187void lg_error_win(const char *); /* swap_fb */
188
189char *lg_entry_win(const char *, int, int); /* swap_fb */
190
191char *lg_entry_win_s(const char *, int, int, LG_Win_Style *); /* swap_fb */
192
194
195LG_Window lg_win(const char *, LG_Color_u, LG_Color_u, zboolean, LG_Color_u, TTF_Font *, int, LG_Color_u, LG_Color_u);
196
198
199int lg_menu_win(const char *, LG_Color_u, LG_Color_u, LG_Color_u, LG_Color_u, TTF_Font *, int, int, int); /* may swap_fb */
200
202
204
206
208
209int lg_win_open(LG_Window *, int, int);
210
212
214
215zboolean is_lg_win(LG_Window *);
216
218
220
222
224
226
227char *lg_wrap_lines(const char *, TTF_Font *, int);
228
229void lg_fonts_list_init();
230
232
233zboolean lg_font_add_to_list(const char *, const char *, int);
234
235LG_Font *lg_font_get(const char *);
236
237TTF_Font *lg_font_get_ttf(const char *);
238
239void lg_font_free(const char *);
240
241void lg_font_free_all();
242
243void lg_font_list_all();
244
245void lg_font_info(LG_Font *);
246
247zboolean lg_font_load_array(LG_Font_Des [], int);
248
249void lg_font_list_array(LG_Font_Des [], int);
250
251#endif /* LG_WIN_H */
void warning(int block, const char *format,...)
Definition lg_error.c:79
int lg_win_open_centered(LG_Window *win)
Definition lg_wins.c:622
char * lg_entry_win(const char *label, int x, int y)
Definition lg_wins.c:464
void lg_info_win_s(const char *text, LG_Win_Style *style)
Definition lg_wins.c:121
LG_MenuWinParams * lg_get_menu_wins_params()
Definition lg_wins.c:947
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)
Definition lg_wins.c:1142
zboolean lg_fonts_list_is_initialized()
Definition lg_wins.c:1674
void lg_win_free_tex(LG_Window *win)
Definition lg_wins.c:1424
void lg_info_win(const char *text, zboolean with_frame, zboolean swap_fb)
Definition lg_wins.c:71
char * lg_action_func_to_str(LG_ActionFunc actions_funcs[])
Definition lg_wins.c:1275
void lg_font_info(LG_Font *font)
Definition lg_wins.c:1865
int lg_win_get_h(LG_Window *win)
Definition lg_wins.c:1513
char * lg_entry_win_s(const char *label, int x, int y, LG_Win_Style *style)
Definition lg_wins.c:496
void lg_font_free(const char *name)
Definition lg_wins.c:1800
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)
Definition lg_wins.c:664
int lg_question_win_s(const char *text, LG_Win_Style *style)
Definition lg_wins.c:279
void lg_warning_win(const char *text)
Definition lg_wins.c:374
void lg_font_free_all()
Definition lg_wins.c:1825
LG_Font * lg_font_get(const char *name)
Definition lg_wins.c:1757
zboolean is_lg_win(LG_Window *win)
Definition lg_wins.c:1436
LG_WinColors * lg_win_get_colors()
Definition lg_wins.c:1527
void lg_fonts_list_init()
Definition lg_wins.c:1660
int lg_win_close(LG_Window *win)
Definition lg_wins.c:1410
void lg_win_show_annoying_errors()
Definition lg_wins.c:1320
Rec2Di lg_get_centered_win_rect(LG_Window *win)
Definition lg_wins.c:1469
char * lg_action_func_to_str2(LG_ActionFunc2 actions_funcs[])
Definition lg_wins.c:1298
zboolean lg_font_load_array(LG_Font_Des fonts[], int n_fonts)
Definition lg_wins.c:1894
TTF_Font * lg_font_get_ttf(const char *name)
Definition lg_wins.c:1777
void lg_font_list_all()
Definition lg_wins.c:1848
int lg_win_open(LG_Window *win, int x, int y)
Definition lg_wins.c:1343
void lg_win_set_default_colors()
Definition lg_wins.c:1535
zboolean lg_font_add_to_list(const char *name, const char *relative_path, int size)
Definition lg_wins.c:1706
void lg_info_win_no_block(const char *text, zboolean with_frame, zboolean swap_fb)
Definition lg_wins.c:32
void lg_error_win(const char *text)
Definition lg_wins.c:412
int lg_question_win(const char *text)
Definition lg_wins.c:180
void lg_font_list_array(LG_Font_Des fonts[], int n_fonts)
Definition lg_wins.c:1919
char * lg_wrap_lines(const char *txt, TTF_Font *font, int max_width)
Definition lg_wins.c:1569
int lg_win_get_w(LG_Window *win)
Definition lg_wins.c:1500
void lg_win_no_annoying_errors()
Definition lg_wins.c:1328
zboolean question(const char *str)
Definition misc.c:87
Definition lg_wins.h:82
Definition lg_wins.h:77
Definition lg_vertex.h:111
Definition lg_wins.h:169
Definition lg_wins.h:161
Definition lg_wins.h:69
Definition lg_string.h:17
Definition lg_wins.h:104
Definition lg_textures.h:50
Definition lg_wins.h:97
Definition lg_wins.h:148
Definition lg_wins.h:56
Definition lg_wins.h:45
Definition lg_gr_func.h:49