Justin
Justin

Reputation: 2142

How to change the mouse cursor in Objective-C

I am making an image editing application, but it looks very incomplete without a cursor like they have in Photoshop for the paintbrush. How can I set the icon, and have it change back when I exit the application?

This is the code in my header file (just in case it's needed):

@interface test : NSWindow <NSWindowDelegate> {
    IBOutlet id myView;

}

@end

myView is an NSView (customView) that will display everything.

Upvotes: 0

Views: 6798

Answers (2)

deovrat singh
deovrat singh

Reputation: 1215

If the drawing area is rectangular(NSTracking Areas are always rectangular) :- Use the mouseEntered,mouse Exited methods of NSTrackingArea to track and change the mouse cursor.The mouse cursor could be changed using NSCursor class.

If the tracking area is not rectangular then make a bigger rectangular tracking area enclosing the whole drawing region and then track the mouseMoved events inside the tracking area to set the cursor appropriately . Refer to apple documentation for more details.

Upvotes: 1

Dave DeLong
Dave DeLong

Reputation: 243146

There's a handy NSCursor class for handling cursor appearance. If one of the built-in cursors doesn't look how you need it to, you can initialize a new NSCursor with an NSImage and -set it to be the active cursor.

Upvotes: 9

Related Questions