From f02e93636f2ee5db689f3055ab91a2b7eb82da09 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Fri, 10 Nov 2017 22:09:50 +0200 Subject: [PATCH] SDL: bigger screen buttons touch area, smaller button images --- project/java/Globals.java | 2 +- project/java/Settings.java | 25 ++++++++++++++----- .../ballfield/AndroidAppSettings.cfg | 4 +-- .../src/video/android/SDL_renderer_gles.c | 2 ++ .../video/android/SDL_touchscreenkeyboard.c | 21 +++++++++++----- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/project/java/Globals.java b/project/java/Globals.java index 2f2e8a77d..f13a37943 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -92,7 +92,7 @@ class Globals public static boolean UseTouchscreenKeyboard = true; public static int TouchscreenKeyboardSize = 1; public static final int TOUCHSCREEN_KEYBOARD_CUSTOM = 4; - public static int TouchscreenKeyboardDrawSize = 1; + public static int TouchscreenKeyboardDrawSize = 2; public static int TouchscreenKeyboardTheme = 2; public static int TouchscreenKeyboardTransparency = 2; public static boolean FloatingScreenJoystick = false; diff --git a/project/java/Settings.java b/project/java/Settings.java index 1ba99c6c8..9e6150a41 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -85,6 +85,7 @@ public class Settings static boolean settingsLoaded = false; static boolean settingsChanged = false; static final int SETTINGS_FILE_VERSION = 5; + static boolean convertButtonSizeFromOldSdlVersion = false; static void Save(final MainActivity p) { @@ -187,6 +188,8 @@ public class Settings out.writeBoolean(Globals.AutoDetectOrientation); out.writeBoolean(Globals.TvBorders); out.writeBoolean(Globals.ForceHardwareMouse); + convertButtonSizeFromOldSdlVersion = false; + out.writeBoolean(convertButtonSizeFromOldSdlVersion); out.close(); settingsLoaded = true; @@ -270,6 +273,7 @@ public class Settings // ICS update sends events in a proper way Globals.RemapHwKeycode[112] = SDL_1_2_Keycodes.SDLK_UNKNOWN; } + convertButtonSizeFromOldSdlVersion = false; try { ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName )); @@ -281,6 +285,7 @@ public class Settings Globals.UseAccelerometerAsArrowKeys = settingsFile.readBoolean(); Globals.UseTouchscreenKeyboard = settingsFile.readBoolean(); Globals.TouchscreenKeyboardSize = settingsFile.readInt(); + convertButtonSizeFromOldSdlVersion = true; // Will be changed to false if we read the remainder of the config file Globals.AccelerometerSensitivity = settingsFile.readInt(); Globals.AccelerometerCenterPos = settingsFile.readInt(); settingsFile.readInt(); @@ -381,6 +386,7 @@ public class Settings Globals.AutoDetectOrientation = settingsFile.readBoolean(); Globals.TvBorders = settingsFile.readBoolean(); Globals.ForceHardwareMouse = settingsFile.readBoolean(); + convertButtonSizeFromOldSdlVersion = settingsFile.readBoolean(); settingsLoaded = true; @@ -403,12 +409,18 @@ public class Settings return; } catch( FileNotFoundException e ) { - Log.i("SDL", "libSDL: settings file not found: " + e); + Log.i("SDL", "libSDL: settings file not found: " + e); } catch( SecurityException e ) { - Log.i("SDL", "libSDL: settings file cannot be opened: " + e); - } catch ( IOException e ) { - Log.i("SDL", "libSDL: settings file cannot be read: " + e); + Log.i("SDL", "libSDL: settings file cannot be opened: " + e); + } catch( IOException e ) { + Log.i("SDL", "libSDL: settings file cannot be read: " + e); DeleteFilesOnUpgrade(p); + if (convertButtonSizeFromOldSdlVersion && Globals.TouchscreenKeyboardSize + 1 < Globals.TOUCHSCREEN_KEYBOARD_CUSTOM) + { + Globals.TouchscreenKeyboardSize ++; // New default button size is bigger, but we are keeping old button size for existing installations + //if (Globals.AppTouchscreenKeyboardKeysAmount <= 4 && Globals.TouchscreenKeyboardSize + 1 < Globals.TOUCHSCREEN_KEYBOARD_CUSTOM) + // Globals.TouchscreenKeyboardSize ++; // If there are only 4 buttons they are even bigger + } if( Globals.ResetSdlConfigForThisVersion ) { Log.i("SDL", "libSDL: old cfg version unknown or too old, our version " + p.getApplicationVersion() + " and we need to clean up config file"); @@ -593,7 +605,8 @@ public class Settings Globals.TouchscreenKeyboardDrawSize, Globals.TouchscreenKeyboardTheme, Globals.TouchscreenKeyboardTransparency, - Globals.FloatingScreenJoystick ? 1 : 0 ); + Globals.FloatingScreenJoystick ? 1 : 0, + Globals.AppTouchscreenKeyboardKeysAmount ); SetupTouchscreenKeyboardGraphics(p); for( int i = 0; i < Globals.RemapScreenKbKeycode.length; i++ ) nativeSetKeymapKeyScreenKb(i, SDL_Keys.values[Globals.RemapScreenKbKeycode[i]]); @@ -967,7 +980,7 @@ public class Settings private static native void nativeSetCompatibilityHacks(); private static native void nativeSetVideoMultithreaded(); private static native void nativeSetVideoForceSoftwareMode(); - private static native void nativeSetupScreenKeyboard(int size, int drawsize, int theme, int transparency, int floatingScreenJoystick); + private static native void nativeSetupScreenKeyboard(int size, int drawsize, int theme, int transparency, int floatingScreenJoystick, int buttonAmount); private static native void nativeSetupScreenKeyboardButtons(byte[] img); private static native void nativeInitKeymap(); private static native int nativeGetKeymapKey(int key); diff --git a/project/jni/application/ballfield/AndroidAppSettings.cfg b/project/jni/application/ballfield/AndroidAppSettings.cfg index 76de440fd..b041883fc 100644 --- a/project/jni/application/ballfield/AndroidAppSettings.cfg +++ b/project/jni/application/ballfield/AndroidAppSettings.cfg @@ -203,7 +203,7 @@ NonBlockingSwapBuffers=n RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE" # Number of virtual keyboard keys (currently 6 is maximum) -AppTouchscreenKeyboardKeysAmount=6 +AppTouchscreenKeyboardKeysAmount=4 # Redefine on-screen keyboard keys to SDL keysyms - 6 keyboard keys + 4 multitouch gestures (zoom in/out and rotate left/right) RedefinedKeysScreenKb="0 1 2 3 4 5 6 7 8 9" @@ -222,7 +222,7 @@ RedefinedKeysScreenKbNames="0 1 2 3 4 5 6 7 8 9" # 7 = SuperNintendo from RetroArch # 8 = DualShock from RetroArch # 9 = Nintendo64 from RetroArch -TouchscreenKeysTheme=4 +TouchscreenKeysTheme=3 # Redefine gamepad keys to SDL keysyms, button order is: # A B X Y L1 R1 L2 R2 LThumb RThumb Start Select Up Down Left Right diff --git a/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c b/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c index e9a875e82..6a2218492 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_renderer_gles.c @@ -30,6 +30,8 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li #if SDL_VIDEO_RENDER_OGL_ES +#define GL_GLEXT_PROTOTYPES 1 + #if SDL_VERSION_ATLEAST(1,3,0) #include "SDL_video.h" #include "SDL_opengles.h" diff --git a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c index d3ffd45a5..b492319e1 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c @@ -34,6 +34,8 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li #include // for memset() #include +#define GL_GLEXT_PROTOTYPES 1 + #include "SDL_opengles.h" #include "SDL_config.h" @@ -748,15 +750,15 @@ void shrinkButtonRect(SDL_Rect s, SDL_Rect * d) return; } - d->w = s.w * 2 / (buttonDrawSize+2); - d->h = s.h * 2 / (buttonDrawSize+2); + d->w = s.w * 2 / (buttonDrawSize+3); + d->h = s.h * 2 / (buttonDrawSize+3); d->x = s.x + s.w / 2 - d->w / 2; d->y = s.y + s.h / 2 - d->h / 2; } JNIEXPORT void JNICALL JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thiz, - jint size, jint drawsize, jint theme, jint _transparency, jint _floatingScreenJoystick ) + jint size, jint drawsize, jint theme, jint _transparency, jint _floatingScreenJoystick, jint buttonAmount ) { int i, ii; int nbuttons1row, nbuttons2row; @@ -782,9 +784,14 @@ JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thiz case 4: transparency = 255.0f/255.0f; break; default: transparency = 192.0f/255.0f; break; } - + + // Screen height fits three buttons at max size + int buttonSizePixels = SDL_ANDROID_sRealWindowHeight * (8 - size) / 8 / 3; + if (buttonAmount <= 4) // Screen height fits two buttons at max size + buttonSizePixels = SDL_ANDROID_sRealWindowHeight * (8 - size) / 8 * 3 / 8; // BIGGER BUTTONS ARE BETTER BUTTONS + // Arrows to the lower-left part of screen - arrows[0].w = SDL_ANDROID_sRealWindowWidth / (size + 3) * 2 / 2; + arrows[0].w = buttonSizePixels * 2; // JOYSTICK SIZE XXL arrows[0].h = arrows[0].w; // Move to the screen edge arrows[0].x = 0; @@ -821,7 +828,7 @@ JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboard) ( JNIEnv* env, jobject thiz { // Custom button ordering int iii = ii + i*2; - buttons[iii].w = SDL_ANDROID_sRealWindowWidth / (size + 3) / 2; + buttons[iii].w = buttonSizePixels; buttons[iii].h = buttons[iii].w; // Move to the screen edge buttons[iii].x = SDL_ANDROID_sRealWindowWidth - buttons[iii].w * (ii + 1); @@ -1315,6 +1322,7 @@ int SDLCALL SDL_ANDROID_SetScreenKeyboardButtonStayPressedAfterTouch(int buttonI int SDLCALL SDL_ANDROID_SetScreenKeyboardTransparency(int alpha) { transparency = (float)alpha / 255.0f; + return 0; } static int ScreenKbRedefinedByUser = 0; @@ -1374,6 +1382,7 @@ extern DECLSPEC int SDL_ANDROID_ScreenKeyboardUpdateToNewVideoMode(int oldx, int pos2.h = (pos.y + pos.h) * newy / oldy - pos2.y; SDL_ANDROID_SetScreenKeyboardButtonPos(i, &pos2); } + return 0; } /**