Pixmap cursors
Pixmap cursors are created by specifying two pixmaps: a shape pixmap and a mask pixmap. The pixmaps must both have a depth of 1 (that is, 1 bit per pixel). The mask pixmap specifies at which pixels the cursor is opaque. Where the mask pixmap is 0, the background shows through. Where it is 1, the shape pixmap specifies the color of the pixel. Where the shape pixmap is 1, the foreground color (black) is used. Where it is 0, the background color (white) is used. A mask pixmap of
nil specifies that the cursor is opaque at all pixels. For more information on creating and using pixmaps, see
"Using pixmaps".
In the following example, a CgPixmap is created by sending the createBitmapFromData:width:height: message to the drawable. Then this CgPixmap object is sent the createPixmapCursor:x:y: or createPixmapCursor:foregroundColor:backgroundColor:x:y: message. Parameters passed to this method include an optional mask pixmap, and the x- and y-coordinates of the cursor's hot spot. The hot spot is the point at which the cursor is centered over the current pointer coordinates.
The following code creates and displays a pixmap cursor with the shape of a small black rectangle with a transparent interior. The cursor's hot spot is in the center of the rectangle. Note that, in this case, the same pixmap is used both for the mask and to define the shape.
| window data pixmap cursor |
window := self shell window.
"Create the cursor."
data := #
2r11111111
2r10000001
2r10000001
2r10000001
2r10000001
2r10000001
2r10000001
2r11111111].
pixmap := window
createBitmapFromData: data
width: 8
height: 8.
cursor := pixmap
createPixmapCursor: pixmap
x: 4
y: 4.
pixmap freePixmap.
"Display the cursor."
window defineCursor: cursor.
(Delay forSeconds: 5) wait.
window undefineCursor.
cursor freeCursor
Last modified date: 04/18/2020