diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index ceb4eddbf..65a249eac 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -1,4 +1,4 @@ -/* +/* OF Simple DirectMedia Layer Java source code (C) 2009-2011 Sergii Pylypenko @@ -391,9 +391,14 @@ public class MainActivity extends Activity { } @Override - public boolean dispatchGenericMotionEvent (final MotionEvent ev) + public boolean dispatchGenericMotionEvent (MotionEvent ev) { - return dispatchTouchEvent(ev); + if(_screenKeyboard != null) + _screenKeyboard.dispatchGenericMotionEvent(ev); + else + if(mGLView != null) + mGLView.onGenericMotionEvent(ev); + return true; } @Override diff --git a/project/java/Video.java b/project/java/Video.java index 0f5b53867..9f769fc2d 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -1,4 +1,4 @@ -/* +/*ACTION_HOVER_MOVE Simple DirectMedia Layer Java source code (C) 2009-2011 Sergii Pylypenko @@ -77,6 +77,7 @@ class Mouse public static final int SDL_FINGER_DOWN = 0; public static final int SDL_FINGER_UP = 1; public static final int SDL_FINGER_MOVE = 2; + public static final int SDL_FINGER_HOVER = 3; } @@ -231,12 +232,10 @@ abstract class DifferentTouchInput if( event.getAction() == MotionEvent.ACTION_HOVER_MOVE ) // Support bluetooth/USB mouse - available since Android 3.1 { // TODO: it is possible that multiple pointers return that event, but we're handling only pointer #0 - // TODO: need to check this on a device, the emulator does not return such event if( touchEvents[0].down ) action = Mouse.SDL_FINGER_UP; else - action = Mouse.SDL_FINGER_MOVE; - action = 2; + action = Mouse.SDL_FINGER_HOVER; touchEvents[0].down = false; touchEvents[0].x = (int)event.getX(); touchEvents[0].y = (int)event.getY(); @@ -256,6 +255,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer context = _context; // Froyo does not flood touch events, and syncs to the screen update, // so we should not use event rate limiter, or we'll get some multitouch events largely outdated + // Another test on Tegra development board shows that with USB mouse FPS drops in half + // when mouse is moved, with and without ratelimiter if( android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO ) mRatelimitTouchEvents = true; System.out.println("libSDL: DemoRenderer: RatelimitTouchEvents " + mRatelimitTouchEvents ); @@ -474,7 +475,9 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { { touchInput.process(event); // Wait a bit, and try to synchronize to app framerate, or event thread will eat all CPU and we'll lose FPS - if( event.getAction() == MotionEvent.ACTION_MOVE && mRenderer.mRatelimitTouchEvents ) + if(( event.getAction() == MotionEvent.ACTION_MOVE || + event.getAction() == MotionEvent.ACTION_HOVER_MOVE) && + mRenderer.mRatelimitTouchEvents ) { synchronized(mRenderer) { diff --git a/project/jni/application/ballfield/AndroidAppSettings.cfg b/project/jni/application/ballfield/AndroidAppSettings.cfg index 509689911..e70bbecb6 100644 --- a/project/jni/application/ballfield/AndroidAppSettings.cfg +++ b/project/jni/application/ballfield/AndroidAppSettings.cfg @@ -14,13 +14,13 @@ SwVideoMode=y SdlVideoResize=y SdlVideoResizeKeepAspect=n CompatibilityHacks=n -AppUsesMouse=n -AppNeedsTwoButtonMouse=n +AppUsesMouse=y +AppNeedsTwoButtonMouse=y AppNeedsArrowKeys=n -AppNeedsTextInput=y +AppNeedsTextInput=n AppUsesJoystick=n AppHandlesJoystickSensitivity=n -AppUsesMultitouch=y +AppUsesMultitouch=n NonBlockingSwapBuffers=y RedefinedKeys="SPACE" AppTouchscreenKeyboardKeysAmount=0 diff --git a/project/jni/application/ballfield/ballfield.cpp b/project/jni/application/ballfield/ballfield.cpp index 7907aa251..438589fc1 100644 --- a/project/jni/application/ballfield/ballfield.cpp +++ b/project/jni/application/ballfield/ballfield.cpp @@ -510,7 +510,26 @@ int main(int argc, char* argv[]) color = 0xff; color = color + color * 0x100 + color * 0x10000; SDL_FillRect(screen, &r, color); + print_num(screen, font, r.x, r.y, i+1); } + int mx, my; + int b = SDL_GetMouseState(&mx, &my); + Uint32 color = 0xff; + if( b ) + { + color = 0; + if( b & SDL_BUTTON_LEFT ) + color |= 0xff00; + if( b & SDL_BUTTON_RIGHT ) + color |= 0xff0000; + } + r.x = mx; + r.y = my; + r.w = 30; + r.h = 30; + r.x -= r.w/2; + r.y -= r.h/2; + SDL_FillRect(screen, &r, color); SDL_Flip(SDL_GetVideoSurface()); SDL_Event evt; 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 e78459c04..e1d6b7ab5 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 @@ -57,7 +57,8 @@ static inline SDL_scancode TranslateKey(int scancode) static int isTrackballUsed = 0; static int isMouseUsed = 0; -enum { RIGHT_CLICK_NONE = 0, RIGHT_CLICK_WITH_MULTITOUCH = 1, RIGHT_CLICK_WITH_PRESSURE = 2, RIGHT_CLICK_WITH_KEY = 3, RIGHT_CLICK_WITH_TIMEOUT = 4 }; +enum { RIGHT_CLICK_NONE = 0, RIGHT_CLICK_WITH_MULTITOUCH = 1, RIGHT_CLICK_WITH_PRESSURE = 2, + RIGHT_CLICK_WITH_KEY = 3, RIGHT_CLICK_WITH_TIMEOUT = 4 }; enum { LEFT_CLICK_NORMAL = 0, LEFT_CLICK_NEAR_CURSOR = 1, LEFT_CLICK_WITH_MULTITOUCH = 2, LEFT_CLICK_WITH_PRESSURE = 3, LEFT_CLICK_WITH_KEY = 4, LEFT_CLICK_WITH_TIMEOUT = 5, LEFT_CLICK_WITH_TAP = 6, LEFT_CLICK_WITH_TAP_OR_TIMEOUT = 7 }; static int leftClickMethod = LEFT_CLICK_NORMAL; @@ -491,8 +492,10 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j { SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, SDL_BUTTON_LEFT ); moveMouseWithKbX = oldMouseX; - moveMouseWithKbY = oldMouseX; - action == MOUSE_MOVE; + moveMouseWithKbY = oldMouseY; + moveMouseWithKbSpeedX = 0; + moveMouseWithKbSpeedY = 0; + action = MOUSE_MOVE; } else if( leftClickMethod == LEFT_CLICK_NORMAL ) @@ -539,7 +542,9 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j SDL_ANDROID_MainThreadPushMouseMotion(moveMouseWithKbX, moveMouseWithKbY); } else + { SDL_ANDROID_MainThreadPushMouseMotion(x, y); + } if( rightClickMethod == RIGHT_CLICK_WITH_PRESSURE || leftClickMethod == LEFT_CLICK_WITH_PRESSURE ) { @@ -611,6 +616,11 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j } } } + + if( action == MOUSE_HOVER && !relativeMovement ) + { + SDL_ANDROID_MainThreadPushMouseMotion(x, y); + } } void ProcessDeferredMouseTap() diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.h b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.h index b4b561462..9bb0c54af 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.h +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.h @@ -115,7 +115,7 @@ typedef SDLKey SDL_scancode; #define SDL_KEY_VAL(X) X -enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP=1, MOUSE_MOVE=2 }; +enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP = 1, MOUSE_MOVE = 2, MOUSE_HOVER = 3 }; extern int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId); extern int SDL_ANDROID_isTouchscreenKeyboardUsed;