|
@@ -79,11 +79,24 @@ public class SDLActivity extends Activity {
|
|
protected static SDLClipboardHandler mClipboardHandler;
|
|
protected static SDLClipboardHandler mClipboardHandler;
|
|
protected static Hashtable<Integer, Object> mCursors;
|
|
protected static Hashtable<Integer, Object> mCursors;
|
|
protected static int mLastCursorID;
|
|
protected static int mLastCursorID;
|
|
|
|
+ protected static SDLGenericMotionListener_API12 mMotionListener;
|
|
|
|
|
|
|
|
|
|
// This is what SDL runs in. It invokes SDL_main(), eventually
|
|
// This is what SDL runs in. It invokes SDL_main(), eventually
|
|
protected static Thread mSDLThread;
|
|
protected static Thread mSDLThread;
|
|
|
|
|
|
|
|
+ protected static SDLGenericMotionListener_API12 getMotionListener() {
|
|
|
|
+ if (mMotionListener == null) {
|
|
|
|
+ if (Build.VERSION.SDK_INT >= 24) {
|
|
|
|
+ mMotionListener = new SDLGenericMotionListener_API24();
|
|
|
|
+ } else {
|
|
|
|
+ mMotionListener = new SDLGenericMotionListener_API12();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return mMotionListener;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* This method returns the name of the shared object with the application entry point
|
|
* This method returns the name of the shared object with the application entry point
|
|
* It can be overridden by derived classes.
|
|
* It can be overridden by derived classes.
|
|
@@ -543,7 +556,7 @@ public class SDLActivity extends Activity {
|
|
public static native void onNativeKeyDown(int keycode);
|
|
public static native void onNativeKeyDown(int keycode);
|
|
public static native void onNativeKeyUp(int keycode);
|
|
public static native void onNativeKeyUp(int keycode);
|
|
public static native void onNativeKeyboardFocusLost();
|
|
public static native void onNativeKeyboardFocusLost();
|
|
- public static native void onNativeMouse(int button, int action, float x, float y);
|
|
|
|
|
|
+ public static native void onNativeMouse(int button, int action, float x, float y, boolean relative);
|
|
public static native void onNativeTouch(int touchDevId, int pointerFingerId,
|
|
public static native void onNativeTouch(int touchDevId, int pointerFingerId,
|
|
int action, float x,
|
|
int action, float x,
|
|
float y, float p);
|
|
float y, float p);
|
|
@@ -641,6 +654,22 @@ public class SDLActivity extends Activity {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * This method is called by SDL using JNI.
|
|
|
|
+ */
|
|
|
|
+ public static boolean supportsRelativeMouse()
|
|
|
|
+ {
|
|
|
|
+ return SDLActivity.getMotionListener().supportsRelativeMouse();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * This method is called by SDL using JNI.
|
|
|
|
+ */
|
|
|
|
+ public static boolean setRelativeMouseEnabled(boolean enabled)
|
|
|
|
+ {
|
|
|
|
+ return SDLActivity.getMotionListener().setRelativeMouseEnabled(enabled);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* This method is called by SDL using JNI.
|
|
* This method is called by SDL using JNI.
|
|
*/
|
|
*/
|
|
@@ -1231,7 +1260,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
|
|
mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 12) {
|
|
if (Build.VERSION.SDK_INT >= 12) {
|
|
- setOnGenericMotionListener(new SDLGenericMotionListener_API12());
|
|
|
|
|
|
+ setOnGenericMotionListener(SDLActivity.getMotionListener());
|
|
}
|
|
}
|
|
|
|
|
|
// Some arbitrary defaults to avoid a potential division by zero
|
|
// Some arbitrary defaults to avoid a potential division by zero
|
|
@@ -1456,7 +1485,14 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|
mouseButton = 1; // oh well.
|
|
mouseButton = 1; // oh well.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- SDLActivity.onNativeMouse(mouseButton, action, event.getX(0), event.getY(0));
|
|
|
|
|
|
+
|
|
|
|
+ // We need to check if we're in relative mouse mode and get the axis offset rather than the x/y values
|
|
|
|
+ // if we are. We'll leverage our existing mouse motion listener
|
|
|
|
+ SDLGenericMotionListener_API12 motionListener = SDLActivity.getMotionListener();
|
|
|
|
+ x = motionListener.getEventX(event);
|
|
|
|
+ y = motionListener.getEventY(event);
|
|
|
|
+
|
|
|
|
+ SDLActivity.onNativeMouse(mouseButton, action, x, y, motionListener.inRelativeMode());
|
|
} else {
|
|
} else {
|
|
switch(action) {
|
|
switch(action) {
|
|
case MotionEvent.ACTION_MOVE:
|
|
case MotionEvent.ACTION_MOVE:
|