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 char timestamp[TIMESTAMP_MAXLEN + 1];
53} LG_Window;
54
55typedef struct {
56 zboolean with_frame;
57 LG_Color_u text_color;
58 LG_Color_u bg_color;
59 LG_Color_u border_color;
60 LG_Color_u highlight_text_color;
61 LG_Color_u highlight_bg_color;
62 int frame_line; /* NONE, TZW_RECTANGLE, or TZW_RECT_CORNERS */
63 LG_Color_u frame_line_color;
64 const char *font;
66
67/* lg_menu_win() global extra params, all initialized to FALSE or NULL */
68typedef struct {
69 zboolean with_frame;
70 zboolean loop;
71 zboolean no_swap; /* No swap and no bg draw */
72 LG_Texture *orig_bg; /* (if !no_swap) lg_take_screenshot(); */
73 zboolean disable_h_arrows; /* Left and right arrows */
75
76typedef struct {
77 const char *str;
78 void (*func)();
80
81typedef struct {
82 const char *str;
83 int (*func)();
85
86/* Wins colors */
87#define ALL_WINS_BG_COLOR "dark-grey2"
88#define ALL_WINS_BORDER_COLOR "dark-grey2"
89
90#define INFO_WIN_TEXT_COLOR "white"
91#define INFO_WIN_BG_COLOR ALL_WINS_BG_COLOR
92#define INFO_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
93#define INFO_WIN_FONT
94#define INFO_WIN_STYLE
95
96#define QUESTION_WIN_TEXT_COLOR "white"
97#define QUESTION_WIN_BG_COLOR ALL_WINS_BG_COLOR
98#define QUESTION_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
99#define QUESTION_WIN_FONT
100#define QUESTION_WIN_STYLE
101
102#define WARNING_WIN_TEXT_COLOR "orange"
103#define WARNING_WIN_BG_COLOR ALL_WINS_BG_COLOR
104#define WARNING_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
105#define WARNING_WIN_FONT
106#define WARNING_WIN_STYLE
107
108#define ERROR_WIN_TEXT_COLOR "red"
109#define ERROR_WIN_BG_COLOR ALL_WINS_BG_COLOR
110#define ERROR_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
111#define ERROR_WIN_FONT
112#define ERROR_WIN_STYLE
113
114/*
115 * Default, modifiable colors
116 * Never used:
117 * win_colors.warning[BG_I]
118 * win_colors.warning[BORDER_I]
119 * win_colors.error[BG_I],
120 * win_colors.error[BORDER_I]
121 * Almost never used:
122 * win_colors.question[BG_I]
123 * win_colors.question[BORDER_I]
124 */
125
126typedef struct {
127 LG_Color_u info[3]; /* Text, bg, and border */
128 LG_Color_u question[3];
130 LG_Color_u error[3];
132
133/* and for each their indices */
134enum {TEXT_I, BG_I, BORDER_I};
135
136/* Fonts things */
137#define N_FONTS_MAX 256
138
139typedef struct {
140 LG_String *name;
141 LG_String *relative_path; /* Path inside the fonts folder, not relative if symlink */
142 int size;
143 TTF_Font *f;
144} LG_Font;
145
146/* Font description */
147typedef struct {
148 const char *name;
149 const char *relative_path; /* Path inside the fonts folder, not relative if symlink */
150 int size;
152
153void lg_info_win_no_block(const char *, zboolean, zboolean);
154
155void lg_info_win(const char *, zboolean, zboolean);
156
157void lg_info_win_s(const char *, LG_Win_Style *); /* swap_fb */
158
159int lg_question_win(const char *); /* swap_fb */
160
161int lg_question_win_s(const char *, LG_Win_Style *); /* swap_fb */
162
163void lg_warning_win(const char *); /* swap_fb */
164
165void lg_error_win(const char *); /* swap_fb */
166
167char *lg_entry_win(const char *, int, int); /* swap_fb */
168
169char *lg_entry_win_s(const char *, int, int, LG_Win_Style *); /* swap_fb */
170
172
173LG_Window lg_win(const char *, LG_Color_u, LG_Color_u, zboolean, LG_Color_u, TTF_Font *, int, LG_Color_u, LG_Color_u);
174
176
177int lg_menu_win(const char *, LG_Color_u, LG_Color_u, LG_Color_u, LG_Color_u, TTF_Font *, int, int, int); /* swap_fb */
178
180
182
184
186
187int lg_win_open(LG_Window *, int, int);
188
190
192
193zboolean is_lg_win(LG_Window *);
194
196
198
200
202
204
205char *lg_wrap_lines(const char *, TTF_Font *, int);
206
207void lg_fonts_list_init();
208
210
211zboolean lg_font_add_to_list(const char *, const char *, int);
212
213LG_Font *lg_font_get(const char *);
214
215TTF_Font *lg_font_get_ttf(const char *);
216
217void lg_font_free(const char *);
218
219void lg_font_free_all();
220
221void lg_font_list_all();
222
223void lg_font_info(LG_Font *);
224
225zboolean lg_font_load_array(LG_Font_Des [], int);
226
227void lg_font_list_array(LG_Font_Des [], int);
228
229#endif /* LG_WIN_H */
void warning(int block, const char *format,...)
Definition lg_error.c:83
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:1065
zboolean lg_fonts_list_is_initialized()
Definition lg_wins.c:1553
void lg_win_free_tex(LG_Window *win)
Definition lg_wins.c:1303
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:1154
void lg_font_info(LG_Font *font)
Definition lg_wins.c:1744
int lg_win_get_h(LG_Window *win)
Definition lg_wins.c:1392
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:1679
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:1704
LG_Font * lg_font_get(const char *name)
Definition lg_wins.c:1636
zboolean is_lg_win(LG_Window *win)
Definition lg_wins.c:1315
LG_WinColors * lg_win_get_colors()
Definition lg_wins.c:1406
void lg_fonts_list_init()
Definition lg_wins.c:1539
int lg_win_close(LG_Window *win)
Definition lg_wins.c:1289
void lg_win_show_annoying_errors()
Definition lg_wins.c:1199
Rec2Di lg_get_centered_win_rect(LG_Window *win)
Definition lg_wins.c:1348
char * lg_action_func_to_str2(LG_ActionFunc2 actions_funcs[])
Definition lg_wins.c:1177
zboolean lg_font_load_array(LG_Font_Des fonts[], int n_fonts)
Definition lg_wins.c:1773
TTF_Font * lg_font_get_ttf(const char *name)
Definition lg_wins.c:1656
void lg_font_list_all()
Definition lg_wins.c:1727
int lg_win_open(LG_Window *win, int x, int y)
Definition lg_wins.c:1222
void lg_win_set_default_colors()
Definition lg_wins.c:1414
zboolean lg_font_add_to_list(const char *name, const char *relative_path, int size)
Definition lg_wins.c:1585
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:1798
char * lg_wrap_lines(const char *txt, TTF_Font *font, int max_width)
Definition lg_wins.c:1448
int lg_win_get_w(LG_Window *win)
Definition lg_wins.c:1379
void lg_win_no_annoying_errors()
Definition lg_wins.c:1207
Definition lg_wins.h:81
Definition lg_wins.h:76
Definition lg_vertex.h:111
Definition lg_wins.h:147
Definition lg_wins.h:139
Definition lg_wins.h:68
Definition lg_string.h:17
Definition lg_textures.h:45
Definition lg_wins.h:126
Definition lg_wins.h:55
Definition lg_wins.h:45
Definition lg_gr_func.h:49