- Inherits from:
- NSObject
- Package:
- com.apple.yellow.application
Instances of the NSCursor class manage the appearance of the cursor. When you initialize a cursor, 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 a constructor 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 method of NSView to associate a region of the view with the cursor, as shown in the following example:
aView.addCursorRect(aRect, aCursor); aCursor.setOnMouseEntered(true);
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 static methods. There is no NSCursor instance for the wait cursor, because the system automatically displays it at the appropriate times.
- Constructors
- NSCursor
- 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
public NSCursor()
public NSCursor(
NSImage newImage,
NSPoint aPoint)
public NSCursor(
NSImage newImage,
NSColor fg,
NSColor bg,
NSPoint hotSpot)
public static NSCursor arrowCursor()
See Also: IBeamCursor, currentCursor, hotSpot
public static NSCursor currentCursor()
See Also: set, push, pop, mouseEntered, mouseExited
public static void hide()
hide overrides setHiddenUntilMouseMoves.
public static NSCursor IBeamCursor()
See Also: arrowCursor, currentCursor
public static void popCursor()
See Also: push
public static void setHiddenUntilMouseMoves(boolean flag)
trueYES
,
hides the cursor. The cursor remains invisible until:false
Do not try to counter this method by invoking unhide. The results are undefined.
See Also: hide
public static void unhide()
See Also: setHiddenUntilMouseMoves, hide
public NSPoint hotSpot()
Note that an NSCursor object is immutable: you cannot change its hot spot after it's created. Instead, use a constructor to create a new cursor with the new settings.
public NSImage image()
null
if none
exists.Note that an NSCursor object is immutable: you cannot change its image after it's created. Instead, use a constructor to create a new cursor with the new settings.
public boolean isSetOnMouseEntered()
true
if
the receiving cursor will become current when it receives a mouseEntered message; otherwise,
returns false
.To receive such a message, the receiver must first be assigned a cursor rectangle. This assignment can be made using NSView's addCursorRect method. For a more complete explanation, see the class description.
See Also: setOnMouseEntered, isSetOnMouseExited
public boolean isSetOnMouseExited()
true
if
the receiving cursor becomes current when it receives a mouseExited message; otherwise,
returns false
. To receive such a message, the receiver must first be assigned a cursor rectangle. This assignment can be made using NSView's addCursorRect method. For a more complete explanation, see the class description.
See Also: setOnMouseExited
public void mouseEntered(NSEvent anEvent)
true
, 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
public void mouseExited(NSEvent anEvent)
See Also: setOnMouseExited, isSetOnMouseExited
public void pop()
public void push()
public void set()
See Also: currentCursor
public void setOnMouseEntered(boolean flag)
true
,
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
public void setOnMouseExited(boolean flag)
true
,
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.