|
@@ -401,6 +401,7 @@ public class SDLActivity extends Activity {
|
|
|
public static native void onNativeKeyDown(int keycode);
|
|
|
public static native void onNativeKeyUp(int keycode);
|
|
|
public static native void onNativeKeyboardFocusLost();
|
|
|
+ public static native void onNativeMouse(int button, int action, float x, float y);
|
|
|
public static native void onNativeTouch(int touchDevId, int pointerFingerId,
|
|
|
int action, float x,
|
|
|
float y, float p);
|
|
@@ -1087,8 +1088,8 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
// Dispatch the different events depending on where they come from
|
|
|
// Some SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
|
|
|
// So, we try to process them as DPAD or GAMEPAD events first, if that fails we try them as KEYBOARD
|
|
|
-
|
|
|
- if ( (event.getSource() & 0x00000401) != 0 || /* API 12: SOURCE_GAMEPAD */
|
|
|
+
|
|
|
+ if ( (event.getSource() & InputDevice.SOURCE_GAMEPAD) != 0 ||
|
|
|
(event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) {
|
|
|
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
if (SDLActivity.onNativePadDown(event.getDeviceId(), keyCode) == 0) {
|
|
@@ -1125,50 +1126,58 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
|
final int pointerCount = event.getPointerCount();
|
|
|
int action = event.getActionMasked();
|
|
|
int pointerFingerId;
|
|
|
+ int mouseButton;
|
|
|
int i = -1;
|
|
|
float x,y,p;
|
|
|
-
|
|
|
- switch(action) {
|
|
|
- case MotionEvent.ACTION_MOVE:
|
|
|
- for (i = 0; i < pointerCount; i++) {
|
|
|
+
|
|
|
+ if (event.getSource() == InputDevice.SOURCE_MOUSE &&
|
|
|
+ SDLActivity.nativeGetHint("SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH").equals("1")) {
|
|
|
+ mouseButton = 1; // For Android==12 all mouse buttons are the left button
|
|
|
+
|
|
|
+ SDLActivity.onNativeMouse(mouseButton, action, event.getX(0), event.getY(0));
|
|
|
+ } else {
|
|
|
+ switch(action) {
|
|
|
+ case MotionEvent.ACTION_MOVE:
|
|
|
+ for (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);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case MotionEvent.ACTION_UP:
|
|
|
+ case MotionEvent.ACTION_DOWN:
|
|
|
+ // Primary pointer up/down, the index is always zero
|
|
|
+ i = 0;
|
|
|
+ case MotionEvent.ACTION_POINTER_UP:
|
|
|
+ case MotionEvent.ACTION_POINTER_DOWN:
|
|
|
+ // Non primary pointer up/down
|
|
|
+ if (i == -1) {
|
|
|
+ i = event.getActionIndex();
|
|
|
+ }
|
|
|
+
|
|
|
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);
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case MotionEvent.ACTION_UP:
|
|
|
- case MotionEvent.ACTION_DOWN:
|
|
|
- // Primary pointer up/down, the index is always zero
|
|
|
- i = 0;
|
|
|
- case MotionEvent.ACTION_POINTER_UP:
|
|
|
- case MotionEvent.ACTION_POINTER_DOWN:
|
|
|
- // Non primary pointer up/down
|
|
|
- if (i == -1) {
|
|
|
- i = event.getActionIndex();
|
|
|
- }
|
|
|
+ break;
|
|
|
|
|
|
- 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);
|
|
|
- break;
|
|
|
-
|
|
|
- case MotionEvent.ACTION_CANCEL:
|
|
|
- for (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, MotionEvent.ACTION_UP, x, y, p);
|
|
|
- }
|
|
|
- break;
|
|
|
+ case MotionEvent.ACTION_CANCEL:
|
|
|
+ for (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, MotionEvent.ACTION_UP, x, y, p);
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
- default:
|
|
|
- break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return true;
|
|
@@ -1497,11 +1506,47 @@ class SDLJoystickHandler_API12 extends SDLJoystickHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class SDLGenericMotionListener_API12 implements View.OnGenericMotionListener {
|
|
|
+class SDLGenericMotionListener implements View.OnGenericMotionListener {
|
|
|
// Generic Motion (mouse hover, joystick...) events go here
|
|
|
// We only have joysticks yet
|
|
|
@Override
|
|
|
public boolean onGenericMotion(View v, MotionEvent event) {
|
|
|
- return SDLActivity.handleJoystickMotionEvent(event);
|
|
|
+ float x, y;
|
|
|
+ int mouseButton;
|
|
|
+ int action;
|
|
|
+
|
|
|
+ switch ( event.getSource() ) {
|
|
|
+ case InputDevice.SOURCE_JOYSTICK:
|
|
|
+ case InputDevice.SOURCE_GAMEPAD:
|
|
|
+ case InputDevice.SOURCE_DPAD:
|
|
|
+ SDLActivity.handleJoystickMotionEvent(event);
|
|
|
+ return true;
|
|
|
+
|
|
|
+ case InputDevice.SOURCE_MOUSE:
|
|
|
+ action = event.getActionMasked();
|
|
|
+ switch(event.getActionMasked()) {
|
|
|
+ case MotionEvent.ACTION_SCROLL:
|
|
|
+ x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
|
|
|
+ y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
|
|
|
+ SDLActivity.onNativeMouse(0, action, x, y);
|
|
|
+ return true;
|
|
|
+
|
|
|
+ case MotionEvent.ACTION_HOVER_MOVE:
|
|
|
+ x = event.getX(0);
|
|
|
+ y = event.getY(0);
|
|
|
+
|
|
|
+ SDLActivity.onNativeMouse(0, action, x, y);
|
|
|
+ return true;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Event was not managed
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|