-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reintroduced SDL changes for new kbd API. (#100)
* Update SDL to use new KBD API.
- Loading branch information
1 parent
b0d0423
commit 5c5613b
Showing
1 changed file
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
[email protected] | ||
Modified by Lawrence Sebald <[email protected]> | ||
Modified by Falco Girgis <[email protected]> | ||
*/ | ||
|
||
#include "SDL.h" | ||
|
@@ -33,9 +34,7 @@ | |
#include "SDL_dcvideo.h" | ||
#include "SDL_dcevents_c.h" | ||
|
||
#include <dc/maple.h> | ||
#include <dc/maple/mouse.h> | ||
#include <dc/maple/keyboard.h> | ||
#include <kos.h> | ||
|
||
const static unsigned short sdl_key[]= { | ||
/*0*/ 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', | ||
|
@@ -101,7 +100,11 @@ static void mouse_update(void) { | |
} | ||
|
||
static void keyboard_update(void) { | ||
#if KOS_VERSION_BELOW(2, 2, 0) | ||
static kbd_state_t old_state; | ||
#else | ||
static kbd_mods_t old_mods; | ||
#endif | ||
kbd_state_t *state; | ||
maple_device_t *dev; | ||
int shiftkeys; | ||
|
@@ -116,6 +119,7 @@ static void keyboard_update(void) { | |
if(!state) | ||
return; | ||
|
||
#if KOS_VERSION_BELOW(2, 2, 0) | ||
shiftkeys = state->shift_keys ^ old_state.shift_keys; | ||
for(i = 0; i < sizeof(sdl_shift); ++i) { | ||
if((shiftkeys >> i) & 1) { | ||
|
@@ -137,6 +141,28 @@ static void keyboard_update(void) { | |
} | ||
|
||
old_state = *state; | ||
|
||
#else /* KOS 2.2.0+ */ | ||
shiftkeys = state->modifiers.raw ^ old_mods.raw; | ||
for(i = 0; i < sizeof(sdl_shift)/sizeof(sdl_shift[0]); ++i) { | ||
if((shiftkeys >> i) & 1) { | ||
keysym.sym = sdl_shift[i]; | ||
SDL_PrivateKeyboard(((state->modifiers.raw >> i) & 1) ? | ||
SDL_PRESSED : SDL_RELEASED, &keysym); | ||
} | ||
} | ||
|
||
for(i = 0; i < sizeof(sdl_key)/sizeof(sdl_key[0]); ++i) { | ||
int key = sdl_key[i]; | ||
keysym.sym = key; | ||
|
||
if(state->key_states[i].value == KEY_STATE_CHANGED_DOWN) { | ||
SDL_PrivateKeyboard(SDL_PRESSED, &keysym); | ||
} else if(state->key_states[i].value == KEY_STATE_CHANGED_UP) { | ||
SDL_PrivateKeyboard(SDL_RELEASED, &keysym); | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
void DC_PumpEvents(_THIS) { | ||
|
@@ -145,4 +171,4 @@ void DC_PumpEvents(_THIS) { | |
} | ||
|
||
void DC_InitOSKeymap(_THIS) { | ||
} | ||
} |