|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #include "IZ_keyboard.h"
-
- void IZ_HandleKeyboardEvents(SDL_Event e, IZ_KeyboardState* state, IZ_Action* action) {
- for (uint8_t i = 0; i < CONTROLS; i += 1) {
- if (e.key.keysym.sym == state->config.control_mapping[i]) {
- const uint16_t bitflag = (0x1 << i);
- if (e.type == SDL_KEYDOWN) {
- *action |= bitflag;
- } else if (e.type == SDL_KEYUP) {
- *action &= ~bitflag;
- }
- }
- }
- }
-
- void IZ_SaveKeyboardConfig(IZ_KeyboardConfig* config, uint8_t p) {
- char config_path[128];
- IZ_GetConfigPath(config_path, 128);
-
- char keyboard_section_name[] = "Keyboard.0.ControlMapping";
- keyboard_section_name[9] = (char) (48 + p);
- for (uint8_t i = 0; i < CONTROLS; i += 1) {
- ini_puts(keyboard_section_name, ACTION_NAMES[i], SDL_GetKeyName(config->control_mapping[i]), config_path);
- }
- }
-
- void IZ_LoadKeyboardConfig(IZ_KeyboardConfig* config, uint8_t p) {
- char config_path[128];
- IZ_GetConfigPath(config_path, 128);
-
- char buffer[128];
- char keyboard_section_name[] = "Keyboard.0.ControlMapping";
- keyboard_section_name[9] = (char) (48 + p);
- for (uint8_t i = 0; i < CONTROLS; i += 1) {
- ini_gets(
- keyboard_section_name,
- ACTION_NAMES[i],
- SDL_GetKeyName(IZ_DEFAULT_KEYBOARD_CONTROLS[p][i]),
- buffer,
- 128,
- config_path
- );
-
- config->control_mapping[i] = SDL_GetKeyFromName(buffer);
- }
- }
|