Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Native OSX Lion resize cursor for custom NSWindow or NSView

If we use NSTrackingArea for some specified region then we can implement such method to change the default cursor:

-(void)cursorUpdate:(NSEvent *)theEvent {
    [[NSCursor resizeLeftCursor] set];
}

I implementing custom resize for NSWindow, which uses NSBorderlessWindowMask. And want to use native Lion's two arrows cursors. But such type of cursors not exist in NSCursor API.

Can I get such native cursors somehow from code?
Or maybe I must redraw them by hand (not a good idea)?

like image 382
Vadim Avatar asked May 24 '12 07:05

Vadim


4 Answers

The ones present in WebKit are not available in retina resolution unfortunatly, looking in

/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors

you'll find pdf version of resizing cursors.

like image 151
thebenjiman Avatar answered Nov 15 '22 08:11

thebenjiman


Here's some sample code for loading vector-based (and therefore retina capable) cursors from HIServices.framework:

NSString *cursorName = @"resizenortheastsouthwest";
NSString *cursorPath = [@"/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors" stringByAppendingPathComponent:cursorName];
NSImage *image = [[NSImage alloc] initByReferencingFile:[cursorPath stringByAppendingPathComponent:@"cursor.pdf"]];
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"info.plist"]];
NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint([[info valueForKey:@"hotx"] doubleValue], [[info valueForKey:@"hoty"] doubleValue])];

Note I don't know whether this works in sandboxed Apps.

like image 26
Nick Dowell Avatar answered Nov 15 '22 09:11

Nick Dowell


There are undocumented methods for creating such cursors. Here's an example:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
    if ([NSCursor respondsToSelector:@selector(_windowResizeNorthSouthCursor)])
    {
        self.resizeUpDownCursor = [NSCursor performSelector:@selector(_windowResizeNorthSouthCursor)];
    }
    else
    {
        self.resizeUpDownCursor = [NSCursor resizeUpDownCursor];
    }
#pragma clang diagnostic pop

Here's the full list of undocumented cursors in macOS Sierra:

[NSCursor _windowResizeEastCursor]
[NSCursor _windowResizeWestCursor]
[NSCursor _windowResizeEastWestCursor]
[NSCursor _windowResizeNorthCursor]
[NSCursor _windowResizeSouthCursor]
[NSCursor _windowResizeNorthSouthCursor]
[NSCursor _windowResizeNorthEastCursor]
[NSCursor _windowResizeNorthWestCursor]
[NSCursor _windowResizeSouthEastCursor]
[NSCursor _windowResizeSouthWestCursor]
[NSCursor _windowResizeNorthEastSouthWestCursor]
[NSCursor _windowResizeNorthWestSouthEastCursor]
[NSCursor _zoomInCursor]
[NSCursor _zoomOutCursor]
[NSCursor _helpCursor]
[NSCursor _copyDragCursor]
[NSCursor _genericDragCursor]
[NSCursor _handCursor]
[NSCursor _closedHandCursor]
[NSCursor _moveCursor]
[NSCursor _waitCursor]
[NSCursor _crosshairCursor]
[NSCursor _horizontalResizeCursor]
[NSCursor _verticalResizeCursor]
[NSCursor _bottomLeftResizeCursor]
[NSCursor _topLeftResizeCursor]
[NSCursor _bottomRightResizeCursor]
[NSCursor _topRightResizeCursor]
[NSCursor _resizeLeftCursor]
[NSCursor _resizeRightCursor]
[NSCursor _resizeLeftRightCursor]
like image 25
Anton Holmberg Avatar answered Nov 15 '22 07:11

Anton Holmberg


WebKit contains images that look exactly the same as the cursors used by the system, in the following directory:

/System/Library/Frameworks/WebKit.framework/Versions/Current/Frameworks/WebCore.framework/Resources/

...for example, the file "northWestSouthEastResizeCursor.png".

like image 24
Kevin Grant Avatar answered Nov 15 '22 09:11

Kevin Grant