From 5e4b450e74aed7af3fa7db160887ca23caa39636 Mon Sep 17 00:00:00 2001 From: pelya Date: Tue, 8 Feb 2011 12:58:12 +0000 Subject: [PATCH] Implemented speed and acceleration for relative mode --- project/java/Globals.java | 4 +- project/java/Settings.java | 14 +++-- project/java/translations/values/strings.xml | 1 + .../src/video/android/SDL_androidinput.c | 55 ++++++++++++++++--- 4 files changed, 58 insertions(+), 16 deletions(-) diff --git a/project/java/Globals.java b/project/java/Globals.java index c1327b50f..1c5619ac9 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -85,8 +85,8 @@ class Globals { public static int MoveMouseWithJoystickAccel = 0; public static boolean ClickMouseWithDpad = false; public static boolean RelativeMouseMovement = AppNeedsTwoButtonMouse; // Laptop touchpad mode - public static int RelativeMouseMovementSpeed = 0; - public static int RelativeMouseMovementAccel = 1; + public static int RelativeMouseMovementSpeed = 2; + public static int RelativeMouseMovementAccel = 0; public static boolean ShowScreenUnderFinger = false; public static boolean KeepAspectRatio = false; public static int ClickScreenPressure = 0; diff --git a/project/java/Settings.java b/project/java/Settings.java index 87bd51388..bfdbca91d 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -414,7 +414,8 @@ class Settings { public void onCancel(DialogInterface dialog) { - showConfigMainMenu(p); + Save(p); + p.startDownloader(); } }); AlertDialog alert = builder.create(); @@ -1210,9 +1211,11 @@ class Settings static void showRelativeMouseMovementConfig(final MainActivity p) { - final CharSequence[] items = { p.getResources().getString(R.string.accel_fast), + final CharSequence[] items = { p.getResources().getString(R.string.accel_veryslow), + p.getResources().getString(R.string.accel_slow), p.getResources().getString(R.string.accel_medium), - p.getResources().getString(R.string.accel_slow) }; + p.getResources().getString(R.string.accel_fast), + p.getResources().getString(R.string.accel_veryfast) }; AlertDialog.Builder builder = new AlertDialog.Builder(p); builder.setTitle(R.string.pointandclick_relative_speed); @@ -1240,9 +1243,10 @@ class Settings static void showRelativeMouseMovementConfig1(final MainActivity p) { - final CharSequence[] items = { p.getResources().getString(R.string.accel_fast), + final CharSequence[] items = { p.getResources().getString(R.string.none), + p.getResources().getString(R.string.accel_slow), p.getResources().getString(R.string.accel_medium), - p.getResources().getString(R.string.accel_slow) }; + p.getResources().getString(R.string.accel_fast) }; AlertDialog.Builder builder = new AlertDialog.Builder(p); builder.setTitle(R.string.pointandclick_relative_accel); diff --git a/project/java/translations/values/strings.xml b/project/java/translations/values/strings.xml index 0cab65010..2503f2491 100644 --- a/project/java/translations/values/strings.xml +++ b/project/java/translations/values/strings.xml @@ -61,6 +61,7 @@ Fast Medium Slow + Very slow Accelerometer sensitivity Floating diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c index c086f0a55..2966605f2 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c @@ -108,10 +108,13 @@ int mouseInitialY = -1; unsigned int mouseInitialTime = 0; int deferredMouseTap = 0; int relativeMovement = 0; -int relativeMovementSpeed = 0; +int relativeMovementSpeed = 2; int relativeMovementAccel = 0; int relativeMovementX = 0; int relativeMovementY = 0; +unsigned int relativeMovementTime = 0; +int oldMouseX = 0; +int oldMouseY = 0; static inline int InsideRect(const SDL_Rect * r, int x, int y) { @@ -363,17 +366,43 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j if( pointerId == firstMousePointerId ) { - int oldX, oldY; - SDL_GetMouseState( &oldX, &oldY ); if( relativeMovement ) { if( action == MOUSE_DOWN ) { - relativeMovementX = oldX - x; - relativeMovementY = oldY - y; + relativeMovementX = oldMouseX - x; + relativeMovementY = oldMouseY - y; } x += relativeMovementX; y += relativeMovementY; + + int diffX = x - oldMouseX; + int diffY = y - oldMouseY; + int coeff = relativeMovementSpeed + 2; + if( relativeMovementSpeed > 2 ) + coeff += relativeMovementSpeed - 2; + diffX = diffX * coeff / 4; + diffY = diffY * coeff / 4; + if( relativeMovementAccel > 0 ) + { + unsigned int newTime = SDL_GetTicks(); + if( newTime - relativeMovementTime > 0 ) + { + diffX += diffX * ( relativeMovementAccel * 30 ) / (int)(newTime - relativeMovementTime); + diffY += diffY * ( relativeMovementAccel * 30 ) / (int)(newTime - relativeMovementTime); + } + relativeMovementTime = newTime; + } + diffX -= x - oldMouseX; + diffY -= y - oldMouseY; + x += diffX; + y += diffY; + relativeMovementX += diffX; + relativeMovementY += diffY; + __android_log_print(ANDROID_LOG_INFO, "libSDL", "x %d y %d relX %d relY %d diffX %d diffY %d", x, y, relativeMovementX, relativeMovementY, diffX, diffY); + + diffX = x; + diffY = y; if( x < 0 ) x = 0; if( x > SDL_ANDROID_sFakeWindowWidth ) @@ -382,6 +411,8 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j y = 0; if( y > SDL_ANDROID_sFakeWindowHeight ) y = SDL_ANDROID_sFakeWindowHeight; + relativeMovementX += x - diffX; + relativeMovementY += y - diffY; } if( action == MOUSE_UP ) { @@ -423,11 +454,11 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j if( action == MOUSE_DOWN ) { if( (moveMouseWithKbX >= 0 || leftClickMethod == LEFT_CLICK_NEAR_CURSOR) && - abs(oldX - x) < SDL_ANDROID_sFakeWindowWidth / 4 && abs(oldY - y) < SDL_ANDROID_sFakeWindowHeight / 4 ) + abs(oldMouseX - x) < SDL_ANDROID_sFakeWindowWidth / 4 && abs(oldMouseY - y) < SDL_ANDROID_sFakeWindowHeight / 4 ) { SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, SDL_BUTTON_LEFT ); - moveMouseWithKbX = oldX; - moveMouseWithKbY = oldY; + moveMouseWithKbX = oldMouseX; + moveMouseWithKbY = oldMouseX; action == MOUSE_MOVE; } else @@ -688,6 +719,7 @@ JAVA_EXPORT_NAME(Settings_nativeSetMouseUsed) ( JNIEnv* env, jobject thiz, relativeMovement = RelativeMovement; relativeMovementSpeed = RelativeMovementSpeed; relativeMovementAccel = RelativeMovementAccel; + //__android_log_print(ANDROID_LOG_INFO, "libSDL", "relativeMovementSpeed %d relativeMovementAccel %d", relativeMovementSpeed, relativeMovementAccel); } JNIEXPORT void JNICALL @@ -1191,6 +1223,8 @@ extern void SDL_ANDROID_MainThreadPushMouseMotion(int x, int y) ev->type = SDL_MOUSEMOTION; ev->motion.x = x; ev->motion.y = y; + oldMouseX = x; + oldMouseY = y; BufferedEventsEnd = nextEvent; SDL_mutexV(BufferedEventsMutex); @@ -1225,7 +1259,10 @@ extern void SDL_ANDROID_MainThreadPushKeyboardKey(int pressed, SDL_scancode key) key == SDL_KEY(LEFT) || key == SDL_KEY(RIGHT) ) ) { if( moveMouseWithKbX < 0 ) - SDL_GetMouseState( &moveMouseWithKbX, &moveMouseWithKbY ); + { + moveMouseWithKbX = oldMouseX; + moveMouseWithKbY = oldMouseY; + } if( pressed ) {