Android: Try supporting gamepad controller buttons

This commit is contained in:
UnknownShadow200 2023-09-07 18:08:14 +10:00
parent 63aa34d2c2
commit f9c898f859
8 changed files with 31 additions and 1 deletions

View file

@ -54,6 +54,7 @@ enum InputButtons {
INPUT_CLIPBOARD_COPY = 1001,
INPUT_CLIPBOARD_PASTE = 1002
};
#define Input_IsPadButton(btn) ((btn) >= CCPAD_A && (btn) < INPUT_COUNT)
extern const char* const Input_DisplayNames[INPUT_COUNT];

View file

@ -78,6 +78,24 @@ static int MapNativeKey(int code) {
case AKEYCODE_NUMPAD_ADD: return CCKEY_KP_PLUS;
case AKEYCODE_NUMPAD_DOT: return CCKEY_KP_DECIMAL;
case AKEYCODE_NUMPAD_ENTER: return CCKEY_KP_ENTER;
case AKEYCODE_DPAD_UP: return CCPAD_UP;
case AKEYCODE_DPAD_DOWN: return CCPAD_DOWN;
case AKEYCODE_DPAD_LEFT: return CCPAD_LEFT;
case AKEYCODE_DPAD_RIGHT: return CCPAD_RIGHT;
case AKEYCODE_BUTTON_A: return CCPAD_A;
case AKEYCODE_BUTTON_B: return CCPAD_B;
case AKEYCODE_BUTTON_X: return CCPAD_X;
case AKEYCODE_BUTTON_Y: return CCPAD_Y;
case AKEYCODE_BUTTON_L1: return CCPAD_L;
case AKEYCODE_BUTTON_R1: return CCPAD_R;
case AKEYCODE_BUTTON_L2: return CCPAD_ZL;
case AKEYCODE_BUTTON_R2: return CCPAD_ZR;
case AKEYCODE_BUTTON_START: return CCPAD_START;
case AKEYCODE_BUTTON_SELECT: return CCPAD_SELECT;
}
return INPUT_NONE;
}
@ -86,6 +104,8 @@ static void JNICALL java_processKeyDown(JNIEnv* env, jobject o, jint code) {
int key = MapNativeKey(code);
Platform_Log2("KEY - DOWN %i,%i", &code, &key);
if (key) Input_SetPressed(key);
if (Input_IsPadButton(key)) Input.Sources |= INPUT_SOURCE_GAMEPAD;
}
static void JNICALL java_processKeyUp(JNIEnv* env, jobject o, jint code) {
@ -259,6 +279,7 @@ void Window_Init(void) {
WindowInfo.SoftKeyboard = SOFT_KEYBOARD_RESIZE;
Input_SetTouchMode(true);
Input.Sources = INPUT_SOURCE_NORMAL;
DisplayInfo.Depth = 32;
DisplayInfo.ScaleX = JavaICall_Float(env, JAVA_getDpiX, NULL);

View file

@ -29,6 +29,7 @@ void Window_Init(void) {
SDL_DisplayMode mode = { 0 };
SDL_Init(SDL_INIT_VIDEO);
SDL_GetDesktopDisplayMode(0, &mode);
Input.Sources = INPUT_SOURCE_NORMAL;
DisplayInfo.Width = mode.w;
DisplayInfo.Height = mode.h;

View file

@ -285,9 +285,11 @@ void Window_Init(void) {
void* lib;
HDC hdc;
DisplayInfo.DPIScaling = Options_GetBool(OPT_DPI_SCALING, false);
DynamicLib_LoadAll(&user32, funcs, Array_Elems(funcs), &lib);
Input.Sources = INPUT_SOURCE_NORMAL;
/* Enable high DPI support */
DisplayInfo.DPIScaling = Options_GetBool(OPT_DPI_SCALING, false);
if (DisplayInfo.DPIScaling && _SetProcessDPIAware) _SetProcessDPIAware();
hdc = GetDC(NULL);

View file

@ -260,6 +260,7 @@ void Window_Init(void) {
win_display = display;
win_rootWin = RootWindow(display, screen);
Input.Sources = INPUT_SOURCE_NORMAL;
/* TODO: Use Xinerama and XRandR for querying these */
DisplayInfo.Width = DisplayWidth(display, screen);

View file

@ -381,6 +381,8 @@ static void RunApp(void) {
void Window_Init(void) {
Events_Init();
RunApp();
Input.Sources = INPUT_SOURCE_NORMAL;
BScreen screen(B_MAIN_SCREEN_ID);
BRect frame = screen.Frame();

View file

@ -150,6 +150,7 @@ static void LogUnhandledNSErrors(NSException* ex) {
static NSAutoreleasePool* pool;
void Window_Init(void) {
NSSetUncaughtExceptionHandler(LogUnhandledNSErrors);
Input.Sources = INPUT_SOURCE_NORMAL;
// https://www.cocoawithlove.com/2009/01/demystifying-nsapplication-by.html
pool = [[NSAutoreleasePool alloc] init];

View file

@ -346,6 +346,7 @@ void Window_Init(void) {
// keyboard now shifts up
WindowInfo.SoftKeyboard = SOFT_KEYBOARD_SHIFT;
Input_SetTouchMode(true);
Input.Sources = INPUT_SOURCE_NORMAL;
DisplayInfo.Depth = 32;
DisplayInfo.ScaleX = 1; // TODO dpi scale