comparison examples/example-notify/example-notify.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
31 31
32 #include <mlk/ui/notify.h> 32 #include <mlk/ui/notify.h>
33 #include <mlk/ui/label.h> 33 #include <mlk/ui/label.h>
34 #include <mlk/ui/ui.h> 34 #include <mlk/ui/ui.h>
35 35
36 /* Sword by Icongeek26 (https://www.flaticon.com). */ 36 #include <mlk/example/example.h>
37 #include <assets/images/sword.h> 37 #include <mlk/example/registry.h>
38
39 #define W 1280
40 #define H 720
41 38
42 static struct label help = { 39 static struct label help = {
43 .text = "Keys: <Space> to generate a notification.", 40 .text = "Keys: <Space> to generate a notification.",
44 .x = 10, 41 .x = 10,
45 .y = 10, 42 .y = 10,
46 .flags = LABEL_FLAGS_SHADOW 43 .flags = LABEL_FLAGS_SHADOW
47 }; 44 };
48 static struct mlk_texture icon; 45 static struct mlk_texture *icon;
49 static struct mlk_state *states[1]; 46 static struct mlk_state *states[1];
50 47
51 static void 48 static void
52 init(void) 49 init(void)
53 { 50 {
54 if (mlk_core_init("fr.malikania", "example-notify") < 0 || ui_init() < 0) 51 int err;
55 mlk_panic(); 52
56 if (mlk_window_open("Example - Notify", W, H) < 0) 53 if ((err = mlk_example_init("example-notify")) < 0)
57 mlk_panic(); 54 mlk_panicf("mlk_example_init: %s", mlk_err_string(err));
58 if (mlk_image_openmem(&icon, assets_images_sword, sizeof (assets_images_sword)) < 0) 55
59 mlk_panic(); 56 icon = &registry_textures[REGISTRY_TEXTURE_SWORD];
60 } 57 }
61 58
62 static void 59 static void
63 handle(struct mlk_state *st, const union mlk_event *ev) 60 handle(struct mlk_state *st, const union mlk_event *ev)
64 { 61 {
68 case MLK_EVENT_QUIT: 65 case MLK_EVENT_QUIT:
69 mlk_game_quit(); 66 mlk_game_quit();
70 break; 67 break;
71 case MLK_EVENT_KEYDOWN: 68 case MLK_EVENT_KEYDOWN:
72 if (ev->key.key == MLK_KEY_SPACE) 69 if (ev->key.key == MLK_KEY_SPACE)
73 notify(&icon, "Quest", "Quest finished."); 70 notify(icon, "Quest", "Quest finished.");
74 break; 71 break;
75 default: 72 default:
76 break; 73 break;
77 } 74 }
78 } 75 }