Skip to content

Commit

Permalink
Merge pull request jMonkeyEngine#254 from revvv/ios-touch-fix
Browse files Browse the repository at this point in the history
Add multi-touch support for iOS
  • Loading branch information
MeFisto94 authored Apr 1, 2020
2 parents c5a9beb + cb11c8d commit 577d53a
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions jme3-ios/ios-data/templates/project/jme-ios/jmeAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,18 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesBegan");
JNIEnv* e = getEnv(self.vm);
if (e) {
UITouch *touch = [touches anyObject];
CGPoint position = [touch locationInView: nil];
float scale = _glview.contentScaleFactor;
// NOTE: cast to jlong is required, otherwise JmeAppHarness receives non-sense values
(*e)->CallVoidMethod(e, self.harness, self.injectTouchBegin, 0, (jlong) touch.timestamp, position.x * scale, position.y * scale);
if ((*e)->ExceptionCheck(e)) {
NSLog(@"Could not invoke iOS Harness injectTouchBegin");
(*e)->ExceptionDescribe(e);
(*e)->ExceptionClear(e);
NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch;
while (touch = [enumerator nextObject]) {
CGPoint position = [touch locationInView: nil];
float scale = _glview.contentScaleFactor;
// NOTE: cast to jlong is required, otherwise JmeAppHarness receives non-sense values
(*e)->CallVoidMethod(e, self.harness, self.injectTouchBegin, (jint) touch.hash, (jlong) touch.timestamp, position.x * scale, position.y * scale);
if ((*e)->ExceptionCheck(e)) {
NSLog(@"Could not invoke iOS Harness injectTouchBegin");
(*e)->ExceptionDescribe(e);
(*e)->ExceptionClear(e);
}
}
}
}
Expand All @@ -290,14 +293,18 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesMoved");
JNIEnv* e = getEnv(self.vm);
if (e) {
UITouch *touch = [touches anyObject];
CGPoint position = [touch locationInView: nil];
float scale = _glview.contentScaleFactor;
(*e)->CallVoidMethod(e, self.harness, self.injectTouchMove, 0, (jlong) touch.timestamp, position.x * scale, position.y * scale);
if ((*e)->ExceptionCheck(e)) {
NSLog(@"Could not invoke iOS Harness injectTouchMove");
(*e)->ExceptionDescribe(e);
(*e)->ExceptionClear(e);
NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch;
while (touch = [enumerator nextObject]) {
CGPoint position = [touch locationInView: nil];
float scale = _glview.contentScaleFactor;
// NOTE: cast to jlong is required, otherwise JmeAppHarness receives non-sense values
(*e)->CallVoidMethod(e, self.harness, self.injectTouchMove, (jint) touch.hash, (jlong) touch.timestamp, position.x * scale, position.y * scale);
if ((*e)->ExceptionCheck(e)) {
NSLog(@"Could not invoke iOS Harness injectTouchMove");
(*e)->ExceptionDescribe(e);
(*e)->ExceptionClear(e);
}
}
}
}
Expand All @@ -306,14 +313,18 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesEnded");
JNIEnv* e = getEnv(self.vm);
if (e) {
UITouch *touch = [touches anyObject];
CGPoint position = [touch locationInView: nil];
float scale = _glview.contentScaleFactor;
(*e)->CallVoidMethod(e, self.harness, self.injectTouchEnd, 0, (jlong) touch.timestamp, position.x * scale, position.y * scale);
if ((*e)->ExceptionCheck(e)) {
NSLog(@"Could not invoke iOS Harness injectTouchEnd");
(*e)->ExceptionDescribe(e);
(*e)->ExceptionClear(e);
NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch;
while (touch = [enumerator nextObject]) {
CGPoint position = [touch locationInView: nil];
float scale = _glview.contentScaleFactor;
// NOTE: cast to jlong is required, otherwise JmeAppHarness receives non-sense values
(*e)->CallVoidMethod(e, self.harness, self.injectTouchEnd, (jint) touch.hash, (jlong) touch.timestamp, position.x * scale, position.y * scale);
if ((*e)->ExceptionCheck(e)) {
NSLog(@"Could not invoke iOS Harness injectTouchEnd");
(*e)->ExceptionDescribe(e);
(*e)->ExceptionClear(e);
}
}
}
}
Expand Down

0 comments on commit 577d53a

Please sign in to comment.