Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added a Cocoa implementation of SDL_CreateSystemCursor()

  • Loading branch information
slouken committed Nov 20, 2012
1 parent 62d8685 commit 2f7a6780d4cc98a7a4f6dbd964f4dd0b819677a5
Showing with 64 additions and 0 deletions.
  1. +64 −0 src/video/cocoa/SDL_cocoamouse.m
@@ -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;

0 comments on commit 2f7a678

Please sign in to comment.