Mercurial > molko
comparison examples/example-message.c @ 157:fb306ed990f8
ui: make message more flexible, closes #2501
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 16 Oct 2020 14:32:22 +0200 |
parents | c3a40062acc2 |
children | e8d2740703df |
comparison
equal
deleted
inserted
replaced
156:c3a40062acc2 | 157:fb306ed990f8 |
---|---|
36 | 36 |
37 #define W (1280) | 37 #define W (1280) |
38 #define H (720) | 38 #define H (720) |
39 | 39 |
40 #define MW (W * 0.75) | 40 #define MW (W * 0.75) |
41 #define MH (H * 0.125) | 41 #define MH (H * 0.130) |
42 #define MX ((W / 2) - (MW / 2)) | 42 #define MX ((W / 2) - (MW / 2)) |
43 #define MY (100) | 43 #define MY (100) |
44 | 44 |
45 static void | 45 static void |
46 init(void) | 46 init(void) |
216 | 216 |
217 static void | 217 static void |
218 smallbottom(void) | 218 smallbottom(void) |
219 { | 219 { |
220 const unsigned int w = window.w / 4; | 220 const unsigned int w = window.w / 4; |
221 const unsigned int h = 50; | 221 const unsigned int h = MH; |
222 const int x = (window.w / 2) - (w / 2); | 222 const int x = (window.w / 2) - (w / 2); |
223 const int y = (window.h - h - 10); | 223 const int y = (window.h - h - 10); |
224 | 224 |
225 struct message msg = { | 225 struct message msg = { |
226 .x = x, | 226 .x = x, |
236 | 236 |
237 run(&msg); | 237 run(&msg); |
238 } | 238 } |
239 | 239 |
240 static void | 240 static void |
241 toosmallh(void) | |
242 { | |
243 struct message msg = { | |
244 .x = MX, | |
245 .y = MY, | |
246 .w = MW, | |
247 .h = 50, | |
248 .text = { | |
249 "This one is too small in height and will emit a warning.", | |
250 }, | |
251 }; | |
252 | |
253 run(&msg); | |
254 } | |
255 | |
256 static void | |
257 toosmallw(void) | |
258 { | |
259 struct message msg = { | |
260 .x = MX, | |
261 .y = MY, | |
262 .w = 160, | |
263 .h = MH, | |
264 .text = { | |
265 "This one is too small in width." | |
266 }, | |
267 }; | |
268 | |
269 run(&msg); | |
270 } | |
271 | |
272 static void | |
241 custom(void) | 273 custom(void) |
242 { | 274 { |
243 struct theme theme; | 275 struct theme theme; |
244 struct message msg = { | 276 struct message msg = { |
245 .x = MX, | 277 .x = MX, |
255 | 287 |
256 /* Borrow default theme and change its frame drawing. */ | 288 /* Borrow default theme and change its frame drawing. */ |
257 memcpy(&theme, theme_default(), sizeof (theme)); | 289 memcpy(&theme, theme_default(), sizeof (theme)); |
258 theme.draw_frame = my_draw_frame; | 290 theme.draw_frame = my_draw_frame; |
259 theme.colors[THEME_COLOR_NORMAL] = 0x0000ffff; | 291 theme.colors[THEME_COLOR_NORMAL] = 0x0000ffff; |
292 | |
293 run(&msg); | |
294 } | |
295 | |
296 static void | |
297 large(void) | |
298 { | |
299 struct message msg = { | |
300 .x = MX, | |
301 .y = MY, | |
302 .w = 500, | |
303 .h = 500, | |
304 .text = { | |
305 "And this one is terribly large.", | |
306 "But lines are still padded at top." | |
307 }, | |
308 }; | |
260 | 309 |
261 run(&msg); | 310 run(&msg); |
262 } | 311 } |
263 | 312 |
264 int | 313 int |
273 fadeout(); | 322 fadeout(); |
274 fade(); | 323 fade(); |
275 automatic(); | 324 automatic(); |
276 question(); | 325 question(); |
277 smallbottom(); | 326 smallbottom(); |
327 toosmallh(); | |
328 toosmallw(); | |
278 custom(); | 329 custom(); |
330 large(); | |
279 quit(); | 331 quit(); |
280 } | 332 } |