Added a Cocoa implementation of SDL_CreateSystemCursor()
authorSam Lantinga <slouken@libsdl.org>
Mon, 19 Nov 2012 20:27:08 -0800
changeset 66764ff261ffaa42
parent 6675 20f3cdea0fd2
child 6677 c3202c29e352
Added a Cocoa implementation of SDL_CreateSystemCursor()
src/video/cocoa/SDL_cocoamouse.m
     1.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Mon Nov 19 15:11:10 2012 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Mon Nov 19 20:27:08 2012 -0800
     1.3 @@ -22,6 +22,7 @@
     1.4  
     1.5  #if SDL_VIDEO_DRIVER_COCOA
     1.6  
     1.7 +#include "SDL_assert.h"
     1.8  #include "SDL_events.h"
     1.9  #include "SDL_cocoavideo.h"
    1.10  
    1.11 @@ -75,6 +76,68 @@
    1.12      return cursor;
    1.13  }
    1.14  
    1.15 +static SDL_Cursor *
    1.16 +Cocoa_CreateSystemCursor(SDL_SystemCursor id)
    1.17 +{
    1.18 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.19 +    NSCursor *nscursor = NULL;
    1.20 +    SDL_Cursor *cursor = NULL;
    1.21 +
    1.22 +    switch(id)
    1.23 +    {
    1.24 +    case SDL_SYSTEM_CURSOR_ARROW:
    1.25 +        nscursor = [NSCursor arrowCursor];
    1.26 +        break;
    1.27 +    case SDL_SYSTEM_CURSOR_IBEAM:
    1.28 +        nscursor = [NSCursor IBeamCursor];
    1.29 +        break;
    1.30 +    case SDL_SYSTEM_CURSOR_WAIT:
    1.31 +        nscursor = [NSCursor arrowCursor];
    1.32 +        break;
    1.33 +    case SDL_SYSTEM_CURSOR_CROSSHAIR:
    1.34 +        nscursor = [NSCursor crosshairCursor];
    1.35 +        break;
    1.36 +    case SDL_SYSTEM_CURSOR_WAITARROW:
    1.37 +        nscursor = [NSCursor arrowCursor];
    1.38 +        break;
    1.39 +    case SDL_SYSTEM_CURSOR_SIZENWSE:
    1.40 +    case SDL_SYSTEM_CURSOR_SIZENESW:
    1.41 +        nscursor = [NSCursor closedHandCursor];
    1.42 +        break;
    1.43 +    case SDL_SYSTEM_CURSOR_SIZEWE:
    1.44 +        nscursor = [NSCursor resizeLeftRightCursor];
    1.45 +        break;
    1.46 +    case SDL_SYSTEM_CURSOR_SIZENS:
    1.47 +        nscursor = [NSCursor resizeUpDownCursor];
    1.48 +        break;
    1.49 +    case SDL_SYSTEM_CURSOR_SIZEALL:
    1.50 +        nscursor = [NSCursor closedHandCursor];
    1.51 +        break;
    1.52 +    case SDL_SYSTEM_CURSOR_NO:
    1.53 +        nscursor = [NSCursor operationNotAllowedCursor];
    1.54 +        break;
    1.55 +    case SDL_SYSTEM_CURSOR_HAND:
    1.56 +        nscursor = [NSCursor pointingHandCursor];
    1.57 +        break;
    1.58 +    default:
    1.59 +        SDL_assert(!"Unknown system cursor");
    1.60 +        return NULL;
    1.61 +    }
    1.62 +
    1.63 +    if (nscursor) {
    1.64 +        cursor = SDL_calloc(1, sizeof(*cursor));
    1.65 +        if (cursor) {
    1.66 +            // We'll free it later, so retain it here
    1.67 +            [nscursor retain];
    1.68 +            cursor->driverdata = nscursor;
    1.69 +        }
    1.70 +    }
    1.71 +
    1.72 +    [pool release];
    1.73 +
    1.74 +    return cursor;
    1.75 +}
    1.76 +
    1.77  static void
    1.78  Cocoa_FreeCursor(SDL_Cursor * cursor)
    1.79  {
    1.80 @@ -139,6 +202,7 @@
    1.81      SDL_Mouse *mouse = SDL_GetMouse();
    1.82  
    1.83      mouse->CreateCursor = Cocoa_CreateCursor;
    1.84 +    mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
    1.85      mouse->ShowCursor = Cocoa_ShowCursor;
    1.86      mouse->FreeCursor = Cocoa_FreeCursor;
    1.87      mouse->WarpMouse = Cocoa_WarpMouse;