src/video/cocoa/SDL_cocoamouse.m
changeset 7158 ff52fba70795
parent 7114 02b2fe147478
child 7191 75360622e65f
     1.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Mon May 06 23:02:37 2013 +0200
     1.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Tue May 07 16:52:39 2013 -0700
     1.3 @@ -28,6 +28,32 @@
     1.4  
     1.5  #include "../../events/SDL_mouse_c.h"
     1.6  
     1.7 +@implementation NSCursor (InvisibleCursor)
     1.8 ++ (NSCursor *)invisibleCursor
     1.9 +{
    1.10 +    static NSCursor *invisibleCursor = NULL;
    1.11 +    if (!invisibleCursor) {
    1.12 +        /* RAW 16x16 transparent GIF */
    1.13 +        static unsigned char cursorBytes[] = {
    1.14 +            0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80,
    1.15 +            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
    1.16 +            0x01, 0x00, 0x00, 0x01, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x10,
    1.17 +            0x00, 0x10, 0x00, 0x00, 0x02, 0x0E, 0x8C, 0x8F, 0xA9, 0xCB, 0xED,
    1.18 +            0x0F, 0xA3, 0x9C, 0xB4, 0xDA, 0x8B, 0xB3, 0x3E, 0x05, 0x00, 0x3B
    1.19 +        };
    1.20 +
    1.21 +        NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0]
    1.22 +                                                  length:sizeof(cursorBytes)
    1.23 +                                            freeWhenDone:NO];
    1.24 +        NSImage *cursorImage = [[[NSImage alloc] initWithData:cursorData] autorelease];
    1.25 +        invisibleCursor = [[NSCursor alloc] initWithImage:cursorImage
    1.26 +                                                  hotSpot:NSZeroPoint];
    1.27 +    }
    1.28 +
    1.29 +    return invisibleCursor;
    1.30 +}
    1.31 +@end
    1.32 +
    1.33  
    1.34  static SDL_Cursor *
    1.35  Cocoa_CreateDefaultCursor()
    1.36 @@ -153,30 +179,17 @@
    1.37  static int
    1.38  Cocoa_ShowCursor(SDL_Cursor * cursor)
    1.39  {
    1.40 -	/* We need to track the previous state because hide and unhide calls need to
    1.41 -	 * be matched, but ShowCursor calls don't.
    1.42 -	 */
    1.43 -	static SDL_bool isShown = SDL_TRUE;
    1.44      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.45  
    1.46 -    if (cursor) {
    1.47 -        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
    1.48 -
    1.49 -        /* We're possibly executing from an event handler where this operation
    1.50 -         * is unsupported. This will execute it in the main Cocoa event loop
    1.51 -         * after this returns.
    1.52 -         */
    1.53 -        [nscursor performSelectorOnMainThread:@selector(set)
    1.54 -                                   withObject:nil
    1.55 -                                waitUntilDone:NO];
    1.56 -
    1.57 -		if (!isShown) {
    1.58 -			[NSCursor unhide];
    1.59 -			isShown = SDL_TRUE;
    1.60 -		}
    1.61 -	} else if (isShown) {
    1.62 -		[NSCursor hide];
    1.63 -		isShown = SDL_FALSE;
    1.64 +    SDL_VideoDevice *device = SDL_GetVideoDevice();
    1.65 +    SDL_Window *window = (device ? device->windows : NULL);
    1.66 +    for (; window != NULL; window = window->next) {
    1.67 +        SDL_WindowData *driverdata = (SDL_WindowData *)window->driverdata;
    1.68 +        if (driverdata) {
    1.69 +            [driverdata->nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:)
    1.70 +                                                   withObject:[driverdata->nswindow contentView]
    1.71 +                                                waitUntilDone:NO];
    1.72 +        }
    1.73      }
    1.74  
    1.75      [pool release];