game_activity/input: support Pointer::tool_type()

This maintains compatibility with the `ndk` crate's `Pointer` API

Ref: https://github.com/rust-windowing/android-ndk-rs/pull/323

This will also be required for enabling pen pressure support to
Winit, re: https://github.com/rust-windowing/winit/pull/2396
This commit is contained in:
Robert Bragg
2022-10-22 21:06:51 +01:00
parent bd8cc86ec7
commit c75f33a81e
7 changed files with 215 additions and 136 deletions
@@ -890,6 +890,7 @@ static struct {
jmethodID getPointerCount;
jmethodID getPointerId;
jmethodID getToolType;
jmethodID getRawX;
jmethodID getRawY;
jmethodID getXPrecision;
@@ -941,6 +942,8 @@ extern "C" int GameActivityMotionEvent_fromJava(
env->GetMethodID(motionEventClass, "getPointerCount", "()I");
gMotionEventClassInfo.getPointerId =
env->GetMethodID(motionEventClass, "getPointerId", "(I)I");
gMotionEventClassInfo.getToolType =
env->GetMethodID(motionEventClass, "getToolType", "(I)I");
if (sdkVersion >= 29) {
gMotionEventClassInfo.getRawX =
env->GetMethodID(motionEventClass, "getRawX", "(I)F");
@@ -1001,6 +1004,8 @@ extern "C" int GameActivityMotionEvent_fromJava(
out_event->pointers[i] = {
/*id=*/env->CallIntMethod(motionEvent,
gMotionEventClassInfo.getPointerId, i),
/*toolType=*/env->CallIntMethod(motionEvent,
gMotionEventClassInfo.getToolType, i),
/*axisValues=*/{0},
/*rawX=*/gMotionEventClassInfo.getRawX
? env->CallFloatMethod(motionEvent,