src/video/cocoa/SDL_cocoamouse.m
changeset 6832 156e608ec4ef
parent 6676 4ff261ffaa42
child 6848 478ecc8a58b3
equal deleted inserted replaced
6831:935b871e1ffe 6832:156e608ec4ef
    30 
    30 
    31 
    31 
    32 static SDL_Cursor *
    32 static SDL_Cursor *
    33 Cocoa_CreateDefaultCursor()
    33 Cocoa_CreateDefaultCursor()
    34 {
    34 {
    35     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    35     @autoreleasepool {
    36     NSCursor *nscursor;
    36         NSCursor *nscursor;
    37     SDL_Cursor *cursor = NULL;
    37         SDL_Cursor *cursor = NULL;
    38 
    38 
    39     nscursor = [NSCursor arrowCursor];
    39         nscursor = [NSCursor arrowCursor];
    40 
    40 
    41     if (nscursor) {
    41         if (nscursor) {
    42         cursor = SDL_calloc(1, sizeof(*cursor));
    42             cursor = SDL_calloc(1, sizeof(*cursor));
    43         if (cursor) {
    43             if (cursor) {
    44             cursor->driverdata = nscursor;
    44                 cursor->driverdata = nscursor;
    45             [nscursor retain];
    45                 [nscursor retain];
    46         }
    46             }
    47     }
    47         }
    48 
    48         
    49     [pool release];
    49         return cursor;
    50 
    50     }
    51     return cursor;
       
    52 }
    51 }
    53 
    52 
    54 static SDL_Cursor *
    53 static SDL_Cursor *
    55 Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
    54 Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
    56 {
    55 {
    57     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    56     @autoreleasepool {
    58     NSImage *nsimage;
    57         NSImage *nsimage;
    59     NSCursor *nscursor = NULL;
    58         NSCursor *nscursor = NULL;
    60     SDL_Cursor *cursor = NULL;
    59         SDL_Cursor *cursor = NULL;
    61 
    60 
    62     nsimage = Cocoa_CreateImage(surface);
    61         nsimage = Cocoa_CreateImage(surface);
    63     if (nsimage) {
    62         if (nsimage) {
    64         nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
    63             nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
    65     }
    64         }
    66 
    65 
    67     if (nscursor) {
    66         if (nscursor) {
    68         cursor = SDL_calloc(1, sizeof(*cursor));
    67             cursor = SDL_calloc(1, sizeof(*cursor));
    69         if (cursor) {
    68             if (cursor) {
    70             cursor->driverdata = nscursor;
    69                 cursor->driverdata = nscursor;
    71         }
    70             }
    72     }
    71         }
    73 
    72         
    74     [pool release];
    73         return cursor;
    75 
    74     }
    76     return cursor;
       
    77 }
    75 }
    78 
    76 
    79 static SDL_Cursor *
    77 static SDL_Cursor *
    80 Cocoa_CreateSystemCursor(SDL_SystemCursor id)
    78 Cocoa_CreateSystemCursor(SDL_SystemCursor id)
    81 {
    79 {
    82     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    80     @autoreleasepool {
    83     NSCursor *nscursor = NULL;
    81         NSCursor *nscursor = NULL;
    84     SDL_Cursor *cursor = NULL;
    82         SDL_Cursor *cursor = NULL;
    85 
    83 
    86     switch(id)
    84         switch(id)
    87     {
    85         {
    88     case SDL_SYSTEM_CURSOR_ARROW:
    86         case SDL_SYSTEM_CURSOR_ARROW:
    89         nscursor = [NSCursor arrowCursor];
    87             nscursor = [NSCursor arrowCursor];
    90         break;
    88             break;
    91     case SDL_SYSTEM_CURSOR_IBEAM:
    89         case SDL_SYSTEM_CURSOR_IBEAM:
    92         nscursor = [NSCursor IBeamCursor];
    90             nscursor = [NSCursor IBeamCursor];
    93         break;
    91             break;
    94     case SDL_SYSTEM_CURSOR_WAIT:
    92         case SDL_SYSTEM_CURSOR_WAIT:
    95         nscursor = [NSCursor arrowCursor];
    93             nscursor = [NSCursor arrowCursor];
    96         break;
    94             break;
    97     case SDL_SYSTEM_CURSOR_CROSSHAIR:
    95         case SDL_SYSTEM_CURSOR_CROSSHAIR:
    98         nscursor = [NSCursor crosshairCursor];
    96             nscursor = [NSCursor crosshairCursor];
    99         break;
    97             break;
   100     case SDL_SYSTEM_CURSOR_WAITARROW:
    98         case SDL_SYSTEM_CURSOR_WAITARROW:
   101         nscursor = [NSCursor arrowCursor];
    99             nscursor = [NSCursor arrowCursor];
   102         break;
   100             break;
   103     case SDL_SYSTEM_CURSOR_SIZENWSE:
   101         case SDL_SYSTEM_CURSOR_SIZENWSE:
   104     case SDL_SYSTEM_CURSOR_SIZENESW:
   102         case SDL_SYSTEM_CURSOR_SIZENESW:
   105         nscursor = [NSCursor closedHandCursor];
   103             nscursor = [NSCursor closedHandCursor];
   106         break;
   104             break;
   107     case SDL_SYSTEM_CURSOR_SIZEWE:
   105         case SDL_SYSTEM_CURSOR_SIZEWE:
   108         nscursor = [NSCursor resizeLeftRightCursor];
   106             nscursor = [NSCursor resizeLeftRightCursor];
   109         break;
   107             break;
   110     case SDL_SYSTEM_CURSOR_SIZENS:
   108         case SDL_SYSTEM_CURSOR_SIZENS:
   111         nscursor = [NSCursor resizeUpDownCursor];
   109             nscursor = [NSCursor resizeUpDownCursor];
   112         break;
   110             break;
   113     case SDL_SYSTEM_CURSOR_SIZEALL:
   111         case SDL_SYSTEM_CURSOR_SIZEALL:
   114         nscursor = [NSCursor closedHandCursor];
   112             nscursor = [NSCursor closedHandCursor];
   115         break;
   113             break;
   116     case SDL_SYSTEM_CURSOR_NO:
   114         case SDL_SYSTEM_CURSOR_NO:
   117         nscursor = [NSCursor operationNotAllowedCursor];
   115             nscursor = [NSCursor operationNotAllowedCursor];
   118         break;
   116             break;
   119     case SDL_SYSTEM_CURSOR_HAND:
   117         case SDL_SYSTEM_CURSOR_HAND:
   120         nscursor = [NSCursor pointingHandCursor];
   118             nscursor = [NSCursor pointingHandCursor];
   121         break;
   119             break;
   122     default:
   120         default:
   123         SDL_assert(!"Unknown system cursor");
   121             SDL_assert(!"Unknown system cursor");
   124         return NULL;
   122             return NULL;
   125     }
   123         }
   126 
   124 
   127     if (nscursor) {
   125         if (nscursor) {
   128         cursor = SDL_calloc(1, sizeof(*cursor));
   126             cursor = SDL_calloc(1, sizeof(*cursor));
   129         if (cursor) {
   127             if (cursor) {
   130             // We'll free it later, so retain it here
   128                 // We'll free it later, so retain it here
   131             [nscursor retain];
   129                 [nscursor retain];
   132             cursor->driverdata = nscursor;
   130                 cursor->driverdata = nscursor;
   133         }
   131             }
   134     }
   132         }
   135 
   133             
   136     [pool release];
   134         return cursor;
   137 
   135     }
   138     return cursor;
       
   139 }
   136 }
   140 
   137 
   141 static void
   138 static void
   142 Cocoa_FreeCursor(SDL_Cursor * cursor)
   139 Cocoa_FreeCursor(SDL_Cursor * cursor)
   143 {
   140 {
   144     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   141     @autoreleasepool {
   145     NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   142         NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   146 
   143 
   147     [nscursor release];
   144         [nscursor release];
   148     SDL_free(cursor);
   145         SDL_free(cursor);
   149 
   146     }
   150     [pool release];
       
   151 }
   147 }
   152 
   148 
   153 static int
   149 static int
   154 Cocoa_ShowCursor(SDL_Cursor * cursor)
   150 Cocoa_ShowCursor(SDL_Cursor * cursor)
   155 {
   151 {
   156     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   152     @autoreleasepool {
   157 
   153         if (cursor) {
   158     if (cursor) {
   154             NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   159         NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   155 
   160 
   156             [nscursor set];
   161         [nscursor set];
   157             [NSCursor unhide];
   162         [NSCursor unhide];
   158         } else {
   163     } else {
   159             [NSCursor hide];
   164         [NSCursor hide];
   160         }
   165     }
   161     }
   166 
       
   167     [pool release];
       
   168 
   162 
   169     return 0;
   163     return 0;
   170 }
   164 }
   171 
   165 
   172 static void
   166 static void