Fixed sending motion and finger up events
authorSam Lantinga <slouken@libsdl.org>
Sat, 31 Jul 2010 20:55:33 -0700
changeset 4680 229529693289
parent 4679 5ee96ba0c01e
child 4681 5378f2d0754f
Fixed sending motion and finger up events
src/video/cocoa/SDL_cocoawindow.m
--- a/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 31 20:38:37 2010 -0700
+++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 31 20:55:33 2010 -0700
@@ -291,14 +291,28 @@
 
 - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
 {
-    NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
+    NSSet *touches = 0;
+    NSEnumerator *enumerator;
+    NSTouch *touch;
 
-    NSEnumerator *enumerator = [touches objectEnumerator];
-    NSTouch *touch = (NSTouch*)[enumerator nextObject];
+    switch (type) {
+        case COCOA_TOUCH_DOWN:
+            touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
+            break;
+        case COCOA_TOUCH_UP:
+        case COCOA_TOUCH_CANCELLED:
+            touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
+            break;
+        case COCOA_TOUCH_MOVE:
+            touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
+            break;
+    }
+
+    enumerator = [touches objectEnumerator];
+    touch = (NSTouch*)[enumerator nextObject];
     while (touch) {
-        long touchId = (long)[touch device];
+        SDL_TouchID touchId = (SDL_TouchID)[touch device];
         if (!SDL_GetTouch(touchId)) {
-	  printf("Adding touch: %li\n",touchId);
             SDL_Touch touch;
 
             touch.id = touchId;
@@ -313,13 +327,12 @@
             touch.native_pressureres = touch.pressure_max - touch.pressure_min;
             
             if (SDL_AddTouch(&touch, "") < 0) {
-                continue;
+                return;
             }
-	    printf("Success, added touch: %li\n",touchId);
         } 
         float x = [touch normalizedPosition].x;
         float y = [touch normalizedPosition].y;
-        long fingerId = (long)[touch identity];
+        SDL_FingerID fingerId = (SDL_FingerID)[touch identity];
         switch (type) {
         case COCOA_TOUCH_DOWN:
             SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1);