unigi.platform.sdl1/events.c

41 lines
1.3 KiB
C
Raw Normal View History

2024-06-30 20:07:10 +00:00
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;
2024-08-08 05:21:46 +00:00
event -> data.input_keyboard.down = (platform_event.type == SDL_KEYDOWN);
return;
}
if (platform_event.type == SDL_MOUSEMOTION) {
event -> type = unigi_enum_event_input_mouse_move;
event -> data.input_mouse_move.rel_x = platform_event.motion.xrel;
event -> data.input_mouse_move.rel_y = platform_event.motion.yrel;
event -> data.input_mouse_move.abs_x = platform_event.motion.x;
event -> data.input_mouse_move.abs_y = platform_event.motion.y;
return;
}
if (
platform_event.type == SDL_MOUSEBUTTONDOWN ||
platform_event.type == SDL_MOUSEBUTTONUP
) {
event -> type = unigi_enum_event_input_mouse_button;
event -> data.input_mouse_button.button = platform_event.button.button;
event -> data.input_mouse_button.down = (platform_event.type == SDL_MOUSEBUTTONDOWN);
2024-06-30 20:07:10 +00:00
return;
}
event -> type = unigi_enum_event_unknown;
return;
} else {
event -> type = unigi_enum_event_none;
return;
}
}