Added a Cocoa implementation of SDL_CreateSystemCursor()
authorSam Lantinga <slouken@libsdl.org>
Mon, 19 Nov 2012 20:27:08 -0800
changeset 6676 4ff261ffaa42
parent 6675 20f3cdea0fd2
child 6677 c3202c29e352
Added a Cocoa implementation of SDL_CreateSystemCursor()
src/video/cocoa/SDL_cocoamouse.m
--- a/src/video/cocoa/SDL_cocoamouse.m	Mon Nov 19 15:11:10 2012 -0800
+++ b/src/video/cocoa/SDL_cocoamouse.m	Mon Nov 19 20:27:08 2012 -0800
@@ -22,6 +22,7 @@
 
 #if SDL_VIDEO_DRIVER_COCOA
 
+#include "SDL_assert.h"
 #include "SDL_events.h"
 #include "SDL_cocoavideo.h"
 
@@ -75,6 +76,68 @@
     return cursor;
 }
 
+static SDL_Cursor *
+Cocoa_CreateSystemCursor(SDL_SystemCursor id)
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    NSCursor *nscursor = NULL;
+    SDL_Cursor *cursor = NULL;
+
+    switch(id)
+    {
+    case SDL_SYSTEM_CURSOR_ARROW:
+        nscursor = [NSCursor arrowCursor];
+        break;
+    case SDL_SYSTEM_CURSOR_IBEAM:
+        nscursor = [NSCursor IBeamCursor];
+        break;
+    case SDL_SYSTEM_CURSOR_WAIT:
+        nscursor = [NSCursor arrowCursor];
+        break;
+    case SDL_SYSTEM_CURSOR_CROSSHAIR:
+        nscursor = [NSCursor crosshairCursor];
+        break;
+    case SDL_SYSTEM_CURSOR_WAITARROW:
+        nscursor = [NSCursor arrowCursor];
+        break;
+    case SDL_SYSTEM_CURSOR_SIZENWSE:
+    case SDL_SYSTEM_CURSOR_SIZENESW:
+        nscursor = [NSCursor closedHandCursor];
+        break;
+    case SDL_SYSTEM_CURSOR_SIZEWE:
+        nscursor = [NSCursor resizeLeftRightCursor];
+        break;
+    case SDL_SYSTEM_CURSOR_SIZENS:
+        nscursor = [NSCursor resizeUpDownCursor];
+        break;
+    case SDL_SYSTEM_CURSOR_SIZEALL:
+        nscursor = [NSCursor closedHandCursor];
+        break;
+    case SDL_SYSTEM_CURSOR_NO:
+        nscursor = [NSCursor operationNotAllowedCursor];
+        break;
+    case SDL_SYSTEM_CURSOR_HAND:
+        nscursor = [NSCursor pointingHandCursor];
+        break;
+    default:
+        SDL_assert(!"Unknown system cursor");
+        return NULL;
+    }
+
+    if (nscursor) {
+        cursor = SDL_calloc(1, sizeof(*cursor));
+        if (cursor) {
+            // We'll free it later, so retain it here
+            [nscursor retain];
+            cursor->driverdata = nscursor;
+        }
+    }
+
+    [pool release];
+
+    return cursor;
+}
+
 static void
 Cocoa_FreeCursor(SDL_Cursor * cursor)
 {
@@ -139,6 +202,7 @@
     SDL_Mouse *mouse = SDL_GetMouse();
 
     mouse->CreateCursor = Cocoa_CreateCursor;
+    mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
     mouse->ShowCursor = Cocoa_ShowCursor;
     mouse->FreeCursor = Cocoa_FreeCursor;
     mouse->WarpMouse = Cocoa_WarpMouse;