diff --git a/changeAppSettings.sh b/changeAppSettings.sh index 6ecd3f454..270c6e9a8 100755 --- a/changeAppSettings.sh +++ b/changeAppSettings.sh @@ -328,6 +328,20 @@ if [ -n "$var" ] ; then fi fi +if [ "$AppUsesJoystick" = "y" ]; then +if [ -z "$AppUsesSecondJoystick" -o -z "$AUTO" ]; then +echo +echo -n "Application uses second on-screen joystick, as SDL joystick 0 axes 2-3 (y)/(n) ($AppUsesSecondJoystick): " +read var +if [ -n "$var" ] ; then + AppUsesSecondJoystick="$var" + CHANGED=1 +fi +fi +else +AppUsesSecondJoystick=n +fi + if [ -z "$AppUsesAccelerometer" -o -z "$AUTO" ]; then echo echo -n "Application uses accelerometer (y) or (n), the accelerometer will be used as joystick 1 axes 0-1 ($AppUsesAccelerometer): " @@ -736,6 +750,7 @@ echo ForceRelativeMouseMode=$ForceRelativeMouseMode >> AndroidAppSettings.cfg echo AppNeedsArrowKeys=$AppNeedsArrowKeys >> AndroidAppSettings.cfg echo AppNeedsTextInput=$AppNeedsTextInput >> AndroidAppSettings.cfg echo AppUsesJoystick=$AppUsesJoystick >> AndroidAppSettings.cfg +echo AppUsesSecondJoystick=$AppUsesSecondJoystick >> AndroidAppSettings.cfg echo AppUsesAccelerometer=$AppUsesAccelerometer >> AndroidAppSettings.cfg echo AppUsesGyroscope=$AppUsesGyroscope >> AndroidAppSettings.cfg echo AppUsesMultitouch=$AppUsesMultitouch >> AndroidAppSettings.cfg @@ -915,6 +930,12 @@ else AppUsesJoystick=false fi +if [ "$AppUsesSecondJoystick" = "y" ] ; then + AppUsesSecondJoystick=true +else + AppUsesSecondJoystick=false +fi + if [ "$AppUsesAccelerometer" = "y" ] ; then AppUsesAccelerometer=true else @@ -1075,6 +1096,7 @@ $SEDI "s/public static boolean ShowMouseCursor = .*;/public static boolean ShowM $SEDI "s/public static boolean AppNeedsArrowKeys = .*;/public static boolean AppNeedsArrowKeys = $AppNeedsArrowKeys;/" project/src/Globals.java $SEDI "s/public static boolean AppNeedsTextInput = .*;/public static boolean AppNeedsTextInput = $AppNeedsTextInput;/" project/src/Globals.java $SEDI "s/public static boolean AppUsesJoystick = .*;/public static boolean AppUsesJoystick = $AppUsesJoystick;/" project/src/Globals.java +$SEDI "s/public static boolean AppUsesSecondJoystick = .*;/public static boolean AppUsesSecondJoystick = $AppUsesSecondJoystick;/" project/src/Globals.java $SEDI "s/public static boolean AppUsesAccelerometer = .*;/public static boolean AppUsesAccelerometer = $AppUsesAccelerometer;/" project/src/Globals.java $SEDI "s/public static boolean AppUsesGyroscope = .*;/public static boolean AppUsesGyroscope = $AppUsesGyroscope;/" project/src/Globals.java $SEDI "s/public static boolean AppUsesMultitouch = .*;/public static boolean AppUsesMultitouch = $AppUsesMultitouch;/" project/src/Globals.java diff --git a/project/java/Globals.java b/project/java/Globals.java index 686db0324..46d123591 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -53,6 +53,7 @@ class Globals public static boolean AppNeedsArrowKeys = true; public static boolean AppNeedsTextInput = true; public static boolean AppUsesJoystick = false; + public static boolean AppUsesSecondJoystick = false; public static boolean AppUsesAccelerometer = false; public static boolean AppUsesGyroscope = false; public static boolean AppUsesMultitouch = false; diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 4c2ddd28a..8ec2aa4cf 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -288,9 +288,6 @@ public class MainActivity extends Activity Log.i("SDL", "libSDL: Initializing video and SDL application"); sdlInited = true; - if(Globals.UseAccelerometerAsArrowKeys || Globals.AppUsesAccelerometer) - getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, - WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); _videoLayout.removeView(_layout); if( _ad.getView() != null ) _videoLayout.removeView(_ad.getView()); diff --git a/project/java/Settings.java b/project/java/Settings.java index cffd8d8f8..3cdefd555 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -2666,8 +2666,7 @@ class Settings Globals.RelativeMouseMovementSpeed, Globals.RelativeMouseMovementAccel, Globals.ShowMouseCursor ? 1 : 0 ); - if( Globals.AppUsesJoystick && (Globals.UseAccelerometerAsArrowKeys || Globals.UseTouchscreenKeyboard) ) - nativeSetJoystickUsed(); + nativeSetJoystickUsed(Globals.AppUsesJoystick ? 1 : 0, Globals.AppUsesSecondJoystick ? 1 : 0); if( Globals.AppUsesAccelerometer ) nativeSetAccelerometerUsed(); if( Globals.AppUsesMultitouch ) @@ -2906,7 +2905,7 @@ class Settings int leftClickTimeout, int rightClickTimeout, int relativeMovement, int relativeMovementSpeed, int relativeMovementAccel, int showMouseCursor); - private static native void nativeSetJoystickUsed(); + private static native void nativeSetJoystickUsed(int firstJoystickUsed, int secondJoystickUsed); private static native void nativeSetAccelerometerUsed(); private static native void nativeSetMultitouchUsed(); private static native void nativeSetTouchscreenKeyboardUsed(); diff --git a/project/jni/application/ballfield/AndroidAppSettings.cfg b/project/jni/application/ballfield/AndroidAppSettings.cfg index c482983c0..382e8362a 100644 --- a/project/jni/application/ballfield/AndroidAppSettings.cfg +++ b/project/jni/application/ballfield/AndroidAppSettings.cfg @@ -28,13 +28,14 @@ ForceRelativeMouseMode=n AppNeedsArrowKeys=y AppNeedsTextInput=y AppUsesJoystick=y +AppUsesSecondJoystick=y AppUsesAccelerometer=y AppUsesGyroscope=y AppUsesMultitouch=y AppRecordsAudio=n NonBlockingSwapBuffers=n RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE" -AppTouchscreenKeyboardKeysAmount=4 +AppTouchscreenKeyboardKeysAmount=6 AppTouchscreenKeyboardKeysAmountAutoFire=0 RedefinedKeysScreenKb="0 1 2 3 4 5 6 7 8 9" RedefinedKeysScreenKbNames="0 1 2 3 4 5 6 7 8 9" diff --git a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h index b605cf911..b2d14d679 100644 --- a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h +++ b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h @@ -54,6 +54,7 @@ enum { SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, /* Button to show screen keyboard */ SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, /* Joystick/D-Pad button */ + SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2, /* Second joystick button */ SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM }; diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c b/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c index 7540c0d02..ff78c7378 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c @@ -81,6 +81,7 @@ int SDL_ANDROID_moveMouseWithKbAccelUpdateNeeded = 0; static int maxForce = 0; static int maxRadius = 0; int SDL_ANDROID_isJoystickUsed = 0; +int SDL_ANDROID_isSecondJoystickUsed = 0; static int SDL_ANDROID_isAccelerometerUsed = 0; static int isMultitouchUsed = 0; SDL_Joystick *SDL_ANDROID_CurrentJoysticks[MAX_MULTITOUCH_POINTERS+1]; @@ -300,6 +301,7 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t #if SDL_VIDEO_RENDER_RESIZE // Translate mouse coordinates + x -= (SDL_ANDROID_sRealWindowWidth - SDL_ANDROID_sWindowWidth) / 2; x = x * SDL_ANDROID_sFakeWindowWidth / SDL_ANDROID_TouchscreenCalibrationWidth; y = y * SDL_ANDROID_sFakeWindowHeight / SDL_ANDROID_TouchscreenCalibrationHeight; if( x < 0 ) @@ -310,6 +312,7 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t y = 0; if( y > SDL_ANDROID_sFakeWindowHeight ) y = SDL_ANDROID_sFakeWindowHeight; + #else x = x * SDL_ANDROID_sRealWindowWidth / SDL_ANDROID_TouchscreenCalibrationWidth; y = y * SDL_ANDROID_sRealWindowHeight / SDL_ANDROID_TouchscreenCalibrationHeight; @@ -807,8 +810,6 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeTextInputFinished) ( JNIEnv* env, jobject t SDL_ANDROID_TextInputFinished = 1; } -static void updateOrientation ( float accX, float accY, float accZ ); - JNIEXPORT void JNICALL JAVA_EXPORT_NAME(AccelerometerReader_nativeAccelerometer) ( JNIEnv* env, jobject thiz, jfloat accPosX, jfloat accPosY, jfloat accPosZ ) { @@ -817,15 +818,15 @@ JAVA_EXPORT_NAME(AccelerometerReader_nativeAccelerometer) ( JNIEnv* env, jobjec if( !SDL_CurrentVideoSurface ) return; #endif - // Calculate two angles from three coordinates - TODO: this is faulty! - //float accX = atan2f(-accPosX, sqrtf(accPosY*accPosY+accPosZ*accPosZ) * ( accPosY > 0 ? 1.0f : -1.0f ) ) * M_1_PI * 180.0f; - //float accY = atan2f(accPosZ, accPosY) * M_1_PI; - + // Calculate two angles from three coordinates float normal = sqrt(accPosX*accPosX+accPosY*accPosY+accPosZ*accPosZ); if(normal <= 0.0000001f) normal = 0.00001f; - updateOrientation (accPosX/normal, accPosY/normal, 0.0f); + SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 0, NORMALIZE_FLOAT_32767(accPosX/normal)); + SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 1, NORMALIZE_FLOAT_32767(-accPosY/normal)); + + // Also send raw coordinates SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 5, fminf(32767.0f, fmaxf(-32767.0f, accPosX*1000.0f))); // Do not consider wraparound case SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 6, fminf(32767.0f, fmaxf(-32767.0f, accPosY*1000.0f))); SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 7, fminf(32767.0f, fmaxf(-32767.0f, accPosZ*1000.0f))); @@ -1029,9 +1030,10 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouseWheel) (JNIEnv* env, jobject thiz, } JNIEXPORT void JNICALL -JAVA_EXPORT_NAME(Settings_nativeSetJoystickUsed) (JNIEnv* env, jobject thiz) +JAVA_EXPORT_NAME(Settings_nativeSetJoystickUsed) (JNIEnv* env, jobject thiz, jint first, jint second) { - SDL_ANDROID_isJoystickUsed = 1; + SDL_ANDROID_isJoystickUsed = first; + SDL_ANDROID_isSecondJoystickUsed = second; } JNIEXPORT void JNICALL @@ -1072,178 +1074,6 @@ JAVA_EXPORT_NAME(Settings_nativeSetTrackballDampening) ( JNIEnv* env, jobject t TrackballDampening = (value * 200); } -void updateOrientation ( float accX, float accY, float accZ ) -{ - SDL_keysym keysym; - // TODO: ask user for accelerometer precision from Java - - static float midX = 0, midY = 0, midZ = 0; - static int pressLeft = 0, pressRight = 0, pressUp = 0, pressDown = 0, pressR = 0, pressL = 0; - - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "updateOrientation(): %f %f %f", accX, accY, accZ); - - if( SDL_ANDROID_isAccelerometerUsed ) - { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "updateOrientation(): sending joystick event"); - SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 0, NORMALIZE_FLOAT_32767(accX)); - SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 1, NORMALIZE_FLOAT_32767(-accY)); - //SDL_ANDROID_MainThreadPushJoystickAxis(0, 2, (Sint16)(fminf(32767.0f, fmax(-32767.0f, -(accZ) * 32767.0f)))); - return; - } - - if( accelerometerCenterPos == ACCELEROMETER_CENTER_FIXED_START ) - { - accelerometerCenterPos = ACCELEROMETER_CENTER_FIXED_HORIZ; - midX = accX; - midY = accY; - midZ = accZ; - } - - if( SDL_ANDROID_isJoystickUsed ) - { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "updateOrientation(): sending joystick event"); - SDL_ANDROID_MainThreadPushJoystickAxis(JOY_TOUCHSCREEN, 0, NORMALIZE_FLOAT_32767((accX - midX) * joystickSensitivity)); - SDL_ANDROID_MainThreadPushJoystickAxis(JOY_TOUCHSCREEN, 1, NORMALIZE_FLOAT_32767(-(accY - midY) * joystickSensitivity)); - //SDL_ANDROID_MainThreadPushJoystickAxis(0, 2, (Sint16)(fminf(32767.0f, fmax(-32767.0f, -(accZ - midZ) * joystickSensitivity)))); - - if( accelerometerCenterPos == ACCELEROMETER_CENTER_FLOATING ) - { - if( accY < midY - dy*2 ) - midY = accY + dy*2; - if( accY > midY + dy*2 ) - midY = accY - dy*2; - if( accZ < midZ - dz*2 ) - midZ = accZ + dz*2; - if( accZ > midZ + dz*2 ) - midZ = accZ - dz*2; - } - return; - } - - if( accX < midX - dx ) - { - if( !pressLeft ) - { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: press left, acc %f mid %f d %f", accX, midX, dx); - pressLeft = 1; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, TranslateKey(KEYCODE_DPAD_LEFT) ); - } - } - else - { - if( pressLeft ) - { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: release left, acc %f mid %f d %f", accX, midX, dx); - pressLeft = 0; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_LEFT) ); - } - } - if( accX < midX - dx*2 ) - midX = accX + dx*2; - - if( accX > midX + dx ) - { - if( !pressRight ) - { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: press right, acc %f mid %f d %f", accX, midX, dx); - pressRight = 1; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, TranslateKey(KEYCODE_DPAD_RIGHT) ); - } - } - else - { - if( pressRight ) - { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: release right, acc %f mid %f d %f", accX, midX, dx); - pressRight = 0; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_RIGHT) ); - } - } - if( accX > midX + dx*2 ) - midX = accX - dx*2; - - if( accY < midY - dy ) - { - if( !pressUp ) - { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: press up, acc %f mid %f d %f", accY, midY, dy); - pressUp = 1; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, TranslateKey(KEYCODE_DPAD_DOWN) ); - } - } - else - { - if( pressUp ) - { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: release up, acc %f mid %f d %f", accY, midY, dy); - pressUp = 0; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_DOWN) ); - } - } - if( accY < midY - dy*2 ) - midY = accY + dy*2; - - if( accY > midY + dy ) - { - if( !pressDown ) - { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: press down, acc %f mid %f d %f", accY, midY, dy); - pressDown = 1; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, TranslateKey(KEYCODE_DPAD_UP) ); - } - } - else - { - if( pressDown ) - { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Accelerometer: release down, acc %f mid %f d %f", accY, midY, dy); - pressDown = 0; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_UP) ); - } - } - if( accY > midY + dy*2 ) - midY = accY - dy*2; - - if( accZ < midZ - dz ) - { - if( !pressL ) - { - pressL = 1; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, TranslateKey(KEYCODE_ALT_LEFT) ); - } - } - else - { - if( pressL ) - { - pressL = 0; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_ALT_LEFT) ); - } - } - if( accZ < midZ - dz*2 ) - midZ = accZ + dz*2; - - if( accZ > midZ + dz ) - { - if( !pressR ) - { - pressR = 1; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, TranslateKey(KEYCODE_ALT_RIGHT) ); - } - } - else - { - if( pressR ) - { - pressR = 0; - SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_ALT_RIGHT) ); - } - } - if( accZ > midZ + dz*2 ) - midZ = accZ - dz*2; - -} - JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeGamepadAnalogJoystickInput) (JNIEnv* env, jobject thiz, jfloat stick1x, jfloat stick1y, jfloat stick2x, jfloat stick2y, jfloat rtrigger, jfloat ltrigger) diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h index 42c7e2c98..27d12c4ff 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.h @@ -84,6 +84,7 @@ extern SDL_Window * ANDROID_CurrentWindow; enum { MAX_MULTITOUCH_POINTERS = 16 }; extern void ANDROID_InitOSKeymap(); extern int SDL_ANDROID_isJoystickUsed; +extern int SDL_ANDROID_isSecondJoystickUsed; // Events have to be sent only from main thread from PumpEvents(), so we'll buffer them here extern void SDL_ANDROID_PumpEvents(); 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 8b5b39b92..06b52ed5b 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 @@ -44,7 +44,7 @@ // TODO: this code is a HUGE MESS -enum { MAX_BUTTONS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM-1, MAX_BUTTONS_AUTOFIRE = 2, BUTTON_TEXT_INPUT = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, BUTTON_ARROWS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD } ; // Max amount of custom buttons +enum { MAX_BUTTONS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM-1, MAX_JOYSTICKS = 2, MAX_BUTTONS_AUTOFIRE = 2, BUTTON_TEXT_INPUT = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, BUTTON_ARROWS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD } ; // Max amount of custom buttons int SDL_ANDROID_isTouchscreenKeyboardUsed = 0; static short touchscreenKeyboardTheme = 0; @@ -54,8 +54,8 @@ static short buttonsize = 1; static short buttonDrawSize = 1; static float transparency = 128.0f/255.0f; -static SDL_Rect arrows, arrowsExtended, buttons[MAX_BUTTONS], buttonsAutoFireRect[MAX_BUTTONS_AUTOFIRE]; -static SDL_Rect arrowsDraw, buttonsDraw[MAX_BUTTONS]; +static SDL_Rect arrows[MAX_JOYSTICKS], arrowsExtended[MAX_JOYSTICKS], buttons[MAX_BUTTONS], buttonsAutoFireRect[MAX_BUTTONS_AUTOFIRE]; +static SDL_Rect arrowsDraw[MAX_JOYSTICKS], buttonsDraw[MAX_BUTTONS]; static SDLKey buttonKeysyms[MAX_BUTTONS] = { SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_0)), SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_1)), @@ -73,8 +73,8 @@ static short ButtonAutoFireX[MAX_BUTTONS_AUTOFIRE*2]; static short ButtonAutoFireRot[MAX_BUTTONS_AUTOFIRE]; static short ButtonAutoFireDecay[MAX_BUTTONS_AUTOFIRE]; -static short pointerInButtonRect[MAX_BUTTONS + 1]; -static short buttonsGenerateSdlEvents[MAX_BUTTONS + 1]; +static short pointerInButtonRect[MAX_BUTTONS + MAX_JOYSTICKS]; +static short buttonsGenerateSdlEvents[MAX_BUTTONS + MAX_JOYSTICKS]; typedef struct { @@ -90,7 +90,7 @@ static GLTexture_t mousePointer; enum { MOUSE_POINTER_W = 32, MOUSE_POINTER_H = 32, MOUSE_POINTER_X = 5, MOUSE_POINTER_Y = 7 }; // X and Y are offsets of the pointer tip static int sunTheme = 0; -static int joystickTouchPoints[2]; +static int joystickTouchPoints[MAX_JOYSTICKS*2]; static inline int InsideRect(const SDL_Rect * r, int x, int y) { @@ -226,18 +226,20 @@ static void drawTouchscreenKeyboardLegacy() ( SDL_GetKeyboardState(NULL)[SDL_KEY(UP)] ? 1 : 0 ) + ( SDL_GetKeyboardState(NULL)[SDL_KEY(DOWN)] ? 1 : 0 ); if( blendFactor == 0 || SDL_ANDROID_isJoystickUsed ) - drawCharTex( &arrowImages[0], NULL, &arrowsDraw, 1.0f, 1.0f, 1.0f, transparency ); + drawCharTex( &arrowImages[0], NULL, &arrowsDraw[0], 1.0f, 1.0f, 1.0f, transparency ); else { if( SDL_GetKeyboardState(NULL)[SDL_KEY(LEFT)] ) - drawCharTex( &arrowImages[1], NULL, &arrowsDraw, 1.0f, 1.0f, 1.0f, transparency / blendFactor ); + drawCharTex( &arrowImages[1], NULL, &arrowsDraw[0], 1.0f, 1.0f, 1.0f, transparency / blendFactor ); if( SDL_GetKeyboardState(NULL)[SDL_KEY(RIGHT)] ) - drawCharTex( &arrowImages[2], NULL, &arrowsDraw, 1.0f, 1.0f, 1.0f, transparency / blendFactor ); + drawCharTex( &arrowImages[2], NULL, &arrowsDraw[0], 1.0f, 1.0f, 1.0f, transparency / blendFactor ); if( SDL_GetKeyboardState(NULL)[SDL_KEY(UP)] ) - drawCharTex( &arrowImages[3], NULL, &arrowsDraw, 1.0f, 1.0f, 1.0f, transparency / blendFactor ); + drawCharTex( &arrowImages[3], NULL, &arrowsDraw[0], 1.0f, 1.0f, 1.0f, transparency / blendFactor ); if( SDL_GetKeyboardState(NULL)[SDL_KEY(DOWN)] ) - drawCharTex( &arrowImages[4], NULL, &arrowsDraw, 1.0f, 1.0f, 1.0f, transparency / blendFactor ); + drawCharTex( &arrowImages[4], NULL, &arrowsDraw[0], 1.0f, 1.0f, 1.0f, transparency / blendFactor ); } + if( SDL_ANDROID_isSecondJoystickUsed ) + drawCharTex( &arrowImages[0], NULL, &arrowsDraw[1], 1.0f, 1.0f, 1.0f, transparency ); for( i = 0; i < MAX_BUTTONS; i++ ) { @@ -303,15 +305,18 @@ static void drawTouchscreenKeyboardSun() { int i; - drawCharTex( &arrowImages[0], NULL, &arrowsDraw, 1.0f, 1.0f, 1.0f, transparency ); - if(pointerInButtonRect[BUTTON_ARROWS] != -1) + for( i = 0; i <= SDL_ANDROID_isSecondJoystickUsed; i++ ) { - SDL_Rect touch = arrowsDraw; - touch.w /= 2; - touch.h /= 2; - touch.x = joystickTouchPoints[0] - touch.w / 2; - touch.y = joystickTouchPoints[1] - touch.h / 2; - drawCharTex( &arrowImages[0], NULL, &touch, 1.0f, 1.0f, 1.0f, transparency ); + drawCharTex( &arrowImages[0], NULL, &arrowsDraw[i], 1.0f, 1.0f, 1.0f, transparency ); + if(pointerInButtonRect[BUTTON_ARROWS+i] != -1) + { + SDL_Rect touch = arrowsDraw[i]; + touch.w /= 2; + touch.h /= 2; + touch.x = joystickTouchPoints[0+i*2] - touch.w / 2; + touch.y = joystickTouchPoints[1+i*2] - touch.h / 2; + drawCharTex( &arrowImages[0], NULL, &touch, 1.0f, 1.0f, 1.0f, transparency ); + } } for( i = 0; i < MAX_BUTTONS; i++ ) @@ -382,8 +387,8 @@ int SDL_ANDROID_drawTouchscreenKeyboard() static inline int ArrowKeysPressed(int x, int y) { int ret = 0, dx, dy; - dx = x - arrows.x - arrows.w / 2; - dy = y - arrows.y - arrows.h / 2; + dx = x - arrows[0].x - arrows[0].w / 2; + dy = y - arrows[0].y - arrows[0].h / 2; // Single arrow key pressed if( abs(dy / 2) >= abs(dx) ) { @@ -417,7 +422,7 @@ static inline int ArrowKeysPressed(int x, int y) unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId) { - int i; + int i, j; unsigned processed = 0; if( !touchscreenKeyboardShown ) @@ -426,34 +431,37 @@ unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int po if( action == MOUSE_DOWN ) { //__android_log_print(ANDROID_LOG_INFO, "libSDL", "touch %03dx%03d ptr %d action %d", x, y, pointerId, action); - if( InsideRect( &arrows, x, y ) ) + for( j = 0; j <= SDL_ANDROID_isSecondJoystickUsed; j++ ) { - processed |= 1<= SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM || ! pos ) return 0; - if( buttonId == SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD ) + if( buttonId >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD && buttonId <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2 ) { - arrows = *pos; - arrowsExtended.w = arrows.w * 2; - arrowsExtended.h = arrows.h * 2; - arrowsExtended.x = arrows.x + arrows.w / 2 - arrowsExtended.w / 2; - arrowsExtended.y = arrows.y + arrows.h / 2 - arrowsExtended.h / 2; - shrinkButtonRect(arrows, &arrowsDraw); + int i = buttonId - SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD; + arrows[i] = *pos; + arrowsExtended[i].w = arrows[i].w * 2; + arrowsExtended[i].h = arrows[i].h * 2; + arrowsExtended[i].x = arrows[i].x + arrows[i].w / 2 - arrowsExtended[i].w / 2; + arrowsExtended[i].y = arrows[i].y + arrows[i].h / 2 - arrowsExtended[i].h / 2; + shrinkButtonRect(arrows[i], &arrowsDraw[i]); } else { @@ -973,8 +1008,8 @@ int SDLCALL SDL_ANDROID_SetScreenKeyboardButtonImagePos(int buttonId, SDL_Rect * if( buttonId < 0 || buttonId >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM || ! pos ) return 0; - if( buttonId == SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD ) - arrowsDraw = *pos; + if( buttonId >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD && buttonId <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2 ) + arrowsDraw[buttonId - SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD] = *pos; else buttonsDraw[buttonId] = *pos; @@ -986,9 +1021,9 @@ int SDL_ANDROID_GetScreenKeyboardButtonPos(int buttonId, SDL_Rect * pos) if( buttonId < 0 || buttonId >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM || ! pos ) return 0; - if( buttonId == SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD ) + if( buttonId >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD && buttonId <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2 ) { - *pos = arrows; + *pos = arrows[buttonId - SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD]; } else { @@ -1124,12 +1159,15 @@ JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyLayout) (JNIEnv* env, jobject thiz { SDL_Rect rect = {x1, y1, x2-x1, y2-y1}; int key = -1; + // Why didn't I use consistent IDs between Java and C code? if( keynum == 0 ) key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD; if( keynum == 1 ) key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT; if( keynum - 2 >= 0 && keynum - 2 <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 ) key = keynum - 2 + SDL_ANDROID_SCREENKEYBOARD_BUTTON_0; + if( keynum == SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2 ) // This one is consistent by chance + key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2; if( key >= 0 ) { diff --git a/readme.txt b/readme.txt index 28e56d04c..3d193a85b 100644 --- a/readme.txt +++ b/readme.txt @@ -249,6 +249,8 @@ SDL reports several joysticks, which are used to pass accelerometer and multitou On-screen joystick events are sent as SDL_JOYAXISMOTION in event.jaxis.jalue, scaled from -32767 to 32767, with event.jaxis.which == 0 and event.jaxis.axis from 0 to 1, you will need to set AppUsesJoystick=y in AndroidAppSettings.cfg and call SDL_JoystickOpen(0) in your code. +If you specify AppUsesSecondJoystick=y in AndroidAppSettings.cfg, there will be second on-screen joystick, +it will send events with event.jaxis.which == 0 and event.jaxis.axis from 2 to 3. Multitouch events are sent as SDL_JOYBALLMOTION in event.jball.xrel and event.jball.yrel, scaled to screen size, with event.jball.which == 0 and e.jball.ball from 0 to 15, you will need to set AppUsesMultitouch=y in AndroidAppSettings.cfg and call SDL_JoystickOpen(0). SDL_JOYBUTTONDOWN and SDL_JOYBUTTONUP events