Refactor Android input handling and add pen support
This commit is contained in:
@@ -223,7 +223,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||||||
protected static SDLClipboardHandler mClipboardHandler;
|
protected static SDLClipboardHandler mClipboardHandler;
|
||||||
protected static Hashtable<Integer, PointerIcon> mCursors;
|
protected static Hashtable<Integer, PointerIcon> mCursors;
|
||||||
protected static int mLastCursorID;
|
protected static int mLastCursorID;
|
||||||
protected static SDLGenericMotionListener_API12 mMotionListener;
|
protected static SDLGenericMotionListener_API14 mMotionListener;
|
||||||
protected static HIDDeviceManager mHIDDeviceManager;
|
protected static HIDDeviceManager mHIDDeviceManager;
|
||||||
|
|
||||||
// This is what SDL runs in. It invokes SDL_main(), eventually
|
// This is what SDL runs in. It invokes SDL_main(), eventually
|
||||||
@@ -232,14 +232,14 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||||||
protected static boolean mActivityCreated = false;
|
protected static boolean mActivityCreated = false;
|
||||||
private static SDLFileDialogState mFileDialogState = null;
|
private static SDLFileDialogState mFileDialogState = null;
|
||||||
|
|
||||||
protected static SDLGenericMotionListener_API12 getMotionListener() {
|
protected static SDLGenericMotionListener_API14 getMotionListener() {
|
||||||
if (mMotionListener == null) {
|
if (mMotionListener == null) {
|
||||||
if (Build.VERSION.SDK_INT >= 26 /* Android 8.0 (O) */) {
|
if (Build.VERSION.SDK_INT >= 26 /* Android 8.0 (O) */) {
|
||||||
mMotionListener = new SDLGenericMotionListener_API26();
|
mMotionListener = new SDLGenericMotionListener_API26();
|
||||||
} else if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
|
} else if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
|
||||||
mMotionListener = new SDLGenericMotionListener_API24();
|
mMotionListener = new SDLGenericMotionListener_API24();
|
||||||
} else {
|
} else {
|
||||||
mMotionListener = new SDLGenericMotionListener_API12();
|
mMotionListener = new SDLGenericMotionListener_API14();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -662,44 +662,61 @@ class SDLHapticHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SDLGenericMotionListener_API12 implements View.OnGenericMotionListener {
|
class SDLGenericMotionListener_API14 implements View.OnGenericMotionListener {
|
||||||
// Generic Motion (mouse hover, joystick...) events go here
|
// Generic Motion (mouse hover, joystick...) events go here
|
||||||
@Override
|
@Override
|
||||||
public boolean onGenericMotion(View v, MotionEvent event) {
|
public boolean onGenericMotion(View v, MotionEvent event) {
|
||||||
float x, y;
|
if (event.getSource() == InputDevice.SOURCE_JOYSTICK)
|
||||||
int action;
|
|
||||||
|
|
||||||
switch ( event.getSource() ) {
|
|
||||||
case InputDevice.SOURCE_JOYSTICK:
|
|
||||||
return SDLControllerManager.handleJoystickMotionEvent(event);
|
return SDLControllerManager.handleJoystickMotionEvent(event);
|
||||||
|
|
||||||
case InputDevice.SOURCE_MOUSE:
|
float x, y;
|
||||||
action = event.getActionMasked();
|
int action = event.getActionMasked();
|
||||||
|
int pointerCount = event.getPointerCount();
|
||||||
|
boolean consumed = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < pointerCount; i++) {
|
||||||
|
int toolType = event.getToolType(i);
|
||||||
|
|
||||||
|
if (toolType == MotionEvent.TOOL_TYPE_MOUSE) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MotionEvent.ACTION_SCROLL:
|
case MotionEvent.ACTION_SCROLL:
|
||||||
x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
|
x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, i);
|
||||||
y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
|
y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, i);
|
||||||
SDLActivity.onNativeMouse(0, action, x, y, false);
|
SDLActivity.onNativeMouse(0, action, x, y, false);
|
||||||
return true;
|
consumed = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_HOVER_MOVE:
|
case MotionEvent.ACTION_HOVER_MOVE:
|
||||||
x = event.getX(0);
|
x = getEventX(event, i);
|
||||||
y = event.getY(0);
|
y = getEventY(event, i);
|
||||||
|
|
||||||
SDLActivity.onNativeMouse(0, action, x, y, false);
|
SDLActivity.onNativeMouse(0, action, x, y, checkRelativeEvent(event));
|
||||||
return true;
|
consumed = true;
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (toolType == MotionEvent.TOOL_TYPE_STYLUS || toolType == MotionEvent.TOOL_TYPE_ERASER) {
|
||||||
|
switch (action) {
|
||||||
|
case MotionEvent.ACTION_HOVER_ENTER:
|
||||||
|
case MotionEvent.ACTION_HOVER_MOVE:
|
||||||
|
case MotionEvent.ACTION_HOVER_EXIT:
|
||||||
|
x = event.getX(i);
|
||||||
|
y = event.getY(i);
|
||||||
|
float p = event.getPressure(i);
|
||||||
|
|
||||||
// Event was not managed
|
// BUTTON_STYLUS_PRIMARY is 2^5, so shift by 4
|
||||||
return false;
|
int buttons = event.getButtonState() >> 4;
|
||||||
|
|
||||||
|
SDLActivity.onNativePen(event.getPointerId(i), buttons, action, x, y, p);
|
||||||
|
consumed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsRelativeMouse() {
|
public boolean supportsRelativeMouse() {
|
||||||
@@ -714,46 +731,29 @@ class SDLGenericMotionListener_API12 implements View.OnGenericMotionListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reclaimRelativeMouseModeIfNeeded()
|
public void reclaimRelativeMouseModeIfNeeded() {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getEventX(MotionEvent event) {
|
public boolean checkRelativeEvent(MotionEvent event) {
|
||||||
return event.getX(0);
|
return inRelativeMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getEventY(MotionEvent event) {
|
public float getEventX(MotionEvent event, int pointerIndex) {
|
||||||
return event.getY(0);
|
return event.getX(pointerIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getEventY(MotionEvent event, int pointerIndex) {
|
||||||
|
return event.getY(pointerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SDLGenericMotionListener_API24 extends SDLGenericMotionListener_API12 {
|
class SDLGenericMotionListener_API24 extends SDLGenericMotionListener_API14 {
|
||||||
// Generic Motion (mouse hover, joystick...) events go here
|
// Generic Motion (mouse hover, joystick...) events go here
|
||||||
|
|
||||||
private boolean mRelativeModeEnabled;
|
private boolean mRelativeModeEnabled;
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onGenericMotion(View v, MotionEvent event) {
|
|
||||||
|
|
||||||
// Handle relative mouse mode
|
|
||||||
if (mRelativeModeEnabled) {
|
|
||||||
if (event.getSource() == InputDevice.SOURCE_MOUSE) {
|
|
||||||
int action = event.getActionMasked();
|
|
||||||
if (action == MotionEvent.ACTION_HOVER_MOVE) {
|
|
||||||
float x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
|
|
||||||
float y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
|
|
||||||
SDLActivity.onNativeMouse(0, action, x, y, true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Event was not managed, call SDLGenericMotionListener_API12 method
|
|
||||||
return super.onGenericMotion(v, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsRelativeMouse() {
|
public boolean supportsRelativeMouse() {
|
||||||
return true;
|
return true;
|
||||||
@@ -771,20 +771,20 @@ class SDLGenericMotionListener_API24 extends SDLGenericMotionListener_API12 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getEventX(MotionEvent event) {
|
public float getEventX(MotionEvent event, int pointerIndex) {
|
||||||
if (mRelativeModeEnabled) {
|
if (mRelativeModeEnabled && event.getToolType(pointerIndex) == MotionEvent.TOOL_TYPE_MOUSE) {
|
||||||
return event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
|
return event.getAxisValue(MotionEvent.AXIS_RELATIVE_X, pointerIndex);
|
||||||
} else {
|
} else {
|
||||||
return event.getX(0);
|
return event.getX(pointerIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getEventY(MotionEvent event) {
|
public float getEventY(MotionEvent event, int pointerIndex) {
|
||||||
if (mRelativeModeEnabled) {
|
if (mRelativeModeEnabled && event.getToolType(pointerIndex) == MotionEvent.TOOL_TYPE_MOUSE) {
|
||||||
return event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
|
return event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y, pointerIndex);
|
||||||
} else {
|
} else {
|
||||||
return event.getY(0);
|
return event.getY(pointerIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -793,65 +793,6 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
|
|||||||
// Generic Motion (mouse hover, joystick...) events go here
|
// Generic Motion (mouse hover, joystick...) events go here
|
||||||
private boolean mRelativeModeEnabled;
|
private boolean mRelativeModeEnabled;
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onGenericMotion(View v, MotionEvent event) {
|
|
||||||
float x, y;
|
|
||||||
int action;
|
|
||||||
|
|
||||||
switch ( event.getSource() ) {
|
|
||||||
case InputDevice.SOURCE_JOYSTICK:
|
|
||||||
return SDLControllerManager.handleJoystickMotionEvent(event);
|
|
||||||
|
|
||||||
case InputDevice.SOURCE_MOUSE:
|
|
||||||
// DeX desktop mouse cursor is a separate non-standard input type.
|
|
||||||
case InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN:
|
|
||||||
action = event.getActionMasked();
|
|
||||||
switch (action) {
|
|
||||||
case MotionEvent.ACTION_SCROLL:
|
|
||||||
x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
|
|
||||||
y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
|
|
||||||
SDLActivity.onNativeMouse(0, action, x, y, false);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_HOVER_MOVE:
|
|
||||||
x = event.getX(0);
|
|
||||||
y = event.getY(0);
|
|
||||||
SDLActivity.onNativeMouse(0, action, x, y, false);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InputDevice.SOURCE_MOUSE_RELATIVE:
|
|
||||||
action = event.getActionMasked();
|
|
||||||
switch (action) {
|
|
||||||
case MotionEvent.ACTION_SCROLL:
|
|
||||||
x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
|
|
||||||
y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
|
|
||||||
SDLActivity.onNativeMouse(0, action, x, y, false);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_HOVER_MOVE:
|
|
||||||
x = event.getX(0);
|
|
||||||
y = event.getY(0);
|
|
||||||
SDLActivity.onNativeMouse(0, action, x, y, true);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Event was not managed
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsRelativeMouse() {
|
public boolean supportsRelativeMouse() {
|
||||||
return (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */);
|
return (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */);
|
||||||
@@ -878,22 +819,26 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reclaimRelativeMouseModeIfNeeded()
|
public void reclaimRelativeMouseModeIfNeeded() {
|
||||||
{
|
|
||||||
if (mRelativeModeEnabled && !SDLActivity.isDeXMode()) {
|
if (mRelativeModeEnabled && !SDLActivity.isDeXMode()) {
|
||||||
SDLActivity.getContentView().requestPointerCapture();
|
SDLActivity.getContentView().requestPointerCapture();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getEventX(MotionEvent event) {
|
public boolean checkRelativeEvent(MotionEvent event) {
|
||||||
// Relative mouse in capture mode will only have relative for X/Y
|
return event.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE;
|
||||||
return event.getX(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getEventY(MotionEvent event) {
|
public float getEventX(MotionEvent event, int pointerIndex) {
|
||||||
// Relative mouse in capture mode will only have relative for X/Y
|
// Relative mouse in capture mode will only have relative for X/Y
|
||||||
return event.getY(0);
|
return event.getX(pointerIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getEventY(MotionEvent event, int pointerIndex) {
|
||||||
|
// Relative mouse in capture mode will only have relative for X/Y
|
||||||
|
return event.getY(pointerIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,35 +239,45 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
int touchDevId = event.getDeviceId();
|
int touchDevId = event.getDeviceId();
|
||||||
final int pointerCount = event.getPointerCount();
|
final int pointerCount = event.getPointerCount();
|
||||||
int action = event.getActionMasked();
|
int action = event.getActionMasked();
|
||||||
int pointerFingerId;
|
int pointerId;
|
||||||
int i = -1;
|
int i = 0;
|
||||||
float x,y,p;
|
float x,y,p;
|
||||||
|
|
||||||
// 12290 = Samsung DeX mode desktop mouse
|
if (action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_POINTER_DOWN)
|
||||||
// 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN
|
i = event.getActionIndex();
|
||||||
// 0x2 = SOURCE_CLASS_POINTER
|
|
||||||
if (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN)) {
|
do {
|
||||||
int mouseButton = 1;
|
int toolType = event.getToolType(i);
|
||||||
try {
|
|
||||||
Object object = event.getClass().getMethod("getButtonState").invoke(event);
|
if (toolType == MotionEvent.TOOL_TYPE_MOUSE) {
|
||||||
if (object != null) {
|
int buttonState = event.getButtonState();
|
||||||
mouseButton = (Integer) object;
|
boolean relative = false;
|
||||||
}
|
|
||||||
} catch(Exception ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to check if we're in relative mouse mode and get the axis offset rather than the x/y values
|
// 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
|
// if we are. We'll leverage our existing mouse motion listener
|
||||||
SDLGenericMotionListener_API12 motionListener = SDLActivity.getMotionListener();
|
SDLGenericMotionListener_API14 motionListener = SDLActivity.getMotionListener();
|
||||||
x = motionListener.getEventX(event);
|
x = motionListener.getEventX(event, i);
|
||||||
y = motionListener.getEventY(event);
|
y = motionListener.getEventY(event, i);
|
||||||
|
relative = motionListener.inRelativeMode();
|
||||||
|
|
||||||
SDLActivity.onNativeMouse(mouseButton, action, x, y, motionListener.inRelativeMode());
|
SDLActivity.onNativeMouse(buttonState, action, x, y, relative);
|
||||||
} else {
|
} else if (toolType == MotionEvent.TOOL_TYPE_STYLUS || toolType == MotionEvent.TOOL_TYPE_ERASER) {
|
||||||
switch(action) {
|
pointerId = event.getPointerId(i);
|
||||||
case MotionEvent.ACTION_MOVE:
|
x = event.getX(i);
|
||||||
for (i = 0; i < pointerCount; i++) {
|
y = event.getY(i);
|
||||||
pointerFingerId = event.getPointerId(i);
|
p = event.getPressure(i);
|
||||||
|
if (p > 1.0f) {
|
||||||
|
// may be larger than 1.0f on some devices
|
||||||
|
// see the documentation of getPressure(i)
|
||||||
|
p = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// BUTTON_STYLUS_PRIMARY is 2^5, so shift by 4, and apply SDL_PEN_INPUT_DOWN/SDL_PEN_INPUT_ERASER_TIP
|
||||||
|
int buttonState = (event.getButtonState() >> 4) | (1 << (toolType == MotionEvent.TOOL_TYPE_STYLUS ? 0 : 30));
|
||||||
|
|
||||||
|
SDLActivity.onNativePen(pointerId, buttonState, action, x, y, p);
|
||||||
|
} else if (toolType == MotionEvent.TOOL_TYPE_FINGER) {
|
||||||
|
pointerId = event.getPointerId(i);
|
||||||
x = getNormalizedX(event.getX(i));
|
x = getNormalizedX(event.getX(i));
|
||||||
y = getNormalizedY(event.getY(i));
|
y = getNormalizedY(event.getY(i));
|
||||||
p = event.getPressure(i);
|
p = event.getPressure(i);
|
||||||
@@ -276,53 +286,15 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
// see the documentation of getPressure(i)
|
// see the documentation of getPressure(i)
|
||||||
p = 1.0f;
|
p = 1.0f;
|
||||||
}
|
}
|
||||||
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_UP:
|
SDLActivity.onNativeTouch(touchDevId, pointerId,
|
||||||
case MotionEvent.ACTION_DOWN:
|
action == MotionEvent.ACTION_CANCEL ? MotionEvent.ACTION_UP : action, x, y, p);
|
||||||
// Primary pointer up/down, the index is always zero
|
|
||||||
i = 0;
|
|
||||||
/* fallthrough */
|
|
||||||
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);
|
// Non-primary up/down
|
||||||
x = getNormalizedX(event.getX(i));
|
if (action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_POINTER_DOWN)
|
||||||
y = getNormalizedY(event.getY(i));
|
|
||||||
p = event.getPressure(i);
|
|
||||||
if (p > 1.0f) {
|
|
||||||
// may be larger than 1.0f on some devices
|
|
||||||
// see the documentation of getPressure(i)
|
|
||||||
p = 1.0f;
|
|
||||||
}
|
|
||||||
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
|
|
||||||
break;
|
break;
|
||||||
|
} while (++i < pointerCount);
|
||||||
case MotionEvent.ACTION_CANCEL:
|
|
||||||
for (i = 0; i < pointerCount; i++) {
|
|
||||||
pointerFingerId = event.getPointerId(i);
|
|
||||||
x = getNormalizedX(event.getX(i));
|
|
||||||
y = getNormalizedY(event.getY(i));
|
|
||||||
p = event.getPressure(i);
|
|
||||||
if (p > 1.0f) {
|
|
||||||
// may be larger than 1.0f on some devices
|
|
||||||
// see the documentation of getPressure(i)
|
|
||||||
p = 1.0f;
|
|
||||||
}
|
|
||||||
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -395,19 +367,21 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
public boolean onCapturedPointerEvent(MotionEvent event)
|
public boolean onCapturedPointerEvent(MotionEvent event)
|
||||||
{
|
{
|
||||||
int action = event.getActionMasked();
|
int action = event.getActionMasked();
|
||||||
|
int pointerCount = event.getPointerCount();
|
||||||
|
|
||||||
|
for (int i = 0; i < pointerCount; i++) {
|
||||||
float x, y;
|
float x, y;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MotionEvent.ACTION_SCROLL:
|
case MotionEvent.ACTION_SCROLL:
|
||||||
x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
|
x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, i);
|
||||||
y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
|
y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, i);
|
||||||
SDLActivity.onNativeMouse(0, action, x, y, false);
|
SDLActivity.onNativeMouse(0, action, x, y, false);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case MotionEvent.ACTION_HOVER_MOVE:
|
case MotionEvent.ACTION_HOVER_MOVE:
|
||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE:
|
||||||
x = event.getX(0);
|
x = event.getX(i);
|
||||||
y = event.getY(0);
|
y = event.getY(i);
|
||||||
SDLActivity.onNativeMouse(0, action, x, y, true);
|
SDLActivity.onNativeMouse(0, action, x, y, true);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -421,13 +395,14 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
action = MotionEvent.ACTION_UP;
|
action = MotionEvent.ACTION_UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = event.getX(0);
|
x = event.getX(i);
|
||||||
y = event.getY(0);
|
y = event.getY(i);
|
||||||
int button = event.getButtonState();
|
int button = event.getButtonState();
|
||||||
|
|
||||||
SDLActivity.onNativeMouse(button, action, x, y, true);
|
SDLActivity.onNativeMouse(button, action, x, y, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#define ACTION_DOWN 0
|
#define ACTION_DOWN 0
|
||||||
#define ACTION_UP 1
|
#define ACTION_UP 1
|
||||||
|
#define ACTION_CANCEL 3
|
||||||
#define ACTION_POINTER_DOWN 5
|
#define ACTION_POINTER_DOWN 5
|
||||||
#define ACTION_POINTER_UP 6
|
#define ACTION_POINTER_UP 6
|
||||||
#define ACTION_HOVER_EXIT 10
|
#define ACTION_HOVER_EXIT 10
|
||||||
@@ -56,11 +57,6 @@ void Android_OnPen(SDL_Window *window, int pen_id_in, int button, int action, fl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == ACTION_HOVER_EXIT) {
|
|
||||||
SDL_RemovePenDevice(0, pen);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_SendPenMotion(0, pen, window, x, y);
|
SDL_SendPenMotion(0, pen, window, x, y);
|
||||||
SDL_SendPenAxis(0, pen, window, SDL_PEN_AXIS_PRESSURE, p);
|
SDL_SendPenAxis(0, pen, window, SDL_PEN_AXIS_PRESSURE, p);
|
||||||
// TODO: add more axis
|
// TODO: add more axis
|
||||||
@@ -77,7 +73,13 @@ void Android_OnPen(SDL_Window *window, int pen_id_in, int button, int action, fl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// button contains DOWN/ERASER_TIP on DOWN/UP regardless of pressed state, use action to distinguish
|
// button contains DOWN/ERASER_TIP on DOWN/UP regardless of pressed state, use action to distinguish
|
||||||
|
// we don't compare tip flags above because MotionEvent.getButtonState doesn't return stylus tip/eraser state.
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case ACTION_CANCEL:
|
||||||
|
case ACTION_HOVER_EXIT:
|
||||||
|
SDL_RemovePenDevice(0, pen);
|
||||||
|
break;
|
||||||
|
|
||||||
case ACTION_DOWN:
|
case ACTION_DOWN:
|
||||||
case ACTION_POINTER_DOWN:
|
case ACTION_POINTER_DOWN:
|
||||||
SDL_SendPenTouch(0, pen, window, (button & SDL_PEN_INPUT_ERASER_TIP) != 0, true);
|
SDL_SendPenTouch(0, pen, window, (button & SDL_PEN_INPUT_ERASER_TIP) != 0, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user