diff options
author | kdx <kikoodx@paranoici.org> | 2023-03-27 08:39:52 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-03-27 08:39:52 +0200 |
commit | a65ccb043979b550c3ed516683418fc0e18063f8 (patch) | |
tree | bcb9d934633d345beaea17d47257d80eb30552f2 | |
parent | 8b92076145893cfdaf3e648e0324b163c1a6d28e (diff) | |
download | tzr-a65ccb043979b550c3ed516683418fc0e18063f8.tar.gz |
register mouse state events
-rw-r--r-- | headers/TZR_globals.h | 1 | ||||
-rw-r--r-- | sources/TZR_CycleEvents.c | 36 | ||||
-rw-r--r-- | sources/TZR_PollEvent.c | 2 | ||||
-rw-r--r-- | sources/globals.c | 9 |
4 files changed, 29 insertions, 19 deletions
diff --git a/headers/TZR_globals.h b/headers/TZR_globals.h index 616ebef..4f8c00c 100644 --- a/headers/TZR_globals.h +++ b/headers/TZR_globals.h @@ -19,3 +19,4 @@ extern int ___tzr_mouse_x; extern int ___tzr_mouse_y; extern const char *___tzr_command[___TZR_RES_COUNT]; extern TZR_KeyState ___tzr_keystates[SDL_NUM_SCANCODES]; +extern TZR_KeyState ___tzr_mousestates[256]; diff --git a/sources/TZR_CycleEvents.c b/sources/TZR_CycleEvents.c index 44e7ca5..b30ffe5 100644 --- a/sources/TZR_CycleEvents.c +++ b/sources/TZR_CycleEvents.c @@ -4,24 +4,30 @@ #include <SDL2/SDL_scancode.h> void +next_state(TZR_KeyState *keystate) +{ + switch (*keystate) { + case TZR_KEYSTATE_RELEASE: + case TZR_KEYSTATE_UP: + *keystate = TZR_KEYSTATE_UP; + break; + case TZR_KEYSTATE_PRESS: + case TZR_KEYSTATE_DOWN: + *keystate = TZR_KEYSTATE_DOWN; + break; + default: + break; + } +} + +void TZR_CycleEvents(void) { TZR_ResourcesWatch(); - for (int i = 0; i < SDL_NUM_SCANCODES; i++) { - TZR_KeyState *const keystate = &___tzr_keystates[i]; - switch (*keystate) { - case TZR_KEYSTATE_RELEASE: - case TZR_KEYSTATE_UP: - *keystate = TZR_KEYSTATE_UP; - break; - case TZR_KEYSTATE_PRESS: - case TZR_KEYSTATE_DOWN: - *keystate = TZR_KEYSTATE_DOWN; - break; - default: - break; - } - } + for (int i = 0; i < SDL_NUM_SCANCODES; i++) + next_state(&___tzr_keystates[i]); + for (int i = 0; i < 256; i++) + next_state(&___tzr_mousestates[i]); TZR_Event e; while (TZR_PollEvent(&e)) ; diff --git a/sources/TZR_PollEvent.c b/sources/TZR_PollEvent.c index 2b31fa3..7b3b94e 100644 --- a/sources/TZR_PollEvent.c +++ b/sources/TZR_PollEvent.c @@ -30,10 +30,12 @@ TZR_PollEvent(TZR_Event *e) case SDL_MOUSEBUTTONDOWN: ___tzr_mouse_x = se.button.x; ___tzr_mouse_y = se.button.y; + ___tzr_mousestates[se.button.button] = TZR_KEYSTATE_PRESS; break; case SDL_MOUSEBUTTONUP: ___tzr_mouse_x = se.button.x; ___tzr_mouse_y = se.button.y; + ___tzr_mousestates[se.button.button] = TZR_KEYSTATE_RELEASE; break; case SDL_MOUSEMOTION: ___tzr_mouse_x = se.motion.x; diff --git a/sources/globals.c b/sources/globals.c index 2986131..badcc1e 100644 --- a/sources/globals.c +++ b/sources/globals.c @@ -3,8 +3,8 @@ #include <SDL2/SDL_render.h> #include <SDL2/SDL_scancode.h> -TZR_Config ___tzr_config = {0}; -TZR_Color ___tzr_color = {0, 0.0f, 0.0f, 0.0f, 1.0f}; +TZR_Config ___tzr_config = {}; +TZR_Color ___tzr_color = {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; TZR_Resource *___tzr_resources = NULL; size_t ___tzr_resources_capacity = 0; size_t ___tzr_resources_size = 0; @@ -17,5 +17,6 @@ unsigned long ___tzr_min_dt = 0; int ___tzr_should_quit = 0; int ___tzr_mouse_x = 0; int ___tzr_mouse_y = 0; -const char *___tzr_command[___TZR_RES_COUNT] = {0}; -TZR_KeyState ___tzr_keystates[SDL_NUM_SCANCODES] = {0}; +const char *___tzr_command[___TZR_RES_COUNT] = {}; +TZR_KeyState ___tzr_keystates[SDL_NUM_SCANCODES] = {}; +TZR_KeyState ___tzr_mousestates[256] = {}; //doc says than mouse button is u8 |