SDL: redefine gamepad Start/Select and DPAD keycodes in AndroidiAppSettings.cfg
This commit is contained in:
@@ -358,7 +358,7 @@ echo "# 9 = Nintendo64 from RetroArch" >> AndroidAppSettings.cfg
|
||||
echo TouchscreenKeysTheme=$TouchscreenKeysTheme >> AndroidAppSettings.cfg
|
||||
echo >> AndroidAppSettings.cfg
|
||||
echo "# Redefine gamepad keys to SDL keysyms, button order is:" >> AndroidAppSettings.cfg
|
||||
echo "# A B X Y L1 R1 L2 R2 LThumb RThumb" >> AndroidAppSettings.cfg
|
||||
echo "# A B X Y L1 R1 L2 R2 LThumb RThumb Start Select Up Down Left Right" >> AndroidAppSettings.cfg
|
||||
echo RedefinedKeysGamepad=\"$RedefinedKeysGamepad\" >> AndroidAppSettings.cfg
|
||||
echo >> AndroidAppSettings.cfg
|
||||
echo "# How long to show startup menu button, in msec, 0 to disable startup menu" >> AndroidAppSettings.cfg
|
||||
|
||||
@@ -361,7 +361,6 @@ abstract class DifferentTouchInput
|
||||
}
|
||||
private static class IcsTouchInput extends GingerbreadTouchInput
|
||||
{
|
||||
float hatX = 0.0f, hatY = 0.0f;
|
||||
private static class Holder
|
||||
{
|
||||
private static final IcsTouchInput sInstance = new IcsTouchInput();
|
||||
@@ -392,33 +391,11 @@ abstract class DifferentTouchInput
|
||||
if( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK )
|
||||
{
|
||||
// event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, on Nvidia Shield and some other joysticks
|
||||
if( event.getAxisValue(MotionEvent.AXIS_HAT_X) != hatX )
|
||||
{
|
||||
hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
|
||||
if( hatX == 0.0f )
|
||||
{
|
||||
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_LEFT, 0, 0);
|
||||
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_RIGHT, 0, 0);
|
||||
}
|
||||
else
|
||||
DemoGLSurfaceView.nativeKey(hatX < 0.0f ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT, 1, 0);
|
||||
}
|
||||
if( event.getAxisValue(MotionEvent.AXIS_HAT_Y) != hatY )
|
||||
{
|
||||
hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
|
||||
if( hatY == 0.0f )
|
||||
{
|
||||
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_UP, 0, 0);
|
||||
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_DOWN, 0, 0);
|
||||
}
|
||||
else
|
||||
DemoGLSurfaceView.nativeKey(hatY < 0.0f ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DPAD_DOWN, 1, 0);
|
||||
}
|
||||
DemoGLSurfaceView.nativeGamepadAnalogJoystickInput(
|
||||
event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y),
|
||||
event.getAxisValue(MotionEvent.AXIS_Z), event.getAxisValue(MotionEvent.AXIS_RZ),
|
||||
event.getAxisValue(MotionEvent.AXIS_LTRIGGER), event.getAxisValue(MotionEvent.AXIS_RTRIGGER),
|
||||
(hatX == 0.0f && hatY == 0.0f) ? 0 : 1 );
|
||||
event.getAxisValue(MotionEvent.AXIS_LTRIGGER), event.getAxisValue(MotionEvent.AXIS_RTRIGGER),
|
||||
event.getAxisValue(MotionEvent.AXIS_HAT_X), event.getAxisValue(MotionEvent.AXIS_HAT_Y) );
|
||||
return;
|
||||
}
|
||||
// Process mousewheel
|
||||
@@ -1098,7 +1075,7 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
|
||||
public static native void nativeHardwareMouseDetected( int detected );
|
||||
public static native void nativeMouseButtonsPressed( int buttonId, int pressedState );
|
||||
public static native void nativeMouseWheel( int scrollX, int scrollY );
|
||||
public static native void nativeGamepadAnalogJoystickInput( float stick1x, float stick1y, float stick2x, float stick2y, float ltrigger, float rtrigger, int usingHat );
|
||||
public static native void nativeGamepadAnalogJoystickInput( float stick1x, float stick1y, float stick2x, float stick2y, float ltrigger, float rtrigger, float dpadx, float dpady );
|
||||
public static native void nativeScreenVisibleRect( int x, int y, int w, int h );
|
||||
public static native void nativeScreenKeyboardShown( int shown );
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ RedefinedKeysScreenKbNames="Jump Rope Fire Dig Change"
|
||||
TouchscreenKeysTheme=3
|
||||
|
||||
# Redefine gamepad keys to SDL keysyms, button order is:
|
||||
# A B X Y L1 R1 L2 R2 LThumb RThumb
|
||||
# A B X Y L1 R1 L2 R2 LThumb RThumb Start Select Up Down Left Right
|
||||
RedefinedKeysGamepad="RETURN RSHIFT RCTRL RALT RSHIFT RALT SLASH RCTRL RETURN RETURN"
|
||||
|
||||
# How long to show startup menu button, in msec, 0 to disable startup menu
|
||||
|
||||
@@ -1416,7 +1416,7 @@ JAVA_EXPORT_NAME(Settings_nativeSetAccelerometerSettings) ( JNIEnv* env, jobjec
|
||||
JNIEXPORT void JNICALL
|
||||
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeGamepadAnalogJoystickInput) (JNIEnv* env, jobject thiz,
|
||||
jfloat stick1x, jfloat stick1y, jfloat stick2x, jfloat stick2y, jfloat ltrigger, jfloat rtrigger,
|
||||
jint usingHat)
|
||||
jfloat dpadx, jfloat dpady)
|
||||
{
|
||||
if( SDL_ANDROID_CurrentJoysticks[JOY_GAMEPAD1] )
|
||||
{
|
||||
@@ -1429,51 +1429,12 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeGamepadAnalogJoystickInput) (JNIEnv* en
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !usingHat )
|
||||
if( fabsf(dpadx) < 0.01f && fabsf(dpady) < 0.01f )
|
||||
{
|
||||
// Translate to up/down/left/right
|
||||
if( stick1x < -0.5f )
|
||||
{
|
||||
if( !SDL_GetKeyboardState(NULL)[SDL_KEY(LEFT)] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, SDL_KEY(LEFT), 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( SDL_GetKeyboardState(NULL)[SDL_KEY(LEFT)] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, SDL_KEY(LEFT), 0 );
|
||||
}
|
||||
if( stick1x > 0.5f )
|
||||
{
|
||||
if( !SDL_GetKeyboardState(NULL)[SDL_KEY(RIGHT)] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, SDL_KEY(RIGHT), 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( SDL_GetKeyboardState(NULL)[SDL_KEY(RIGHT)] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, SDL_KEY(RIGHT), 0 );
|
||||
}
|
||||
if( stick1y < -0.5f )
|
||||
{
|
||||
if( !SDL_GetKeyboardState(NULL)[SDL_KEY(UP)] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, SDL_KEY(UP), 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( SDL_GetKeyboardState(NULL)[SDL_KEY(UP)] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, SDL_KEY(UP), 0 );
|
||||
}
|
||||
if( stick1y > 0.5f )
|
||||
{
|
||||
if( !SDL_GetKeyboardState(NULL)[SDL_KEY(DOWN)] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, SDL_KEY(DOWN), 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( SDL_GetKeyboardState(NULL)[SDL_KEY(DOWN)] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, SDL_KEY(DOWN), 0 );
|
||||
}
|
||||
dpadx = stick1x;
|
||||
dpady = stick1y;
|
||||
}
|
||||
if( fabsf(stick2x) > 0.2 || fabsf(stick2y) > 0.2 )
|
||||
if( fabsf(stick2x) > 0.2f || fabsf(stick2y) > 0.2f )
|
||||
{
|
||||
// Move mouse with right stick
|
||||
SDL_ANDROID_moveMouseWithKbAccelUpdateNeeded |= 4;
|
||||
@@ -1485,6 +1446,47 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeGamepadAnalogJoystickInput) (JNIEnv* en
|
||||
SDL_ANDROID_moveMouseWithKbAccelUpdateNeeded &= ~4;
|
||||
}
|
||||
}
|
||||
// Translate to up/down/left/right
|
||||
if( dpadx < -0.5f )
|
||||
{
|
||||
if( !SDL_GetKeyboardState(NULL)[SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_14))] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_14)), 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( SDL_GetKeyboardState(NULL)[SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_14))] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_14)), 0 );
|
||||
}
|
||||
if( dpadx > 0.5f )
|
||||
{
|
||||
if( !SDL_GetKeyboardState(NULL)[SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_15))] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_15)), 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( SDL_GetKeyboardState(NULL)[SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_15))] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_15)), 0 );
|
||||
}
|
||||
if( dpady < -0.5f )
|
||||
{
|
||||
if( !SDL_GetKeyboardState(NULL)[SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_12))] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_12)), 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( SDL_GetKeyboardState(NULL)[SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_12))] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_12)), 0 );
|
||||
}
|
||||
if( dpady > 0.5f )
|
||||
{
|
||||
if( !SDL_GetKeyboardState(NULL)[SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_13))] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_13)), 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( SDL_GetKeyboardState(NULL)[SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_13))] )
|
||||
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_13)), 0 );
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_SYS_JoystickInit(void)
|
||||
|
||||
@@ -241,6 +241,24 @@ extern int SDL_ANDROID_isTouchscreenKeyboardUsed;
|
||||
#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_9
|
||||
#define SDL_ANDROID_GAMEPAD_KEYCODE_9 RETURN
|
||||
#endif
|
||||
#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_10
|
||||
#define SDL_ANDROID_GAMEPAD_KEYCODE_10 SDL_ANDROID_KEYCODE_5
|
||||
#endif
|
||||
#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_11
|
||||
#define SDL_ANDROID_GAMEPAD_KEYCODE_11 SDL_ANDROID_KEYCODE_4
|
||||
#endif
|
||||
#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_12
|
||||
#define SDL_ANDROID_GAMEPAD_KEYCODE_12 UP
|
||||
#endif
|
||||
#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_13
|
||||
#define SDL_ANDROID_GAMEPAD_KEYCODE_13 DOWN
|
||||
#endif
|
||||
#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_14
|
||||
#define SDL_ANDROID_GAMEPAD_KEYCODE_14 LEFT
|
||||
#endif
|
||||
#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_15
|
||||
#define SDL_ANDROID_GAMEPAD_KEYCODE_15 RIGHT
|
||||
#endif
|
||||
|
||||
// Queue events to main thread
|
||||
extern void SDL_ANDROID_MainThreadPushMouseMotion(int x, int y);
|
||||
|
||||
@@ -144,8 +144,8 @@ void SDL_android_init_keymap(SDLKey *SDL_android_keymap)
|
||||
keymap[KEYCODE_BUTTON_R2] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_7));
|
||||
keymap[KEYCODE_BUTTON_THUMBL] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_8));
|
||||
keymap[KEYCODE_BUTTON_THUMBR] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_9));
|
||||
keymap[KEYCODE_BUTTON_START] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_5));
|
||||
keymap[KEYCODE_BUTTON_SELECT] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_4));
|
||||
keymap[KEYCODE_BUTTON_START] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_10));
|
||||
keymap[KEYCODE_BUTTON_SELECT] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_11));
|
||||
keymap[KEYCODE_BUTTON_MODE] = SDL_KEY(SPACE);
|
||||
keymap[KEYCODE_ESCAPE] = SDL_KEY(ESCAPE);
|
||||
keymap[KEYCODE_FORWARD_DEL] = SDL_KEY(DELETE);
|
||||
@@ -233,8 +233,8 @@ void SDL_android_init_keymap(SDLKey *SDL_android_keymap)
|
||||
keymap[KEYCODE_BUTTON_6] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_5));
|
||||
keymap[KEYCODE_BUTTON_7] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_6));
|
||||
keymap[KEYCODE_BUTTON_8] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_7));
|
||||
keymap[KEYCODE_BUTTON_9] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_5));
|
||||
keymap[KEYCODE_BUTTON_10] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_4));
|
||||
keymap[KEYCODE_BUTTON_9] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_10));
|
||||
keymap[KEYCODE_BUTTON_10] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_11));
|
||||
keymap[KEYCODE_BUTTON_11] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_8));
|
||||
keymap[KEYCODE_BUTTON_12] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_9));
|
||||
keymap[KEYCODE_BUTTON_13] = SDL_KEY(M);
|
||||
|
||||
Reference in New Issue
Block a user