Mercurial > molko
comparison examples/example-cursor/example-cursor.c @ 486:d6757c30658e
core: rework errors
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 28 Feb 2023 13:04:13 +0100 |
parents | 3ff1fe64d0cd |
children | fce3b3c4b496 |
comparison
equal
deleted
inserted
replaced
485:3ff1fe64d0cd | 486:d6757c30658e |
---|---|
17 */ | 17 */ |
18 | 18 |
19 #include <stdio.h> | 19 #include <stdio.h> |
20 | 20 |
21 #include <mlk/core/core.h> | 21 #include <mlk/core/core.h> |
22 #include <mlk/core/err.h> | |
22 #include <mlk/core/event.h> | 23 #include <mlk/core/event.h> |
23 #include <mlk/core/game.h> | 24 #include <mlk/core/game.h> |
24 #include <mlk/core/key.h> | 25 #include <mlk/core/key.h> |
25 #include <mlk/core/painter.h> | 26 #include <mlk/core/painter.h> |
26 #include <mlk/core/panic.h> | 27 #include <mlk/core/panic.h> |
30 #include <mlk/core/window.h> | 31 #include <mlk/core/window.h> |
31 | 32 |
32 #include <mlk/ui/label.h> | 33 #include <mlk/ui/label.h> |
33 #include <mlk/ui/ui.h> | 34 #include <mlk/ui/ui.h> |
34 | 35 |
35 #define W 1280 | 36 #include <mlk/example/example.h> |
36 #define H 720 | |
37 | 37 |
38 static struct mlk_state *states[1]; | 38 static struct mlk_state *states[1]; |
39 static char help_text[128]; | 39 static char help_text[128]; |
40 static enum mlk_window_cursor cursor = MLK_WINDOW_CURSOR_ARROW; | 40 static enum mlk_window_cursor cursor = MLK_WINDOW_CURSOR_ARROW; |
41 | 41 |
47 }; | 47 }; |
48 | 48 |
49 static void | 49 static void |
50 init(void) | 50 init(void) |
51 { | 51 { |
52 if (mlk_core_init("fr.malikania", "example-cursor") < 0 || ui_init() < 0) | 52 int err; |
53 mlk_panic(); | 53 |
54 if (mlk_window_open("Example - Cursor", W, H) < 0) | 54 if ((err = mlk_example_init("example-cursor")) < 0) |
55 mlk_panic(); | 55 mlk_panicf("mlk_example_init: %s", mlk_err_string(err)); |
56 } | 56 } |
57 | 57 |
58 static void | 58 static void |
59 change(enum mlk_window_cursor cursor) | 59 change(enum mlk_window_cursor cursor) |
60 { | 60 { |
61 static const char *names[] = { | 61 static const char *names[] = { |
62 [WINDOW_CURSOR_ARROW] = "WINDOW_CURSOR_ARROW", | 62 [MLK_WINDOW_CURSOR_ARROW] = "MLK_WINDOW_CURSOR_ARROW", |
63 [WINDOW_CURSOR_EDIT] = "WINDOW_CURSOR_EDIT", | 63 [MLK_WINDOW_CURSOR_EDIT] = "MLK_WINDOW_CURSOR_EDIT", |
64 [WINDOW_CURSOR_WAIT] = "WINDOW_CURSOR_WAIT", | 64 [MLK_WINDOW_CURSOR_WAIT] = "MLK_WINDOW_CURSOR_WAIT", |
65 [WINDOW_CURSOR_CROSSHAIR] = "WINDOW_CURSOR_CROSSHAIR", | 65 [MLK_WINDOW_CURSOR_CROSSHAIR] = "MLK_WINDOW_CURSOR_CROSSHAIR", |
66 [WINDOW_CURSOR_SIZE] = "WINDOW_CURSOR_SIZE", | 66 [MLK_WINDOW_CURSOR_SIZE] = "MLK_WINDOW_CURSOR_SIZE", |
67 [WINDOW_CURSOR_NO] = "WINDOW_CURSOR_NO", | 67 [MLK_WINDOW_CURSOR_NO] = "MLK_WINDOW_CURSOR_NO", |
68 [WINDOW_CURSOR_HAND] = "WINDOW_CURSOR_HAND" | 68 [MLK_WINDOW_CURSOR_HAND] = "MLK_WINDOW_CURSOR_HAND" |
69 }; | 69 }; |
70 | 70 |
71 snprintf(help_text, sizeof (help_text), "Keys: <Left>/<Right> to change cursor. Current: %s", names[cursor]); | 71 snprintf(help_text, sizeof (help_text), "Keys: <Left>/<Right> to change cursor. Current: %s", names[cursor]); |
72 mlk_window_set_cursor(cursor); | 72 mlk_window_set_cursor(cursor); |
73 } | 73 } |
89 change(++cursor); | 89 change(++cursor); |
90 break; | 90 break; |
91 default: | 91 default: |
92 break; | 92 break; |
93 } | 93 } |
94 | |
95 | 94 |
96 break; | 95 break; |
97 case MLK_EVENT_QUIT: | 96 case MLK_EVENT_QUIT: |
98 mlk_game_quit(); | 97 mlk_game_quit(); |
99 break; | 98 break; |