src/video/cocoa/SDL_cocoamouse.m
changeset 6832 156e608ec4ef
parent 6676 4ff261ffaa42
child 6848 478ecc8a58b3
     1.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Fri Feb 01 17:09:01 2013 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Sun Jan 06 19:04:53 2013 +0300
     1.3 @@ -32,140 +32,134 @@
     1.4  static SDL_Cursor *
     1.5  Cocoa_CreateDefaultCursor()
     1.6  {
     1.7 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     1.8 -    NSCursor *nscursor;
     1.9 -    SDL_Cursor *cursor = NULL;
    1.10 +    @autoreleasepool {
    1.11 +        NSCursor *nscursor;
    1.12 +        SDL_Cursor *cursor = NULL;
    1.13  
    1.14 -    nscursor = [NSCursor arrowCursor];
    1.15 +        nscursor = [NSCursor arrowCursor];
    1.16  
    1.17 -    if (nscursor) {
    1.18 -        cursor = SDL_calloc(1, sizeof(*cursor));
    1.19 -        if (cursor) {
    1.20 -            cursor->driverdata = nscursor;
    1.21 -            [nscursor retain];
    1.22 +        if (nscursor) {
    1.23 +            cursor = SDL_calloc(1, sizeof(*cursor));
    1.24 +            if (cursor) {
    1.25 +                cursor->driverdata = nscursor;
    1.26 +                [nscursor retain];
    1.27 +            }
    1.28          }
    1.29 +        
    1.30 +        return cursor;
    1.31      }
    1.32 -
    1.33 -    [pool release];
    1.34 -
    1.35 -    return cursor;
    1.36  }
    1.37  
    1.38  static SDL_Cursor *
    1.39  Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
    1.40  {
    1.41 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.42 -    NSImage *nsimage;
    1.43 -    NSCursor *nscursor = NULL;
    1.44 -    SDL_Cursor *cursor = NULL;
    1.45 +    @autoreleasepool {
    1.46 +        NSImage *nsimage;
    1.47 +        NSCursor *nscursor = NULL;
    1.48 +        SDL_Cursor *cursor = NULL;
    1.49  
    1.50 -    nsimage = Cocoa_CreateImage(surface);
    1.51 -    if (nsimage) {
    1.52 -        nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
    1.53 +        nsimage = Cocoa_CreateImage(surface);
    1.54 +        if (nsimage) {
    1.55 +            nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
    1.56 +        }
    1.57 +
    1.58 +        if (nscursor) {
    1.59 +            cursor = SDL_calloc(1, sizeof(*cursor));
    1.60 +            if (cursor) {
    1.61 +                cursor->driverdata = nscursor;
    1.62 +            }
    1.63 +        }
    1.64 +        
    1.65 +        return cursor;
    1.66      }
    1.67 -
    1.68 -    if (nscursor) {
    1.69 -        cursor = SDL_calloc(1, sizeof(*cursor));
    1.70 -        if (cursor) {
    1.71 -            cursor->driverdata = nscursor;
    1.72 -        }
    1.73 -    }
    1.74 -
    1.75 -    [pool release];
    1.76 -
    1.77 -    return cursor;
    1.78  }
    1.79  
    1.80  static SDL_Cursor *
    1.81  Cocoa_CreateSystemCursor(SDL_SystemCursor id)
    1.82  {
    1.83 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.84 -    NSCursor *nscursor = NULL;
    1.85 -    SDL_Cursor *cursor = NULL;
    1.86 +    @autoreleasepool {
    1.87 +        NSCursor *nscursor = NULL;
    1.88 +        SDL_Cursor *cursor = NULL;
    1.89  
    1.90 -    switch(id)
    1.91 -    {
    1.92 -    case SDL_SYSTEM_CURSOR_ARROW:
    1.93 -        nscursor = [NSCursor arrowCursor];
    1.94 -        break;
    1.95 -    case SDL_SYSTEM_CURSOR_IBEAM:
    1.96 -        nscursor = [NSCursor IBeamCursor];
    1.97 -        break;
    1.98 -    case SDL_SYSTEM_CURSOR_WAIT:
    1.99 -        nscursor = [NSCursor arrowCursor];
   1.100 -        break;
   1.101 -    case SDL_SYSTEM_CURSOR_CROSSHAIR:
   1.102 -        nscursor = [NSCursor crosshairCursor];
   1.103 -        break;
   1.104 -    case SDL_SYSTEM_CURSOR_WAITARROW:
   1.105 -        nscursor = [NSCursor arrowCursor];
   1.106 -        break;
   1.107 -    case SDL_SYSTEM_CURSOR_SIZENWSE:
   1.108 -    case SDL_SYSTEM_CURSOR_SIZENESW:
   1.109 -        nscursor = [NSCursor closedHandCursor];
   1.110 -        break;
   1.111 -    case SDL_SYSTEM_CURSOR_SIZEWE:
   1.112 -        nscursor = [NSCursor resizeLeftRightCursor];
   1.113 -        break;
   1.114 -    case SDL_SYSTEM_CURSOR_SIZENS:
   1.115 -        nscursor = [NSCursor resizeUpDownCursor];
   1.116 -        break;
   1.117 -    case SDL_SYSTEM_CURSOR_SIZEALL:
   1.118 -        nscursor = [NSCursor closedHandCursor];
   1.119 -        break;
   1.120 -    case SDL_SYSTEM_CURSOR_NO:
   1.121 -        nscursor = [NSCursor operationNotAllowedCursor];
   1.122 -        break;
   1.123 -    case SDL_SYSTEM_CURSOR_HAND:
   1.124 -        nscursor = [NSCursor pointingHandCursor];
   1.125 -        break;
   1.126 -    default:
   1.127 -        SDL_assert(!"Unknown system cursor");
   1.128 -        return NULL;
   1.129 +        switch(id)
   1.130 +        {
   1.131 +        case SDL_SYSTEM_CURSOR_ARROW:
   1.132 +            nscursor = [NSCursor arrowCursor];
   1.133 +            break;
   1.134 +        case SDL_SYSTEM_CURSOR_IBEAM:
   1.135 +            nscursor = [NSCursor IBeamCursor];
   1.136 +            break;
   1.137 +        case SDL_SYSTEM_CURSOR_WAIT:
   1.138 +            nscursor = [NSCursor arrowCursor];
   1.139 +            break;
   1.140 +        case SDL_SYSTEM_CURSOR_CROSSHAIR:
   1.141 +            nscursor = [NSCursor crosshairCursor];
   1.142 +            break;
   1.143 +        case SDL_SYSTEM_CURSOR_WAITARROW:
   1.144 +            nscursor = [NSCursor arrowCursor];
   1.145 +            break;
   1.146 +        case SDL_SYSTEM_CURSOR_SIZENWSE:
   1.147 +        case SDL_SYSTEM_CURSOR_SIZENESW:
   1.148 +            nscursor = [NSCursor closedHandCursor];
   1.149 +            break;
   1.150 +        case SDL_SYSTEM_CURSOR_SIZEWE:
   1.151 +            nscursor = [NSCursor resizeLeftRightCursor];
   1.152 +            break;
   1.153 +        case SDL_SYSTEM_CURSOR_SIZENS:
   1.154 +            nscursor = [NSCursor resizeUpDownCursor];
   1.155 +            break;
   1.156 +        case SDL_SYSTEM_CURSOR_SIZEALL:
   1.157 +            nscursor = [NSCursor closedHandCursor];
   1.158 +            break;
   1.159 +        case SDL_SYSTEM_CURSOR_NO:
   1.160 +            nscursor = [NSCursor operationNotAllowedCursor];
   1.161 +            break;
   1.162 +        case SDL_SYSTEM_CURSOR_HAND:
   1.163 +            nscursor = [NSCursor pointingHandCursor];
   1.164 +            break;
   1.165 +        default:
   1.166 +            SDL_assert(!"Unknown system cursor");
   1.167 +            return NULL;
   1.168 +        }
   1.169 +
   1.170 +        if (nscursor) {
   1.171 +            cursor = SDL_calloc(1, sizeof(*cursor));
   1.172 +            if (cursor) {
   1.173 +                // We'll free it later, so retain it here
   1.174 +                [nscursor retain];
   1.175 +                cursor->driverdata = nscursor;
   1.176 +            }
   1.177 +        }
   1.178 +            
   1.179 +        return cursor;
   1.180      }
   1.181 -
   1.182 -    if (nscursor) {
   1.183 -        cursor = SDL_calloc(1, sizeof(*cursor));
   1.184 -        if (cursor) {
   1.185 -            // We'll free it later, so retain it here
   1.186 -            [nscursor retain];
   1.187 -            cursor->driverdata = nscursor;
   1.188 -        }
   1.189 -    }
   1.190 -
   1.191 -    [pool release];
   1.192 -
   1.193 -    return cursor;
   1.194  }
   1.195  
   1.196  static void
   1.197  Cocoa_FreeCursor(SDL_Cursor * cursor)
   1.198  {
   1.199 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.200 -    NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   1.201 +    @autoreleasepool {
   1.202 +        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   1.203  
   1.204 -    [nscursor release];
   1.205 -    SDL_free(cursor);
   1.206 -
   1.207 -    [pool release];
   1.208 +        [nscursor release];
   1.209 +        SDL_free(cursor);
   1.210 +    }
   1.211  }
   1.212  
   1.213  static int
   1.214  Cocoa_ShowCursor(SDL_Cursor * cursor)
   1.215  {
   1.216 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.217 +    @autoreleasepool {
   1.218 +        if (cursor) {
   1.219 +            NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   1.220  
   1.221 -    if (cursor) {
   1.222 -        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   1.223 -
   1.224 -        [nscursor set];
   1.225 -        [NSCursor unhide];
   1.226 -    } else {
   1.227 -        [NSCursor hide];
   1.228 +            [nscursor set];
   1.229 +            [NSCursor unhide];
   1.230 +        } else {
   1.231 +            [NSCursor hide];
   1.232 +        }
   1.233      }
   1.234  
   1.235 -    [pool release];
   1.236 -
   1.237      return 0;
   1.238  }
   1.239