mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-07 07:38:04 -04:00
Let the platform code deliver the key mappings
This commit is contained in:
parent
17def48f1f
commit
c19e28f626
6 changed files with 69 additions and 103 deletions
62
in_sdl.c
62
in_sdl.c
|
@ -20,6 +20,7 @@ typedef unsigned long keybits_t;
|
|||
#define KEYBITS_WORD_BITS (sizeof(keybits_t) * 8)
|
||||
|
||||
struct in_sdl_state {
|
||||
const in_drv_t *drv;
|
||||
SDL_Joystick *joy;
|
||||
int joy_id;
|
||||
int axis_keydown[2];
|
||||
|
@ -162,7 +163,7 @@ static const char * const in_sdl_keys[SDLK_LAST] = {
|
|||
[SDLK_COMPOSE] = "compose",
|
||||
};
|
||||
|
||||
static void in_sdl_probe(void)
|
||||
static void in_sdl_probe(const in_drv_t *drv)
|
||||
{
|
||||
struct in_sdl_state *state;
|
||||
SDL_Joystick *joy;
|
||||
|
@ -175,6 +176,7 @@ static void in_sdl_probe(void)
|
|||
return;
|
||||
}
|
||||
|
||||
state->drv = drv;
|
||||
in_register(IN_SDL_PREFIX "keys", -1, state, SDLK_LAST,
|
||||
in_sdl_keys, 0);
|
||||
|
||||
|
@ -194,6 +196,7 @@ static void in_sdl_probe(void)
|
|||
}
|
||||
state->joy = joy;
|
||||
state->joy_id = i;
|
||||
state->drv = drv;
|
||||
|
||||
snprintf(name, sizeof(name), IN_SDL_PREFIX "%s", SDL_JoystickName(i));
|
||||
in_register(name, -1, state, SDLK_LAST, in_sdl_keys, 0);
|
||||
|
@ -406,52 +409,22 @@ static int in_sdl_update_keycode(void *drv_data, int *is_down)
|
|||
return ret_kc;
|
||||
}
|
||||
|
||||
struct menu_keymap {
|
||||
short key;
|
||||
short pbtn;
|
||||
};
|
||||
|
||||
static const struct menu_keymap key_pbtn_map[] =
|
||||
{
|
||||
{ SDLK_UP, PBTN_UP },
|
||||
{ SDLK_DOWN, PBTN_DOWN },
|
||||
{ SDLK_LEFT, PBTN_LEFT },
|
||||
{ SDLK_RIGHT, PBTN_RIGHT },
|
||||
/* XXX: maybe better set this from it's plat code somehow */
|
||||
{ SDLK_RETURN, PBTN_MOK },
|
||||
{ SDLK_ESCAPE, PBTN_MBACK },
|
||||
{ SDLK_SEMICOLON, PBTN_MA2 },
|
||||
{ SDLK_QUOTE, PBTN_MA3 },
|
||||
{ SDLK_BACKSLASH, PBTN_MENU },
|
||||
{ SDLK_LEFTBRACKET, PBTN_L },
|
||||
{ SDLK_RIGHTBRACKET, PBTN_R },
|
||||
};
|
||||
#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
|
||||
|
||||
static const struct menu_keymap joybtn_pbtn_map[] =
|
||||
{
|
||||
{ SDLK_UP, PBTN_UP },
|
||||
{ SDLK_DOWN, PBTN_DOWN },
|
||||
{ SDLK_LEFT, PBTN_LEFT },
|
||||
{ SDLK_RIGHT, PBTN_RIGHT },
|
||||
/* joystick */
|
||||
{ SDLK_WORLD_0, PBTN_MOK },
|
||||
{ SDLK_WORLD_1, PBTN_MBACK },
|
||||
{ SDLK_WORLD_2, PBTN_MA2 },
|
||||
{ SDLK_WORLD_3, PBTN_MA3 },
|
||||
};
|
||||
#define JOYBTN_PBTN_MAP_SIZE (sizeof(joybtn_pbtn_map) / sizeof(joybtn_pbtn_map[0]))
|
||||
|
||||
static int in_sdl_menu_translate(void *drv_data, int keycode, char *charcode)
|
||||
{
|
||||
struct in_sdl_state *state = drv_data;
|
||||
const struct in_pdata *pdata = state->drv->pdata;
|
||||
const struct menu_keymap *map;
|
||||
int map_len;
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
map = state->joy ? joybtn_pbtn_map : key_pbtn_map;
|
||||
map_len = state->joy ? JOYBTN_PBTN_MAP_SIZE : KEY_PBTN_MAP_SIZE;
|
||||
if (state->joy) {
|
||||
map = pdata->joy_map;
|
||||
map_len = pdata->jmap_size;
|
||||
} else {
|
||||
map = pdata->key_map;
|
||||
map_len = pdata->kmap_size;
|
||||
}
|
||||
|
||||
if (keycode < 0)
|
||||
{
|
||||
|
@ -491,9 +464,14 @@ static const in_drv_t in_sdl_drv = {
|
|||
.menu_translate = in_sdl_menu_translate,
|
||||
};
|
||||
|
||||
void in_sdl_init(const struct in_default_bind *defbinds,
|
||||
void (*handler)(void *event))
|
||||
int in_sdl_init(const struct in_pdata *pdata, void (*handler)(void *event))
|
||||
{
|
||||
in_register_driver(&in_sdl_drv, defbinds);
|
||||
if (!pdata) {
|
||||
fprintf(stderr, "in_sdl: Missing input platform data\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
in_register_driver(&in_sdl_drv, pdata->defbinds, pdata);
|
||||
ext_event_handler = handler;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue