Replaced SDL_HINT_APPLE_TV_REMOTE_SWIPES_AS_ARROW_KEYS with SDL_HINT_TV_REMOTE_AS_JOYSTICK which controls whether remotes on iOS and Android are interpreted as joysticks (the default) or as return/escape/arrow keys.
This commit is contained in:
parent
35b16e2fb7
commit
125a9c8592
4 changed files with 89 additions and 52 deletions
|
@ -80,8 +80,7 @@ keycode_to_SDL(int keycode)
|
|||
{
|
||||
/* FIXME: If this function gets too unwieldy in the future, replace with a lookup table */
|
||||
int button = 0;
|
||||
switch(keycode)
|
||||
{
|
||||
switch (keycode) {
|
||||
/* Some gamepad buttons (API 9) */
|
||||
case AKEYCODE_BUTTON_A:
|
||||
button = SDL_CONTROLLER_BUTTON_A;
|
||||
|
@ -179,7 +178,30 @@ keycode_to_SDL(int keycode)
|
|||
*/
|
||||
SDL_assert(button < ANDROID_MAX_NBUTTONS);
|
||||
return button;
|
||||
|
||||
}
|
||||
|
||||
static SDL_Scancode
|
||||
button_to_scancode(int button)
|
||||
{
|
||||
switch (button) {
|
||||
case SDL_CONTROLLER_BUTTON_A:
|
||||
return SDL_SCANCODE_RETURN;
|
||||
case SDL_CONTROLLER_BUTTON_B:
|
||||
return SDL_SCANCODE_ESCAPE;
|
||||
case SDL_CONTROLLER_BUTTON_BACK:
|
||||
return SDL_SCANCODE_ESCAPE;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_UP:
|
||||
return SDL_SCANCODE_UP;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
|
||||
return SDL_SCANCODE_DOWN;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
|
||||
return SDL_SCANCODE_LEFT;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
|
||||
return SDL_SCANCODE_RIGHT;
|
||||
}
|
||||
|
||||
/* Unsupported button */
|
||||
return SDL_SCANCODE_UNKNOWN;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -191,6 +213,8 @@ Android_OnPadDown(int device_id, int keycode)
|
|||
item = JoystickByDeviceId(device_id);
|
||||
if (item && item->joystick) {
|
||||
SDL_PrivateJoystickButton(item->joystick, button , SDL_PRESSED);
|
||||
} else {
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, button_to_scancode(button));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -207,6 +231,8 @@ Android_OnPadUp(int device_id, int keycode)
|
|||
item = JoystickByDeviceId(device_id);
|
||||
if (item && item->joystick) {
|
||||
SDL_PrivateJoystickButton(item->joystick, button, SDL_RELEASED);
|
||||
} else {
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, button_to_scancode(button));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -252,8 +278,15 @@ Android_AddJoystick(int device_id, const char *name, const char *desc, SDL_bool
|
|||
{
|
||||
SDL_JoystickGUID guid;
|
||||
SDL_joylist_item *item;
|
||||
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
|
||||
/* Ignore devices that aren't actually controllers (e.g. remotes), they'll be handled as keyboard input */
|
||||
if (naxes < 2 && nhats < 1) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(JoystickByDeviceId(device_id) != NULL || name == NULL) {
|
||||
if (JoystickByDeviceId(device_id) != NULL || name == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue