Browse Source

Merge pull request #254 from revvv/ios-touch-fix

Add multi-touch support for iOS
MeFisto94 5 years ago
parent
commit
577d53a170
1 changed files with 36 additions and 25 deletions
  1. 36 25
      jme3-ios/ios-data/templates/project/jme-ios/jmeAppDelegate.m

+ 36 - 25
jme3-ios/ios-data/templates/project/jme-ios/jmeAppDelegate.m

@@ -273,15 +273,18 @@ getEnv(JavaVM* vm)
     NSLog(@"touchesBegan");
     NSLog(@"touchesBegan");
     JNIEnv* e = getEnv(self.vm);
     JNIEnv* e = getEnv(self.vm);
     if (e) {
     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);
+            }
         }
         }
     }
     }
 }
 }
@@ -290,14 +293,18 @@ getEnv(JavaVM* vm)
     NSLog(@"touchesMoved");
     NSLog(@"touchesMoved");
     JNIEnv* e = getEnv(self.vm);
     JNIEnv* e = getEnv(self.vm);
     if (e) {
     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);
+            }
         }
         }
     }
     }
 }
 }
@@ -306,14 +313,18 @@ getEnv(JavaVM* vm)
     NSLog(@"touchesEnded");
     NSLog(@"touchesEnded");
     JNIEnv* e = getEnv(self.vm);
     JNIEnv* e = getEnv(self.vm);
     if (e) {
     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);
+            }
         }
         }
     }
     }
 }
 }