MotionEvent: implement getRawX() / getRawY() properly

This commit is contained in:
Julian Winkler
2024-03-14 22:20:01 +01:00
parent 796742c0fc
commit a67b973e67
3 changed files with 13 additions and 6 deletions

View File

@@ -83,7 +83,7 @@ void set_up_handle_cache(JNIEnv *env)
handle_cache.paint.getColor = _METHOD(handle_cache.paint.class, "getColor", "()I");
handle_cache.motion_event.class = _REF((*env)->FindClass(env, "android/view/MotionEvent"));
handle_cache.motion_event.constructor = _METHOD(handle_cache.motion_event.class, "<init>", "(IIFFJ)V");
handle_cache.motion_event.constructor = _METHOD(handle_cache.motion_event.class, "<init>", "(IIFFJFF)V");
handle_cache.canvas.class = _REF((*env)->FindClass(env, "android/graphics/Canvas"));
handle_cache.canvas.constructor = _METHOD(handle_cache.canvas.class, "<init>", "(JJ)V");

View File

@@ -19,10 +19,13 @@ static struct touch_callback_data *cancel_triggerer = NULL;
static bool call_ontouch_callback(int action, double x, double y, struct touch_callback_data *d, GtkPropagationPhase phase, guint32 timestamp, GdkEvent *event)
{
bool ret;
double raw_x;
double raw_y;
JNIEnv *env;
(*d->jvm)->GetEnv(d->jvm, (void**)&env, JNI_VERSION_1_6);
jobject motion_event = (*env)->NewObject(env, handle_cache.motion_event.class, handle_cache.motion_event.constructor, SOURCE_TOUCHSCREEN, action, (float)x, (float)y, (long)timestamp);
gdk_event_get_position(event, &raw_x, &raw_y);
jobject motion_event = (*env)->NewObject(env, handle_cache.motion_event.class, handle_cache.motion_event.constructor, SOURCE_TOUCHSCREEN, action, (float)x, (float)y, (long)timestamp, (float)raw_x, (float)raw_y);
if (phase == GTK_PHASE_CAPTURE && !d->intercepted) {
d->intercepted = (*env)->CallBooleanMethod(env, d->this, handle_cache.view.onInterceptTouchEvent, motion_event);
@@ -120,7 +123,7 @@ static gboolean scroll_cb(GtkEventControllerScroll* self, gdouble dx, gdouble dy
dx /= MAGIC_SCROLL_FACTOR;
dy /= MAGIC_SCROLL_FACTOR;
}
jobject motion_event = (*env)->NewObject(env, handle_cache.motion_event.class, handle_cache.motion_event.constructor, SOURCE_CLASS_POINTER, MOTION_EVENT_ACTION_SCROLL, dx, -dy, (long)0);
jobject motion_event = (*env)->NewObject(env, handle_cache.motion_event.class, handle_cache.motion_event.constructor, SOURCE_CLASS_POINTER, MOTION_EVENT_ACTION_SCROLL, dx, -dy, (long)0, 0.f, 0.f);
gboolean ret = (*env)->CallBooleanMethod(env, this, handle_cache.view.onGenericMotionEvent, motion_event);
if((*env)->ExceptionCheck(env))

View File

@@ -1370,16 +1370,20 @@ public final class MotionEvent extends InputEvent {
float coord_x;
float coord_y;
long eventTime;
float raw_x;
float raw_y;
private MotionEvent() {
}
public MotionEvent(int source, int action, float coord_x, float coord_y, long eventTime) {
public MotionEvent(int source, int action, float coord_x, float coord_y, long eventTime, float raw_x, float raw_y) {
this.source = source;
this.action = action;
this.coord_x = coord_x;
this.coord_y = coord_y;
this.eventTime = eventTime;
this.raw_x = raw_x;
this.raw_y = raw_y;
}
@Override
@@ -2233,7 +2237,7 @@ public final class MotionEvent extends InputEvent {
* @see #AXIS_X
*/
public final float getRawX() {
return coord_x;
return raw_x;
}
/**
@@ -2246,7 +2250,7 @@ public final class MotionEvent extends InputEvent {
* @see #AXIS_Y
*/
public final float getRawY() {
return coord_y;
return raw_y;
}
/**