Fixed sending motion and finger up events
authorSam Lantinga <slouken@libsdl.org>
Sat, 31 Jul 2010 20:55:33 -0700
changeset 4680229529693289
parent 4679 5ee96ba0c01e
child 4681 5378f2d0754f
Fixed sending motion and finger up events
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 31 20:38:37 2010 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 31 20:55:33 2010 -0700
     1.3 @@ -291,14 +291,28 @@
     1.4  
     1.5  - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
     1.6  {
     1.7 -    NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
     1.8 +    NSSet *touches = 0;
     1.9 +    NSEnumerator *enumerator;
    1.10 +    NSTouch *touch;
    1.11  
    1.12 -    NSEnumerator *enumerator = [touches objectEnumerator];
    1.13 -    NSTouch *touch = (NSTouch*)[enumerator nextObject];
    1.14 +    switch (type) {
    1.15 +        case COCOA_TOUCH_DOWN:
    1.16 +            touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
    1.17 +            break;
    1.18 +        case COCOA_TOUCH_UP:
    1.19 +        case COCOA_TOUCH_CANCELLED:
    1.20 +            touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
    1.21 +            break;
    1.22 +        case COCOA_TOUCH_MOVE:
    1.23 +            touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
    1.24 +            break;
    1.25 +    }
    1.26 +
    1.27 +    enumerator = [touches objectEnumerator];
    1.28 +    touch = (NSTouch*)[enumerator nextObject];
    1.29      while (touch) {
    1.30 -        long touchId = (long)[touch device];
    1.31 +        SDL_TouchID touchId = (SDL_TouchID)[touch device];
    1.32          if (!SDL_GetTouch(touchId)) {
    1.33 -	  printf("Adding touch: %li\n",touchId);
    1.34              SDL_Touch touch;
    1.35  
    1.36              touch.id = touchId;
    1.37 @@ -313,13 +327,12 @@
    1.38              touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    1.39              
    1.40              if (SDL_AddTouch(&touch, "") < 0) {
    1.41 -                continue;
    1.42 +                return;
    1.43              }
    1.44 -	    printf("Success, added touch: %li\n",touchId);
    1.45          } 
    1.46          float x = [touch normalizedPosition].x;
    1.47          float y = [touch normalizedPosition].y;
    1.48 -        long fingerId = (long)[touch identity];
    1.49 +        SDL_FingerID fingerId = (SDL_FingerID)[touch identity];
    1.50          switch (type) {
    1.51          case COCOA_TOUCH_DOWN:
    1.52              SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1);