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 TMP_STR_MAXLEN 1023
33
34#define H_PADDING 12
35#define V_PADDING 8
36#define BORDER_WIDTH 2
37
38#define LG_WIN_N_LINES_MAX 200
39
40#define LG_LEFT_MARGIN 5
41#define LG_BOTTOM_MARGIN 5
42
43#define LG_WIN_SCROLL_SHIFT_SIZE 8
44
45#define TIMESTAMP_MAXLEN (64 - 1)
46
47typedef struct {
48 int id; /* (So far) 0 -> OK, -1 -> invalid win */
49 LG_Texture *tex; /* Used inside new/open/free_win(), don't modify elsewhere */
50 uint32_t tex_w;
51 uint32_t tex_h;
52 int last_open_x; /* Set by lg_win_open() */
53 int last_open_y; /* Set by lg_win_open() */
54 Rec2Di layout_rec[LG_WIN_N_LINES_MAX]; /* Clickable areas for menu items */
55 uint32_t h_margin;
56 uint32_t v_margin;
57 Rec2Di visible_area;
58 char timestamp[TIMESTAMP_MAXLEN + 1];
59} LG_Window;
60
61/* UD_FONTNAME_MAX_LEN is defined in lg_fonts.h */
62
63typedef struct {
64 zboolean with_frame;
65 LG_Color_u text_color;
66 LG_Color_u bg_color;
67 LG_Color_u border_color;
68 LG_Color_u highlight_text_color; /* Should be highlighted_text_color */
69 LG_Color_u highlight_bg_color; /* Should be highlighted_bg_color */
70 int frame_line; /* NONE, TZW_RECTANGLE, or TZW_RECT_CORNERS */
71 LG_Color_u frame_line_color;
72 char ud_font_name[UD_FONTNAME_MAX_LEN + 1]; /* User-defined name, like "dejavu_sans_bold_18" */
74
75/* lg_menu_win() global extra params, all initialized to FALSE or NULL */
76typedef struct {
77 zboolean with_frame;
78 zboolean loop;
79 zboolean no_swap; /* No swap and no bg draw */
80 LG_Texture *orig_bg; /* (if !no_swap) lg_take_screenshot(); */
81 zboolean disable_h_arrows; /* Left and right arrows */
83
84typedef struct {
85 const char *str;
86 void (*func)();
88
89typedef struct {
90 const char *str;
91 int (*func)();
93
94#define MENUWIN_KEY_ESC (-1)
95#define MENUWIN_KEY_LEFT (-2)
96#define MENUWIN_KEY_RIGHT (-3)
97#define MENUWIN_KEY_SPACE (-4)
98#define MENUWIN_ERROR (-5)
99
100typedef enum {MENUWIN_CONTINUE, MENUWIN_CLOSE, MENUWIN_EXIT, MENUWIN_SPACE_PRESSED} menuwin_exit;
101
102/* TZW stuff used in lg_ui.c/h */
103#define N_TZW_MAX 1024
104
105typedef struct {
106 LG_Window win;
107 LG_Color_u color;
108 Rec2Di area;
110
111/* Array of all TZ wins for one frame */
112typedef struct {
113 LG_TouchZoneWindow *tzw[N_TZW_MAX];
115
116void lg_info_win(LG_Win_Style *style, const char *format, ...); /* Swap fb */
117
118void lg_info_win_no_block(zboolean, zboolean, const char *); /* May swap fb */
119
120void lg_error_win(LG_Win_Style *style, zboolean log, const char *format, ...); /* Swap fb */
121
122int lg_question_win(LG_Win_Style *, const char *, ...); /* Swap fb */
123
124char *lg_entry_win(LG_Win_Style *, int, int, const char *); /* Swap fb */
125
126int lg_win_open_centered(LG_Window *, uint32_t *);
127
128LG_Window lg_win(const char *, LG_Color_u, LG_Color_u, zboolean, LG_Color_u, TTF_Font *, int, LG_Color_u, LG_Color_u);
129
131
132int 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 */
133
135
137
138void lg_scrollable_win(LG_Win_Style *, int, int, int, const char *);
139
140void lg_set_scrolling_shift_size(uint32_t);
141
143
144//zboolean lg_winstyle_set_global();
145
146//LG_Win_Style lg_winstyle_get_global();
147
149
151
152int lg_win_open(LG_Window *, int, int, uint32_t *);
153
154int lg_win_close(LG_Window *);
155
157
158zboolean is_lg_win(LG_Window *);
159
161
163
165
166int lg_text_get_n_lines(const char *);
167
168char *lg_text_format_for_win(const char *, TTF_Font *);
169
170char *lg_wrap_lines(const char *, TTF_Font *, int);
171
172#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:897
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:1115
void lg_win_free_tex(LG_Window *win)
Definition lg_wins.c:1507
char * lg_action_func_to_str(LG_ActionFunc actions_funcs[])
Definition lg_wins.c:1258
void lg_reset_default_scrolling_shift_size()
Definition lg_wins.c:1381
int lg_win_get_h(LG_Window *win)
Definition lg_wins.c:1600
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:864
char * lg_text_format_for_win(const char *text, TTF_Font *font)
Definition lg_wins.c:1644
char * lg_wrap_lines(const char *text, TTF_Font *font, int max_width)
Definition lg_wins.c:1704
zboolean is_lg_win(LG_Window *win)
Definition lg_wins.c:1519
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:1409
void lg_set_scrolling_shift_size(uint32_t scrolling_shift_size)
Definition lg_wins.c:1372
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:1433
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:1552
char * lg_action_func_to_str2(LG_ActionFunc2 actions_funcs[])
Definition lg_wins.c:1288
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:1321
int lg_text_get_n_lines(const char *text)
Definition lg_wins.c:1620
int lg_win_open_centered(LG_Window *win, uint32_t *v_shift)
Definition lg_wins.c:531
int lg_win_get_w(LG_Window *win)
Definition lg_wins.c:1585
void lg_win_no_annoying_errors()
Definition lg_wins.c:1417
Definition lg_wins.h:89
Definition lg_wins.h:84
Definition lg_vertex.h:111
Definition lg_wins.h:76
Definition lg_wins.h:112
Definition lg_textures.h:50
Definition lg_wins.h:105
Definition lg_wins.h:63
Definition lg_wins.h:47
Definition lg_gr_func.h:49