LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_wins.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2024
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 #define WARNING_TIMEOUT 3000
26 
27 /* Fully transparent colors actually */
28 #define UNUSED_SDL_COLOR ((SDL_Color){0, 0, 0, 0})
29 #define UNUSED_LG_COLOR_U ((LG_Color_u){0, 0, 0, 0})
30 
31 #define TMP_STR_MAXLEN 1023
32 
33 #define H_PADDING 12
34 #define V_PADDING 8
35 #define BORDER_WIDTH 2
36 
37 #define LG_WIN_TXT_NBSP '~'
38 
39 /* TODO: what if win text is over 24 lines ? */
40 #define LG_WIN_N_LINES_MAX 24
41 
42 #define LG_LEFT_MARGIN 5
43 #define LG_BOTTOM_MARGIN 5
44 
45 #define LG_WIN_TIMESTAMP_MAXLEN (64 - 1)
46 
47 typedef struct {
48  int id; /* (So far) 0 -> OK, -1 -> invalid win */
49  LG_Texture *tex; /* Used inside new/open/close/free_win(), don't modify elsewhere */
50  Rec2Di text_rect;
51  int x;
52  int y;
53  /* === Don't modify === */
54  int w;
55  int h;
56  int last_open_x;
57  int last_open_y;
58  char timestamp[LG_WIN_TIMESTAMP_MAXLEN + 1];
59 } LG_Window;
60 
61 /* Wins colors */
62 #define ALL_WINS_BG_COLOR "dark-grey2"
63 #define ALL_WINS_BORDER_COLOR "dark-grey2"
64 
65 #define INFO_WIN_TEXT_COLOR "white"
66 #define INFO_WIN_BG_COLOR ALL_WINS_BG_COLOR
67 #define INFO_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
68 #define INFO_WIN_FONT
69 #define INFO_WIN_STYLE
70 
71 #define QUESTION_WIN_TEXT_COLOR "white"
72 #define QUESTION_WIN_BG_COLOR ALL_WINS_BG_COLOR
73 #define QUESTION_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
74 #define QUESTION_WIN_FONT
75 #define QUESTION_WIN_STYLE
76 
77 #define WARNING_WIN_TEXT_COLOR "orange"
78 #define WARNING_WIN_BG_COLOR ALL_WINS_BG_COLOR
79 #define WARNING_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
80 #define WARNING_WIN_FONT
81 #define WARNING_WIN_STYLE
82 
83 #define ERROR_WIN_TEXT_COLOR "red"
84 #define ERROR_WIN_BG_COLOR ALL_WINS_BG_COLOR
85 #define ERROR_WIN_BORDER_COLOR ALL_WINS_BORDER_COLOR
86 #define ERROR_WIN_FONT
87 #define ERROR_WIN_STYLE
88 
89 /*
90  * Default, modifiable colors
91  * Never used:
92  * win_colors.warning[BG_I]
93  * win_colors.warning[BORDER_I]
94  * win_colors.error[BG_I],
95  * win_colors.error[BORDER_I]
96  * Almost never used:
97  * win_colors.question[BG_I]
98  * win_colors.question[BORDER_I]
99  */
100 typedef struct {
101  LG_Color_u info[3]; /* Text, bg, and border */
102  LG_Color_u question[3];
103  LG_Color_u warning[3];
104  LG_Color_u error[3];
105 } LG_WinColors;
106 
107 /* and for each their indexes */
108 enum {TEXT_I, BG_I, BORDER_I};
109 
110 void lg_info_win_no_block(const char *, zboolean, zboolean);
111 
112 void lg_info_win(const char *, zboolean, zboolean);
113 
114 int lg_question_win(const char *); /* swap_fb */
115 
116 void lg_warning_win(const char *); /* swap_fb */
117 
118 void lg_error_win(const char *); /* swap_fb */
119 
120 char *lg_entry_win(const char *, int, int); /* swap_fb */
121 
123 
124 LG_Window lg_win(const char *, LG_Color_u, zboolean, LG_Color_u, LG_Color_u, TTF_Font *);
125 
126 int lg_win_open(LG_Window *, int, int);
127 
128 int lg_win_close(LG_Window *);
129 
130 void lg_win_free_tex(LG_Window *);
131 
132 int lg_get_win_w(LG_Window *);
133 
134 int lg_get_win_h(LG_Window *);
135 
136 void lg_set_fonts(TTF_Font *, TTF_Font *, TTF_Font *, TTF_Font *, TTF_Font *, TTF_Font *, TTF_Font *);
137 
138 TTF_Font *lg_get_small_font();
139 
140 TTF_Font *lg_get_medium_font();
141 
142 TTF_Font *lg_get_large_font();
143 
144 TTF_Font *lg_get_big_font();
145 
146 TTF_Font *lg_get_big_papyrus_font();
147 
148 TTF_Font *lg_get_very_big_papyrus_font();
149 
151 
153 
155 
156 char *lg_wrap_lines(const char *, TTF_Font *);
157 
158 #endif /* LG_WIN_H */
lg_question_win
int lg_question_win(const char *text)
Definition: lg_wins.c:123
lg_set_fonts
void lg_set_fonts(TTF_Font *small_f, TTF_Font *medium_f, TTF_Font *large_f, TTF_Font *big_f, TTF_Font *big_papyrus_f, TTF_Font *very_big_papyrus_f, TTF_Font *large_intelone_mono_f)
Definition: lg_wins.c:834
lg_get_win_h
int lg_get_win_h(LG_Window *win)
Definition: lg_wins.c:824
lg_win_open
int lg_win_open(LG_Window *win, int x, int y)
Definition: lg_wins.c:664
lg_get_medium_font
TTF_Font * lg_get_medium_font()
Definition: lg_wins.c:867
lg_get_very_big_papyrus_font
TTF_Font * lg_get_very_big_papyrus_font()
Definition: lg_wins.c:907
lg_win_close
int lg_win_close(LG_Window *win)
Definition: lg_wins.c:738
lg_get_large_font
TTF_Font * lg_get_large_font()
Definition: lg_wins.c:877
lg_win_free_tex
void lg_win_free_tex(LG_Window *win)
Definition: lg_wins.c:800
lg_warning_win
void lg_warning_win(const char *text)
Definition: lg_wins.c:188
LG_WinColors
Definition: lg_wins.h:100
lg_win_open_centered
int lg_win_open_centered(LG_Window *win)
Definition: lg_wins.c:369
lg_win
LG_Window lg_win(const char *text, LG_Color_u text_color, zboolean with_frame, LG_Color_u bg_color, LG_Color_u border_color, TTF_Font *font)
Definition: lg_wins.c:409
lg_get_small_font
TTF_Font * lg_get_small_font()
Definition: lg_wins.c:857
lg_get_win_colors
LG_WinColors * lg_get_win_colors()
Definition: lg_wins.c:927
LG_Color_u
Definition: lg_vertex.h:91
lg_info_win
void lg_info_win(const char *text, zboolean with_frame, zboolean swap_fb)
Definition: lg_wins.c:78
lg_entry_win
char * lg_entry_win(const char *label, int x, int y)
Definition: lg_wins.c:264
lg_wrap_lines
char * lg_wrap_lines(const char *txt, TTF_Font *font)
Definition: lg_wins.c:966
LG_Texture
Definition: lg_textures.h:42
question
zboolean question(const char *str)
Definition: misc.c:81
lg_set_default_win_colors
void lg_set_default_win_colors()
Definition: lg_wins.c:935
LG_Window
Definition: lg_wins.h:47
lg_get_win_w
int lg_get_win_w(LG_Window *win)
Definition: lg_wins.c:813
lg_error_win
void lg_error_win(const char *text)
Definition: lg_wins.c:222
warning
void warning(int block, const char *format,...)
Definition: lg_error.c:82
lg_get_big_papyrus_font
TTF_Font * lg_get_big_papyrus_font()
Definition: lg_wins.c:897
lg_info_win_no_block
void lg_info_win_no_block(const char *text, zboolean with_frame, zboolean swap_fb)
Definition: lg_wins.c:43
lg_get_big_font
TTF_Font * lg_get_big_font()
Definition: lg_wins.c:887
lg_get_large_intelone_mono_font
TTF_Font * lg_get_large_intelone_mono_font()
Definition: lg_wins.c:917
Rec2Di
Definition: lg_gr_func.h:47