From 81239d4bd22f080179a544a49852dbc2f244f6cb Mon Sep 17 00:00:00 2001 From: Elias Aebi Date: Wed, 18 Sep 2024 12:49:07 +0200 Subject: [PATCH] improve the events demo --- demos/events.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/demos/events.c b/demos/events.c index 922357e..b48e4ad 100644 --- a/demos/events.c +++ b/demos/events.c @@ -121,7 +121,7 @@ static void control_change(unsigned char controller, unsigned char value, void * static void create_window(void *user_data) { struct demo *demo = user_data; - struct gral_window_interface window_interface = { + struct gral_window_interface interface = { &close, &draw, &resize, @@ -139,18 +139,15 @@ static void create_window(void *user_data) { &focus_enter, &focus_leave }; - demo->window = gral_window_create(demo->application, 600, 400, "gral events demo", &window_interface, demo); - demo->timer = gral_timer_create(1000, &timer, demo); - struct gral_midi_interface midi_interface = { - ¬e_on, - ¬e_off, - &control_change - }; - demo->midi = gral_midi_create(demo->application, "gral events demo", &midi_interface, demo); + demo->window = gral_window_create(demo->application, 600, 400, "gral events demo", &interface, demo); } static void start(void *user_data) { printf("start\n"); + struct demo *demo = user_data; + demo->timer = gral_timer_create(1000, &timer, demo); + struct gral_midi_interface midi_interface = {¬e_on, ¬e_off, &control_change}; + demo->midi = gral_midi_create(demo->application, "gral events demo", &midi_interface, demo); } static void open_empty(void *user_data) { @@ -165,6 +162,8 @@ static void open_file(char const *path, void *user_data) { static void quit(void *user_data) { printf("quit\n"); + struct demo *demo = user_data; + gral_midi_delete(demo->midi); } int main(int argc, char **argv) { @@ -172,7 +171,6 @@ int main(int argc, char **argv) { struct gral_application_interface interface = {&start, &open_empty, &open_file, &quit}; demo.application = gral_application_create("com.github.eyelash.libgral.demos.events", &interface, &demo); int result = gral_application_run(demo.application, argc, argv); - gral_midi_delete(demo.midi); gral_window_delete(demo.window); gral_application_delete(demo.application); return result;