cmd/ebitenmobile: fix the button mask to include hat infomation for Android

This commit is contained in:
Hajime Hoshi 2022-09-08 00:04:43 +09:00
parent 4a851bcf27
commit 521ec6f09b
2 changed files with 16 additions and 8 deletions

View File

@ -564,7 +564,7 @@ public class EbitenView extends ViewGroup implements InputManager.InputDeviceLis
int productId = inputDevice.getProductId(); int productId = inputDevice.getProductId();
// These values are required to calculate SDL's GUID. // These values are required to calculate SDL's GUID.
int buttonMask = getButtonMask(inputDevice); int buttonMask = getButtonMask(inputDevice, nhats2/2);
int axisMask = getAxisMask(inputDevice); int axisMask = getAxisMask(inputDevice);
Ebitenmobileview.onGamepadAdded(deviceId, inputDevice.getName(), naxes, nhats2/2, descriptor, vendorId, productId, buttonMask, axisMask); Ebitenmobileview.onGamepadAdded(deviceId, inputDevice.getName(), naxes, nhats2/2, descriptor, vendorId, productId, buttonMask, axisMask);
@ -572,8 +572,8 @@ public class EbitenView extends ViewGroup implements InputManager.InputDeviceLis
// The implementation is copied from SDL: // The implementation is copied from SDL:
// https://github.com/libsdl-org/SDL/blob/0e9560aea22818884921e5e5064953257bfe7fa7/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java#L308 // https://github.com/libsdl-org/SDL/blob/0e9560aea22818884921e5e5064953257bfe7fa7/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java#L308
private int getButtonMask(InputDevice joystickDevice) { private int getButtonMask(InputDevice joystickDevice, int nhats) {
int button_mask = 0; int buttonMask = 0;
int[] keys = new int[] { int[] keys = new int[] {
KeyEvent.KEYCODE_BUTTON_A, KeyEvent.KEYCODE_BUTTON_A,
KeyEvent.KEYCODE_BUTTON_B, KeyEvent.KEYCODE_BUTTON_B,
@ -655,13 +655,21 @@ public class EbitenView extends ViewGroup implements InputManager.InputDeviceLis
0xFFFFFFFF, // 15 -> ?? 0xFFFFFFFF, // 15 -> ??
0xFFFFFFFF, // 16 -> ?? 0xFFFFFFFF, // 16 -> ??
}; };
boolean[] has_keys = joystickDevice.hasKeys(keys); boolean[] hasKeys = joystickDevice.hasKeys(keys);
for (int i = 0; i < keys.length; ++i) { for (int i = 0; i < keys.length; ++i) {
if (has_keys[i]) { if (hasKeys[i]) {
button_mask |= masks[i]; buttonMask |= masks[i];
} }
} }
return button_mask; // https://github.com/libsdl-org/SDL/blob/47f2373dc13b66c48bf4024fcdab53cd0bdd59bb/src/joystick/android/SDL_sysjoystick.c#L360-L367
if (nhats > 0) {
// Add Dpad buttons.
buttonMask |= 1 << 11;
buttonMask |= 1 << 12;
buttonMask |= 1 << 13;
buttonMask |= 1 << 14;
}
return buttonMask;
} }
private int getAxisMask(InputDevice joystickDevice) { private int getAxisMask(InputDevice joystickDevice) {

File diff suppressed because one or more lines are too long