mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-17 19:34:39 +01:00
Implement full support for mouse input on Android
The smoothing algorithm changed a bit now that I centralized that logic in a way that can work with all backends.
This commit is contained in:
1 parent
904ce4f7e1
commit
db4993bfdc
10 files changed
+120
-64
No files matched your search
@@ -1019,6 +1019,12 @@ public abstract class NativeActivity extends Activity {
|
||||
}
|
||||
|
||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
|
||||
if ((event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
|
||||
float dx = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
|
||||
float dy = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
|
||||
NativeApp.mouseDelta(dx, dy);
|
||||
}
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_HOVER_MOVE:
|
||||
// process the mouse hover movement...
|
||||
|
||||
@@ -50,6 +50,7 @@ public class NativeApp {
|
||||
|
||||
public static native void accelerometer(float x, float y, float z);
|
||||
|
||||
public static native void mouseDelta(float x, float y);
|
||||
public static native void sendMessageFromJava(String msg, String arg);
|
||||
public static native void sendRequestResult(int seqID, boolean result, String value, int iValue);
|
||||
public static native String queryConfig(String queryName);
|
||||
|
||||
@@ -15,6 +15,7 @@ import android.hardware.SensorManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
@@ -23,6 +24,8 @@ import com.bda.controller.ControllerListener;
|
||||
import com.bda.controller.KeyEvent;
|
||||
import com.bda.controller.StateEvent;
|
||||
|
||||
import java.lang.annotation.Native;
|
||||
|
||||
public class NativeSurfaceView extends SurfaceView implements SensorEventListener, ControllerListener {
|
||||
private static String TAG = "NativeSurfaceView";
|
||||
private SensorManager mSensorManager;
|
||||
@@ -58,6 +61,15 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene
|
||||
return ev.getToolType(pointer);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
|
||||
private void processMouseDelta(final MotionEvent ev) {
|
||||
if ((ev.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
|
||||
float dx = ev.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
|
||||
float dy = ev.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
|
||||
NativeApp.mouseDelta(dx, dy);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public boolean onTouchEvent(final MotionEvent ev) {
|
||||
@@ -81,9 +93,13 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene
|
||||
if (ev.getActionIndex() == i)
|
||||
code = 4;
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
case MotionEvent.ACTION_MOVE: {
|
||||
code = 1;
|
||||
if (Build.VERSION.SDK_INT >= 12) {
|
||||
processMouseDelta(ev);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user