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 TIMESTAMP_MAXLEN (64 - 1)
44
45typedef struct {
46 int id; /* (So far) 0 -> OK, -1 -> invalid win */
47 int total_n_lines;
48 int n_visible_lines;
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 tex_area;
58 Rec2Di visible_area;
59 char timestamp[TIMESTAMP_MAXLEN + 1];
60} LG_Window;
61
62/* UD_FONTNAME_MAX_LEN is defined in lg_fonts.h */
63
64typedef struct {
65 zboolean with_frame;
66 LG_Color_u text_color;
67 LG_Color_u bg_color;
68 LG_Color_u border_color;
69 LG_Color_u highlight_text_color; /* Should be highlighted_text_color */
70 LG_Color_u highlight_bg_color; /* Should be highlighted_bg_color */
71 int frame_line; /* NONE, TZW_RECTANGLE, or TZW_RECT_CORNERS */
72 LG_Color_u frame_line_color;
73 char ud_font_name[UD_FONTNAME_MAX_LEN + 1]; /* User-defined name, like "dejavu_sans_bold_18" */
75
76/* lg_menu_win() global extra params, all initialized to FALSE or NULL */
77typedef struct {
78 zboolean with_frame;
79 zboolean loop;
80 zboolean no_swap; /* No swap and no bg draw */
81 LG_Texture *orig_bg; /* (if !no_swap) lg_take_screenshot(); */
82 zboolean disable_h_arrows; /* Left and right arrows */
84
85typedef struct {
86 const char *str;
87 void (*func)();
89
90typedef struct {
91 const char *str;
92 int (*func)();
94
95#define MENUWIN_KEY_ESC (-1)
96#define MENUWIN_KEY_LEFT (-2)
97#define MENUWIN_KEY_RIGHT (-3)
98#define MENUWIN_KEY_SPACE (-4)
99#define MENUWIN_ERROR (-5)
100
101typedef enum {MENUWIN_CONTINUE, MENUWIN_CLOSE, MENUWIN_EXIT, MENUWIN_SPACE_PRESSED} menuwin_exit;
102
103/* TZW stuff used in lg_ui.c/h */
104#define N_TZW_MAX 1024
105
106typedef struct {
107 LG_Window win;
108 LG_Color_u color;
109 Rec2Di area;
111
112/* Array of all TZ wins for one frame */
113typedef struct {
114 LG_TouchZoneWindow *tzw[N_TZW_MAX];
116
117void lg_info_win(LG_Win_Style *style, const char *format, ...); /* Swap fb */
118
119void lg_info_win_no_block(zboolean, zboolean, const char *); /* May swap fb */
120
121void lg_error_win(LG_Win_Style *style, zboolean log, const char *format, ...); /* Swap fb */
122
123int lg_question_win(LG_Win_Style *, const char *, ...); /* Swap fb */
124
125char *lg_entry_win(LG_Win_Style *, int, int, const char *); /* Swap fb */
126
127int lg_win_open_centered(LG_Window *, uint32_t);
128
129LG_Window lg_win(const char *, LG_Color_u, LG_Color_u, zboolean, LG_Color_u, TTF_Font *, int, LG_Color_u, LG_Color_u);
130
132
133int 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 */
134
136
138
139void lg_scrollable_win(LG_Win_Style *, int, const char *);
140
141//zboolean lg_winstyle_set_global();
142
143//LG_Win_Style lg_winstyle_get_global();
144
146
148
149int lg_win_open(LG_Window *, int, int, uint32_t);
150
151int lg_win_close(LG_Window *);
152
154
155zboolean is_lg_win(LG_Window *);
156
158
160
162
163int lg_text_get_n_lines(const char *);
164
165char *lg_text_format_for_win(const char *, TTF_Font *);
166
167char *lg_wrap_lines(const char *, TTF_Font *, int);
168
169#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:944
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:1162
void lg_win_free_tex(LG_Window *win)
Definition lg_wins.c:1524
char * lg_action_func_to_str(LG_ActionFunc actions_funcs[])
Definition lg_wins.c:1305
int lg_win_get_h(LG_Window *win)
Definition lg_wins.c:1617
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:908
char * lg_text_format_for_win(const char *text, TTF_Font *font)
Definition lg_wins.c:1661
int lg_win_open(LG_Window *win, int x, int y, uint32_t v_shift)
Definition lg_wins.c:1448
char * lg_wrap_lines(const char *text, TTF_Font *font, int max_width)
Definition lg_wins.c:1721
zboolean is_lg_win(LG_Window *win)
Definition lg_wins.c:1536
void lg_error_win(LG_Win_Style *style, zboolean log, const char *format,...)
Definition lg_wins.c:153
int lg_win_open_centered(LG_Window *win, uint32_t v_shift)
Definition lg_wins.c:531
void lg_win_show_annoying_errors()
Definition lg_wins.c:1424
void lg_info_win_no_block(zboolean with_frame, zboolean swap_fb, const char *text)
Definition lg_wins.c:114
void lg_info_win(LG_Win_Style *style, const char *format,...)
Definition lg_wins.c:39
void lg_scrollable_win(LG_Win_Style *style, int display_n_lines, const char *text)
Definition lg_wins.c:1360
Rec2Di lg_get_centered_win_rec(LG_Window *win)
Definition lg_wins.c:1569
char * lg_action_func_to_str2(LG_ActionFunc2 actions_funcs[])
Definition lg_wins.c:1335
int lg_question_win(LG_Win_Style *style, const char *format,...)
Definition lg_wins.c:240
int lg_text_get_n_lines(const char *text)
Definition lg_wins.c:1637
int lg_win_get_w(LG_Window *win)
Definition lg_wins.c:1602
void lg_win_no_annoying_errors()
Definition lg_wins.c:1432
Definition lg_wins.h:90
Definition lg_wins.h:85
Definition lg_vertex.h:111
Definition lg_wins.h:77
Definition lg_wins.h:113
Definition lg_textures.h:50
Definition lg_wins.h:106
Definition lg_wins.h:64
Definition lg_wins.h:45
Definition lg_gr_func.h:49