Implement unigi_event_get()

This commit is contained in:
Fierelier 2024-06-30 22:07:10 +02:00
parent fbe7b14110
commit a5c52ebb76
2 changed files with 26 additions and 1 deletions

25
src/events.h Normal file
View File

@ -0,0 +1,25 @@
void unigi_event_get(unigi_type_event * event) {
SDL_Event platform_event;
if (SDL_PollEvent(&platform_event)) {
if (
platform_event.type == SDL_KEYDOWN ||
platform_event.type == SDL_KEYUP
) {
event -> type = unigi_enum_event_input_keyboard;
event -> data.input_keyboard.device = 0;
event -> data.input_keyboard.button = platform_event.key.keysym.scancode;
if (platform_event.type == SDL_KEYDOWN) {
event -> data.input_keyboard.down = 1;
} else {
event -> data.input_keyboard.down = 0;
}
return;
}
event -> type = unigi_enum_event_unknown;
return;
} else {
event -> type = unigi_enum_event_none;
return;
}
}

View File

@ -1,7 +1,7 @@
#include <stdint.h> #include <stdint.h>
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include "graphics.h" #include "graphics.h"
#include "input.h" #include "events.h"
unigi_type_error unigi_init() { unigi_type_error unigi_init() {
return 0; return 0;