- Inherits from:
- NSObject
- Conforms to:
- NSCoding
- NSObject (NSObject)
Declared in:
- AppKit/NSCursor.h
Instances of the NSCursor class manage the appearance of the cursor. When you initialize a cursor-the designated initializer is initWithImage:hotSpot:-you assign it a 16-by-16 pixel NSImage and a point to be the hot spot. The image is usually a small, opaque icon-for example, a pair of cross-hairs-surrounded by transparent pixels. The pixels in the cursor image are mapped on a flipped coordinate system: the upper left pixel is (0,0); the lower right is (15,15).
To determine exactly when the mouse is inside a particular cursor rectangle, the Application Kit tracks a single pixel in the cursor image. This pixel is known as the hot spot, and you can reference it using the hotSpot method. By definition, the location of the current cursor's hot spot is the location of the mouse; when the hot spot is inside a cursor rectangle, so is the mouse. The hot spot is useful not only for determining which cursor is current, but for determining where a mouse click should have its effect.
An NSCursor object is immutable: you cannot change its hot spot or image after it's created. Instead, use initWithImage:hotSpot: to create a new one with the new settings.
An application may use several cursor instances-for example, one that looks like an arrow and one that looks like an I-beam. The instance that currently appears on the screen is called the "current cursor," and is referenced by the currentCursor class method. You can set the current cursor in several ways:
The cursor rectangle is a region inside an NSView that triggers a change in the current cursor. To create a cursor rectangle, use the addCursorRect:cursor: method of NSView to associate a region of the view with the cursor, as shown in the following example:
[aView addCursorRect:aRect cursor:aCursor]; [aCursor setOnMouseEntered:YES];
This assignment means that when the mouse enters aRect, aCursor will receive a mouseEntered: event message, which the cursor uses to make itself the current cursor. However, before the cursor can acknowledge the mouseEntered: message, you must invoke the cursor's setOnMouseEntered: method. Alternatively, you can set the cursor when the mouse leaves the cursor rectangle by invoking the setOnMouseExited: method instead of setOnMouseEntered:. A cursor that sets itself upon leaving the cursor rectangle receives a mouseExited: event message to instigate the change.
The Application Kit provides two ready-made cursors for commonly used cursor images. You can retrieve these cursors by using the arrowCursor and IBeamCursor class methods. There is no NSCursor instance for the wait cursor, because the system automatically displays it at the appropriate times.
NSCoding
- - encodeWithCoder:
- - initWithCoder:
- Initializing a new cursor
- - initWithImage:hotSpot:
- - initWithImage:foregroundColorHint:backgroundColorHint:hotSpot:
- Setting cursor attributes
- - image
- - hotSpot
- + hide
- + unhide
- + setHiddenUntilMouseMoves:
- Controlling which cursor is current
- + pop
- - pop
- - push
- - set
- - mouseEntered:
- - setOnMouseEntered:
- - isSetOnMouseEntered
- - mouseExited:
- - setOnMouseExited:
- - isSetOnMouseExited
- Retrieving cursor instances
- + arrowCursor
- + currentCursor
- + IBeamCursor
+ (NSCursor *)arrowCursor
See Also: + IBeamCursor, + currentCursor, - hotSpot
+ (NSCursor *)currentCursor
See Also: - set, - push, + pop, - mouseEntered:, - mouseExited:
+ (void)hide
hide overrides setHiddenUntilMouseMoves:.
+ (NSCursor *)IBeamCursor
See Also: + arrowCursor, + currentCursor
+ (void)pop
See Also: - push
+ (void)setHiddenUntilMouseMoves:(BOOL)flag
trueYES
,
hides the cursor. The cursor remains invisible until:NO
Do not try to counter this method by invoking unhide. The results are undefined.
See Also: + hide
+ (void)unhide
See Also: + setHiddenUntilMouseMoves:, + hide
- (NSPoint)hotSpot
Note that an NSCursor object is immutable: you cannot change its hot spot after it's created. Instead, use initWithImage:hotSpot: to create a new cursor with the new settings.
See Also: - initWithImage:hotSpot:
- (NSImage *)image
nil
if none
exists.Note that an NSCursor object is immutable: you cannot change its image after it's created. Instead, use initWithImage:hotSpot: to create a new cursor with the new settings.
See Also: - initWithImage:hotSpot:
- (id)initWithImage:(NSImage
*)newImage
foregroundColorHint:(NSColor *)fg
backgroundColorHint:(NSColor *)bg
hotSpot:(NSPoint)hotSpot
See Also: - initWithImage:hotSpot:
- (id)initWithImage:(NSImage
*)newImage
hotSpot:(NSPoint)aPoint
See Also: - hotSpot, - image, - initWithImage:foregroundColorHint:backgroundColorHint:hotSpot:
- (BOOL)isSetOnMouseEntered
YES
if
the receiving cursor will become current when it receives a mouseEntered: message; otherwise,
returns NO
.To receive such a message, the receiver must first be assigned a cursor rectangle. This assignment can be made using NSView's addCursorRect:cursor: method. For a more complete explanation, see the class description.
See Also: - setOnMouseEntered:, - isSetOnMouseExited
- (BOOL)isSetOnMouseExited
YES
if
the receiving cursor becomes current when it receives a mouseExited: message; otherwise,
returns NO
. To receive such a message, the receiver must first be assigned a cursor rectangle. This assignment can be made using NSView's addCursorRect:cursor: method. For a more complete explanation, see the class description.
See Also: - setOnMouseExited:
- (void)mouseEntered:(NSEvent
*)anEvent
YES
, mouseEntered: can
make the receiver the current cursor.In your programs, you won't invoke mouseEntered: explicitly. It's only included in the class interface so you can override it.
For a more complete explanation, see the class description.
See Also: - isSetOnMouseEntered, - mouseExited:
- (void)mouseExited:(NSEvent
*)anEvent
See Also: - setOnMouseExited:, - isSetOnMouseExited
- (void)pop
- (void)push
- (void)set
See Also: + currentCursor
- (void)setOnMouseEntered:(BOOL)flag
YES
,
the cursor accepts future mouseEntered: event
messages, otherwise it ignores them. Accepting mouseEntered: event messages allows
the cursor to be made the current cursor when the mouse enters a
view's cursor rectangle.See Also: - mouseEntered:
- (void)setOnMouseExited:(BOOL)flag
YES
,
the cursor accepts future mouseExited: event
messages, otherwise it ignores them. Accepting mouseExited: event messages allows
the cursor to be made the current cursor when the mouse exits a
view's cursor rectangle.