changeset 4680:229529693289

Fixed sending motion and finger up events
author Sam Lantinga <slouken@libsdl.org>
date Sat, 31 Jul 2010 20:55:33 -0700
parents 5ee96ba0c01e
children 5378f2d0754f
files src/video/cocoa/SDL_cocoawindow.m
diffstat 1 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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);