src/video/cocoa/SDL_cocoawindow.m
changeset 8986 1c81316ac642
parent 8978 7753e4fd3d1d
child 9041 89e97caa2387
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Jul 07 11:44:14 2014 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Jul 07 12:48:25 2014 -0700
     1.3 @@ -362,8 +362,7 @@
     1.4         !!! FIXME:   http://bugzilla.libsdl.org/show_bug.cgi?id=1825
     1.5      */
     1.6      windows = [NSApp orderedWindows];
     1.7 -    for (NSWindow *win in windows)
     1.8 -    {
     1.9 +    for (NSWindow *win in windows) {
    1.10          if (win == window) {
    1.11              continue;
    1.12          }
    1.13 @@ -386,8 +385,7 @@
    1.14  
    1.15  - (void)windowDidFinishMoving
    1.16  {
    1.17 -    if ([self isMoving])
    1.18 -    {
    1.19 +    if ([self isMoving]) {
    1.20          isMoving = NO;
    1.21  
    1.22          SDL_Mouse *mouse = SDL_GetMouse();
    1.23 @@ -859,48 +857,29 @@
    1.24  
    1.25  - (void)touchesBeganWithEvent:(NSEvent *) theEvent
    1.26  {
    1.27 -    [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent];
    1.28 +    [self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
    1.29  }
    1.30  
    1.31  - (void)touchesMovedWithEvent:(NSEvent *) theEvent
    1.32  {
    1.33 -    [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent];
    1.34 +    [self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
    1.35  }
    1.36  
    1.37  - (void)touchesEndedWithEvent:(NSEvent *) theEvent
    1.38  {
    1.39 -    [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent];
    1.40 +    [self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
    1.41  }
    1.42  
    1.43  - (void)touchesCancelledWithEvent:(NSEvent *) theEvent
    1.44  {
    1.45 -    [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent];
    1.46 +    [self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
    1.47  }
    1.48  
    1.49 -- (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
    1.50 +- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
    1.51  {
    1.52 -    NSSet *touches = 0;
    1.53 -    NSEnumerator *enumerator;
    1.54 -    NSTouch *touch;
    1.55 +    NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
    1.56  
    1.57 -    switch (type) {
    1.58 -        case COCOA_TOUCH_DOWN:
    1.59 -            touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
    1.60 -            break;
    1.61 -        case COCOA_TOUCH_UP:
    1.62 -            touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
    1.63 -            break;
    1.64 -        case COCOA_TOUCH_CANCELLED:
    1.65 -            touches = [event touchesMatchingPhase:NSTouchPhaseCancelled inView:nil];
    1.66 -            break;
    1.67 -        case COCOA_TOUCH_MOVE:
    1.68 -            touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
    1.69 -            break;
    1.70 -    }
    1.71 -
    1.72 -    enumerator = [touches objectEnumerator];
    1.73 -    touch = (NSTouch*)[enumerator nextObject];
    1.74 -    while (touch) {
    1.75 +    for (NSTouch *touch in touches) {
    1.76          const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
    1.77          if (!SDL_GetTouch(touchId)) {
    1.78              if (SDL_AddTouch(touchId, "") < 0) {
    1.79 @@ -914,20 +893,20 @@
    1.80          /* Make the origin the upper left instead of the lower left */
    1.81          y = 1.0f - y;
    1.82  
    1.83 -        switch (type) {
    1.84 -        case COCOA_TOUCH_DOWN:
    1.85 +        switch (phase) {
    1.86 +        case NSTouchPhaseBegan:
    1.87              SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
    1.88              break;
    1.89 -        case COCOA_TOUCH_UP:
    1.90 -        case COCOA_TOUCH_CANCELLED:
    1.91 +        case NSTouchPhaseEnded:
    1.92 +        case NSTouchPhaseCancelled:
    1.93              SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
    1.94              break;
    1.95 -        case COCOA_TOUCH_MOVE:
    1.96 +        case NSTouchPhaseMoved:
    1.97              SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
    1.98              break;
    1.99 +        default:
   1.100 +            break;
   1.101          }
   1.102 -
   1.103 -        touch = (NSTouch*)[enumerator nextObject];
   1.104      }
   1.105  }
   1.106  
   1.107 @@ -1065,23 +1044,20 @@
   1.108      NSRect rect;
   1.109      SDL_Rect bounds;
   1.110      unsigned int style;
   1.111 +    NSArray *screens = [NSScreen screens];
   1.112  
   1.113      Cocoa_GetDisplayBounds(_this, display, &bounds);
   1.114      rect.origin.x = window->x;
   1.115      rect.origin.y = window->y;
   1.116      rect.size.width = window->w;
   1.117      rect.size.height = window->h;
   1.118 -    ConvertNSRect([[NSScreen screens] objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect);
   1.119 +    ConvertNSRect([screens objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect);
   1.120  
   1.121      style = GetWindowStyle(window);
   1.122  
   1.123      /* Figure out which screen to place this window */
   1.124 -    NSArray *screens = [NSScreen screens];
   1.125      NSScreen *screen = nil;
   1.126 -    NSScreen *candidate;
   1.127 -    int i, count = [screens count];
   1.128 -    for (i = 0; i < count; ++i) {
   1.129 -        candidate = [screens objectAtIndex:i];
   1.130 +    for (NSScreen *candidate in screens) {
   1.131          NSRect screenRect = [candidate frame];
   1.132          if (rect.origin.x >= screenRect.origin.x &&
   1.133              rect.origin.x < screenRect.origin.x + screenRect.size.width &&
   1.134 @@ -1104,7 +1080,7 @@
   1.135      [nswindow setBackgroundColor:[NSColor blackColor]];
   1.136  
   1.137      if (videodata->allow_spaces) {
   1.138 -        SDL_assert(videodata->osversion >= 0x1070);
   1.139 +        SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
   1.140          SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
   1.141          /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
   1.142          if (window->flags & SDL_WINDOW_RESIZABLE) {