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_WINS_H
7#define LG_WINS_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 NO_FRAME (!WITH_FRAME)
15
16#define SWAP_FB TRUE
17#define NO_SWAP (!SWAP_FB)
18
19#define LOG TRUE
20#define NO_LOG (!LOG)
21
22#if defined(LINUX_V) || defined(WIN32_V)
23 #define PRESS_OR_TAP_ANYTHING "Press any key ..."
24#elif defined(ANDROID_V)
25 #define PRESS_OR_TAP_ANYTHING "Tap anywhere to continue ..."
26#endif
27
28/* Fully transparent colors actually */
29#define UNUSED_SDL_COLOR ((SDL_Color){0, 0, 0, 0})
30#define UNUSED_LG_COLOR_U ((LG_Color_u){0, 0, 0, 0})
31
32#define H_PADDING 12
33#define V_PADDING 8
34#define BORDER_WIDTH 2
35
36#define LG_WIN_N_LINES_MAX 200
37
38#define LG_LEFT_MARGIN 5
39#define LG_BOTTOM_MARGIN 5
40
41#define SCROLL_V_SHIFT_IN_PIXELS 8
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/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_rec[LG_WIN_N_LINES_MAX]; /* Clickable areas for menu items */
53 uint32_t h_margin;
54 uint32_t v_margin;
55 Rec2Di visible_area;
56 char timestamp[TIMESTAMP_MAXLEN + 1];
57} LG_Window;
58
59/* UD_FONTNAME_MAX_LEN is defined in lg_fonts.h */
60
61typedef struct {
62 zboolean with_frame;
63 LG_Color_u text_color;
64 LG_Color_u bg_color;
65 LG_Color_u border_color;
66 LG_Color_u highlight_text_color; /* Should be highlighted_text_color */
67 LG_Color_u highlight_bg_color; /* Should be highlighted_bg_color */
68 int frame_line; /* NONE, TZW_RECTANGLE, or TZW_RECT_CORNERS */
69 LG_Color_u frame_line_color;
70 char ud_font_name[UD_FONTNAME_MAX_LEN + 1]; /* User-defined name, like "dejavu_sans_bold_18" */
72
73/* lg_menu_win() global extra params, all initialized to FALSE or NULL */
74typedef struct {
75 zboolean with_frame;
76 zboolean loop;
77 zboolean no_swap; /* No swap and no bg draw */
78 LG_Texture *orig_bg; /* (if !no_swap) lg_take_screenshot(); */
79 zboolean disable_h_arrows; /* Left and right arrows */
81
82typedef struct {
83 const char *str;
84 void (*func)();
86
87typedef struct {
88 const char *str;
89 int (*func)();
91
92#define MENUWIN_KEY_ESC (-1)
93#define MENUWIN_KEY_LEFT (-2)
94#define MENUWIN_KEY_RIGHT (-3)
95#define MENUWIN_KEY_SPACE (-4)
96#define MENUWIN_ERROR (-5)
97
98typedef enum {MENUWIN_CONTINUE, MENUWIN_CLOSE, MENUWIN_EXIT, MENUWIN_SPACE_PRESSED} menuwin_exit;
99
100/* TZW stuff used in lg_ui.c/h */
101#define N_TZW_MAX 1024
102
103typedef struct {
104 LG_Window win;
105 LG_Color_u color;
106 Rec2Di area;
108
109/* Array of all TZ wins for one frame */
110typedef struct {
111 LG_TouchZoneWindow *tzw[N_TZW_MAX];
113
114void lg_info_win(LG_Win_Style *style, const char *format, ...); /* Swap fb */
115
116void lg_info_win_no_block(zboolean, zboolean, const char *); /* May swap fb */
117
118void lg_error_win(LG_Win_Style *style, zboolean log, const char *format, ...); /* Swap fb */
119
120int lg_question_win(LG_Win_Style *, const char *, ...); /* Swap fb */
121
122char *lg_entry_win(LG_Win_Style *, int, int, const char *); /* Swap fb */
123
124int lg_win_open_centered(LG_Window *, uint32_t *);
125
126LG_Window lg_win(const char *, LG_Color_u, LG_Color_u, zboolean, LG_Color_u, TTF_Font *, int, LG_Color_u, LG_Color_u);
127
129
130int 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 */
131
133
135
136void lg_scrollable_win(LG_Win_Style *, int, int, int, const char *);
137
138void lg_set_scrolling_v_shift(uint32_t);
139
141
143
145
146int lg_win_open(LG_Window *, int, int, uint32_t *);
147
148int lg_win_close(LG_Window *);
149
151
152zboolean is_lg_win(LG_Window *);
153
155
157
159
160int lg_text_get_n_lines(const char *);
161
162char *lg_text_format_for_win(const char *, TTF_Font *);
163
164char *lg_wrap_lines(const char *, TTF_Font *, int);
165
166#endif /* LG_WINS_H */
char * lg_entry_win(LG_Win_Style *style, int x, int y, const char *label)
Definition lg_wins.c:377
LG_MenuWinParams * lg_get_menu_wins_params()
Definition lg_wins.c:904
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:1122
void lg_win_free_tex(LG_Window *win)
Definition lg_wins.c:1530
char * lg_action_func_to_str(LG_ActionFunc actions_funcs[])
Definition lg_wins.c:1265
int lg_win_get_h(LG_Window *win)
Definition lg_wins.c:1623
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:871
char * lg_text_format_for_win(const char *text, TTF_Font *font)
Definition lg_wins.c:1667
char * lg_wrap_lines(const char *text, TTF_Font *font, int max_width)
Definition lg_wins.c:1727
void lg_reset_scrolling_v_shift()
Definition lg_wins.c:1404
zboolean is_lg_win(LG_Window *win)
Definition lg_wins.c:1542
void lg_error_win(LG_Win_Style *style, zboolean log, const char *format,...)
Definition lg_wins.c:153
void lg_win_show_annoying_errors()
Definition lg_wins.c:1432
void lg_info_win_no_block(zboolean with_frame, zboolean swap_fb, const char *text)
Definition lg_wins.c:114
int lg_win_open(LG_Window *win, int x, int y, uint32_t *v_shift)
Definition lg_wins.c:1456
void lg_info_win(LG_Win_Style *style, const char *format,...)
Definition lg_wins.c:39
Rec2Di lg_get_centered_win_rec(LG_Window *win)
Definition lg_wins.c:1575
char * lg_action_func_to_str2(LG_ActionFunc2 actions_funcs[])
Definition lg_wins.c:1295
int lg_question_win(LG_Win_Style *style, const char *format,...)
Definition lg_wins.c:240
void lg_scrollable_win(LG_Win_Style *style, int x, int y, int display_n_lines, const char *text)
Definition lg_wins.c:1328
int lg_text_get_n_lines(const char *text)
Definition lg_wins.c:1643
int lg_win_open_centered(LG_Window *win, uint32_t *v_shift)
Definition lg_wins.c:540
void lg_set_scrolling_v_shift(uint32_t v_shift)
Definition lg_wins.c:1395
int lg_win_get_w(LG_Window *win)
Definition lg_wins.c:1608
void lg_win_no_annoying_errors()
Definition lg_wins.c:1440
Definition lg_wins.h:87
Definition lg_wins.h:82
Definition lg_vertex.h:111
Definition lg_wins.h:74
Definition lg_wins.h:110
Definition lg_textures.h:48
Definition lg_wins.h:103
Definition lg_wins.h:61
Definition lg_wins.h:45
Definition lg_gr_func.h:49