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 LG_WIN_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[LG_WIN_TIMESTAMP_MAXLEN + 1];
53} LG_Window;
54
55/* Wins colors */
56#define ALL_WINS_BG_COLOR "dark-grey2"
57#define ALL_WINS_BORDER_COLOR "dark-grey2"
58
59#define INFO_WIN_TEXT_COLOR "white"
60#define INFO_WIN_BG_COLOR ALL_WINS_BG_COLOR
61#define INFO_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
62#define INFO_WIN_FONT
63#define INFO_WIN_STYLE
64
65#define QUESTION_WIN_TEXT_COLOR "white"
66#define QUESTION_WIN_BG_COLOR ALL_WINS_BG_COLOR
67#define QUESTION_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
68#define QUESTION_WIN_FONT
69#define QUESTION_WIN_STYLE
70
71#define WARNING_WIN_TEXT_COLOR "orange"
72#define WARNING_WIN_BG_COLOR ALL_WINS_BG_COLOR
73#define WARNING_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
74#define WARNING_WIN_FONT
75#define WARNING_WIN_STYLE
76
77#define ERROR_WIN_TEXT_COLOR "red"
78#define ERROR_WIN_BG_COLOR ALL_WINS_BG_COLOR
79#define ERROR_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
80#define ERROR_WIN_FONT
81#define ERROR_WIN_STYLE
82
83/*
84 * Default, modifiable colors
85 * Never used:
86 * win_colors.warning[BG_I]
87 * win_colors.warning[BORDER_I]
88 * win_colors.error[BG_I],
89 * win_colors.error[BORDER_I]
90 * Almost never used:
91 * win_colors.question[BG_I]
92 * win_colors.question[BORDER_I]
93 */
94
95typedef struct {
96 LG_Color_u info[3]; /* Text, bg, and border */
97 LG_Color_u question[3];
99 LG_Color_u error[3];
101
102/* and for each their indices */
103enum {TEXT_I, BG_I, BORDER_I};
104
105/* Fonts things */
106#define N_FONTS_MAX 256
107
108typedef struct {
109 LG_String *name;
110 LG_String *relative_path; /* Path inside the fonts folder, not relative if symlink */
111 int size;
112 TTF_Font *f;
113} LG_Font;
114
115/* Font description */
116typedef struct {
117 const char *name;
118 const char *relative_path; /* Path inside the fonts folder, not relative if symlink */
119 int size;
121
122typedef struct {
123 zboolean with_frame;
124 LG_Color_u text_color;
125 LG_Color_u bg_color;
126 LG_Color_u border_color;
127 LG_Color_u highlight_text_color;
128 LG_Color_u highlight_bg_color;
129 const char *font;
131
132/* lg_menu_win() global extra params, all initialized to FALSE or NULL */
133typedef struct {
134 zboolean with_frame;
135 zboolean loop;
136 LG_Texture *orig_bg; /* lg_take_screenshot(); */
137 zboolean disable_h_arrows; /* Left and right arrows */
139
140void lg_info_win_no_block(const char *, zboolean, zboolean);
141
142void lg_info_win(const char *, zboolean, zboolean);
143
144void lg_info_win_s(const char *, LG_Win_Style *); /* swap_fb */
145
146int lg_question_win(const char *); /* swap_fb */
147
148int lg_question_win_s(const char *, LG_Win_Style *); /* swap_fb */
149
150void lg_warning_win(const char *); /* swap_fb */
151
152void lg_error_win(const char *); /* swap_fb */
153
154char *lg_entry_win(const char *, int, int); /* swap_fb */
155
157
158LG_Window lg_win(const char *, LG_Color_u, LG_Color_u, zboolean, LG_Color_u, TTF_Font *, int, LG_Color_u, LG_Color_u);
159
161
162int lg_menu_win(const char *, LG_Color_u, LG_Color_u, LG_Color_u, LG_Color_u, TTF_Font *, int); /* swap_fb */
163
165
167
168int lg_win_open(LG_Window *, int, int);
169
171
173
174zboolean is_lg_win(LG_Window *);
175
177
179
181
183
184char *lg_wrap_lines(const char *, TTF_Font *, int);
185
186void lg_fonts_list_init();
187
189
190zboolean lg_font_add_to_list(const char *, const char *, int);
191
192LG_Font *lg_font_get(const char *);
193
194TTF_Font *lg_font_get_ttf(const char *);
195
196void lg_font_free(const char *);
197
198void lg_font_free_all();
199
200void lg_font_list_all();
201
202void lg_font_info(LG_Font *);
203
204zboolean lg_font_load_array(LG_Font_Des [], int);
205
206void lg_font_list_array(LG_Font_Des [], int);
207
208#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:531
char * lg_entry_win(const char *label, int x, int y)
Definition lg_wins.c:405
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:856
zboolean lg_fonts_list_is_initialized()
Definition lg_wins.c:1375
void lg_win_free_tex(LG_Window *win)
Definition lg_wins.c:1158
void lg_info_win(const char *text, zboolean with_frame, zboolean swap_fb)
Definition lg_wins.c:71
void lg_font_info(LG_Font *font)
Definition lg_wins.c:1566
int lg_win_get_h(LG_Window *win)
Definition lg_wins.c:1214
void lg_font_free(const char *name)
Definition lg_wins.c:1501
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:573
int lg_question_win_s(const char *text, LG_Win_Style *style)
Definition lg_wins.c:246
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)
Definition lg_wins.c:972
void lg_warning_win(const char *text)
Definition lg_wins.c:315
void lg_font_free_all()
Definition lg_wins.c:1526
LG_Font * lg_font_get(const char *name)
Definition lg_wins.c:1458
zboolean is_lg_win(LG_Window *win)
Definition lg_wins.c:1170
LG_WinColors * lg_win_get_colors()
Definition lg_wins.c:1228
void lg_fonts_list_init()
Definition lg_wins.c:1361
int lg_win_close(LG_Window *win)
Definition lg_wins.c:1144
void lg_win_show_annoying_errors()
Definition lg_wins.c:1054
zboolean lg_font_load_array(LG_Font_Des fonts[], int n_fonts)
Definition lg_wins.c:1595
TTF_Font * lg_font_get_ttf(const char *name)
Definition lg_wins.c:1478
void lg_font_list_all()
Definition lg_wins.c:1549
int lg_win_open(LG_Window *win, int x, int y)
Definition lg_wins.c:1077
void lg_win_set_default_colors()
Definition lg_wins.c:1236
zboolean lg_font_add_to_list(const char *name, const char *relative_path, int size)
Definition lg_wins.c:1407
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:353
int lg_question_win(const char *text)
Definition lg_wins.c:170
void lg_font_list_array(LG_Font_Des fonts[], int n_fonts)
Definition lg_wins.c:1620
char * lg_wrap_lines(const char *txt, TTF_Font *font, int max_width)
Definition lg_wins.c:1270
int lg_win_get_w(LG_Window *win)
Definition lg_wins.c:1201
void lg_win_no_annoying_errors()
Definition lg_wins.c:1062
Definition lg_vertex.h:111
Definition lg_wins.h:116
Definition lg_wins.h:108
Definition lg_wins.h:133
Definition lg_string.h:17
Definition lg_textures.h:45
Definition lg_wins.h:95
Definition lg_wins.h:122
Definition lg_wins.h:45