Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added a Cocoa implementation of SDL_CreateSystemCursor()
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 20, 2012
1 parent 62d8685 commit 2f7a678
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/video/cocoa/SDL_cocoamouse.m
Expand Up @@ -22,6 +22,7 @@

#if SDL_VIDEO_DRIVER_COCOA

#include "SDL_assert.h"
#include "SDL_events.h"
#include "SDL_cocoavideo.h"

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2f7a678

Please sign in to comment.