diff -r 9935f71c8c81 android-project/src/org/libsdl/app/SDLActivity.java --- a/android-project/src/org/libsdl/app/SDLActivity.java Sat Dec 15 21:50:17 2012 -0800 +++ b/android-project/src/org/libsdl/app/SDLActivity.java Sun Dec 16 18:45:57 2012 +0100 @@ -161,6 +161,7 @@ public static native void onNativeTouch(int touchDevId, int pointerFingerId, int action, float x, float y, float p); + public static native void onNativeMouse(int action, float x, float y); public static native void onNativeAccel(float x, float y, float z); public static native void nativeRunAudioThread(); @@ -621,18 +622,34 @@ float y = event.getY(actionPointerIndex) / mHeight; float p = event.getPressure(actionPointerIndex); - if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) { - // TODO send motion to every pointer if its position has - // changed since prev event. - for (int i = 0; i < pointerCount; i++) { - pointerFingerId = event.getPointerId(i); - x = event.getX(i) / mWidth; - y = event.getY(i) / mHeight; - p = event.getPressure(i); - SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); - } - } else { - SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); + // Dispatch the different events depending on how they come from + switch ( event.getSource() ) { + case InputDevice.SOURCE_TOUCHPAD: + case InputDevice.SOURCE_TOUCHSCREEN: + final int touchDevId = event.getDeviceId(); + final int pointerCount = event.getPointerCount(); + // touchId, pointerId, action, x, y, pressure + int pointerFingerId = event.getPointerId(actionPointerIndex); + + float p = event.getPressure(actionPointerIndex); + + if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) { + // TODO send motion to every pointer if its position has + // changed since prev event. + for (int i = 0; i < pointerCount; i++) { + pointerFingerId = event.getPointerId(i); + x = event.getX(i) / mWidth; + y = event.getY(i) / mHeight; + p = event.getPressure(i); + SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); + } + } else { + SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); + } + break; + case InputDevice.SOURCE_MOUSE: + SDLActivity.onNativeMouse(action, x, y); + break; } } return true; diff -r 9935f71c8c81 src/core/android/SDL_android.cpp --- a/src/core/android/SDL_android.cpp Sat Dec 15 21:50:17 2012 -0800 +++ b/src/core/android/SDL_android.cpp Sun Dec 16 18:45:57 2012 +0100 @@ -167,6 +167,14 @@ Android_OnTouch(touch_device_id_in, pointer_finger_id_in, action, x, y, p); } +// Mouse +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeMouse( + JNIEnv* env, jclass jcls, + jint action, jfloat x, jfloat y) +{ + Android_OnMouse(action, x, y); +} + // Accelerometer extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel( JNIEnv* env, jclass jcls, diff -r 9935f71c8c81 src/video/android/SDL_androidmouse.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/android/SDL_androidmouse.c Sun Dec 16 18:45:57 2012 +0100 @@ -0,0 +1,74 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "SDL_config.h" + +#if SDL_VIDEO_DRIVER_ANDROID + +#include + +#include "SDL_events.h" +#include "../../events/SDL_mouse_c.h" + +#include "SDL_androidmouse.h" + +#define ACTION_DOWN 0 +#define ACTION_UP 1 +#define ACTION_MOVE 2 + +static void Android_GetWindowCoordinates(float x, float y, + int *window_x, int *window_y) +{ + int window_w, window_h; + + SDL_GetWindowSize(Android_Window, &window_w, &window_h); + *window_x = (int)(x * window_w); + *window_y = (int)(y * window_h); +} + +void Android_OnMouse(int action, float x, float y) +{ + int window_x, window_y; + + if (!Android_Window) { + return; + } + + switch (action) { + case ACTION_DOWN: + Android_GetWindowCoordinates(x, y, &window_x, &window_y); + SDL_Log("Mouse down @ %fx%f", window_x, window_y); + SDL_SendMouseMotion(NULL, 0, window_x, window_y); + SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); + break; + case ACTION_MOVE: + Android_GetWindowCoordinates(x, y, &window_x, &window_y); + + SDL_SendMouseMotion(NULL, 0, window_x, window_y); + break; + case ACTION_UP: + SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); + break; + } +} + +#endif /* SDL_VIDEO_DRIVER_ANDROID */ + +/* vi: set ts=4 sw=4 expandtab: */ diff -r 9935f71c8c81 src/video/android/SDL_androidmouse.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/android/SDL_androidmouse.h Sun Dec 16 18:45:57 2012 +0100 @@ -0,0 +1,27 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "SDL_config.h" + +#include "SDL_androidvideo.h" + +extern void Android_OnMouse( int action, float x, float y ); + +/* vi: set ts=4 sw=4 expandtab: */