///////////////////////////////////////////////////////
| 336 | |
| 337 | //////////////////////////////////////////////////////////// |
| 338 | int WindowImplAndroid::processScrollEvent(AInputEvent* inputEvent, ActivityStates& states) |
| 339 | { |
| 340 | // Prepare the Java virtual machine |
| 341 | auto jni = Jni::attachCurrentThread(*states.activity); |
| 342 | if (!jni) |
| 343 | { |
| 344 | err() << "Failed to initialize JNI" << std::endl; |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | auto& lJNIEnv = jni->getEnv(); |
| 349 | |
| 350 | // Retrieve everything we need to create this MotionEvent in Java |
| 351 | const std::int64_t downTime = AMotionEvent_getDownTime(inputEvent); |
| 352 | const std::int64_t eventTime = AMotionEvent_getEventTime(inputEvent); |
| 353 | const std::int32_t action = AMotionEvent_getAction(inputEvent); |
| 354 | const float x = AMotionEvent_getX(inputEvent, 0); |
| 355 | const float y = AMotionEvent_getY(inputEvent, 0); |
| 356 | const float pressure = AMotionEvent_getPressure(inputEvent, 0); |
| 357 | const float size = AMotionEvent_getSize(inputEvent, 0); |
| 358 | const std::int32_t metaState = AMotionEvent_getMetaState(inputEvent); |
| 359 | const float xPrecision = AMotionEvent_getXPrecision(inputEvent); |
| 360 | const float yPrecision = AMotionEvent_getYPrecision(inputEvent); |
| 361 | const std::int32_t deviceId = AInputEvent_getDeviceId(inputEvent); |
| 362 | const std::int32_t edgeFlags = AMotionEvent_getEdgeFlags(inputEvent); |
| 363 | |
| 364 | // Create the MotionEvent object in Java through its static constructor obtain() |
| 365 | jclass classMotionEvent = lJNIEnv.FindClass("android/view/MotionEvent"); |
| 366 | jmethodID staticMethodObtain = lJNIEnv.GetStaticMethodID(classMotionEvent, |
| 367 | "obtain", |
| 368 | "(JJIFFFFIFFII)Landroid/view/MotionEvent;"); |
| 369 | // Note: C standard compatibility, varargs |
| 370 | // automatically promote floats to doubles |
| 371 | // even though the function signature declares float |
| 372 | jobject objectMotionEvent = lJNIEnv.CallStaticObjectMethod(classMotionEvent, |
| 373 | staticMethodObtain, |
| 374 | downTime, |
| 375 | eventTime, |
| 376 | action, |
| 377 | static_cast<double>(x), |
| 378 | static_cast<double>(y), |
| 379 | static_cast<double>(pressure), |
| 380 | static_cast<double>(size), |
| 381 | metaState, |
| 382 | static_cast<double>(xPrecision), |
| 383 | static_cast<double>(yPrecision), |
| 384 | deviceId, |
| 385 | edgeFlags); |
| 386 | |
| 387 | // Call its getAxisValue() method to get the delta value of our wheel move event |
| 388 | jmethodID methodGetAxisValue = lJNIEnv.GetMethodID(classMotionEvent, "getAxisValue", "(I)F"); |
| 389 | const jfloat delta = lJNIEnv.CallFloatMethod(objectMotionEvent, methodGetAxisValue, 0x00000001); |
| 390 | |
| 391 | lJNIEnv.DeleteLocalRef(classMotionEvent); |
| 392 | lJNIEnv.DeleteLocalRef(objectMotionEvent); |
| 393 | |
| 394 | // Create and send our mouse wheel event |
| 395 | Event::MouseWheelScrolled event; |