Cursor Animation
Volume Number: 7
Issue Number: 3
Column Tag: C Workshop
Related Info: Vert. Retrace Mgr
Animated Color Cursors 
By Richard Lesh, Bridgeton, MO
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
Animated Color Cursors
[Richard Lesh is a free-lance programmer who has been programming in C since
1983 and has been doing development on the Macintosh for the past four years. He has
done work in a number of fields including numerical methods and analysis, computer
graphics, artificial intelligence and neural networks. You can contact him on AppleLink
at CALICO or through INTERNET at CALICO@APPLELINK.APPLE.COM]
Since the introduction of HyperCard, more and more programs have been
sporting animated cursors. Using animated cursors is an attractive way to provide
visual feedback to the user that the computer is diligently working on a time consuming
task. The standard wrist watch cursor does not provide this type of dynamic feedback to
assure the user that things are proceeding normally. This article will present a new
method of implementing animated cursors that supports both monochrome and color
cursors. Also presented is a simple demo program that exercises the cursor control
routines using a number of monochrome and color cursors.
In the past there have been two approaches to implementing animated cursors.
The first type is seen in HyperCard, the Finder and in the MPW library cursor control
routines. Using this technique, the programmer simply intersperses frequent calls to a
routine that sets the cursor to the next cursor in the animation sequence. It typically
results in cursor animation that is not smooth, i.e. jerky. The second and less popular
method is to set up a VBL task that changes the cursor at a constant rate, thus providing
smooth animation. More about these techniques and VBL tasks will be presented later in
this article. Both of these techniques have shortcomings that the technique presented
here attempts to overcome.
As a general rule of thumb, there are a number of issues that any animated
cursor technique should address:
1. It should provide feedback that the computer is executing a task normally.
2. It should provide smooth animation of the cursor.
3. It should support both monochrome (CURS) and color (crsr) cursors.
Each of these issues will now be discussed and the methodology for addressing
each will be presented.
Visual Feedback
The primary reason for using animated cursors is to give some reassuring
feedback to the user that everything is proceeding normally during a lengthy task that
otherwise would not provide visual feedback. In order to set up a sequence of animated
cursors, one must first create separate cursor resources for each ‘frame’ of the
animation. Each ‘frame’ differs slightly from the next and when displayed in rapid
succession they give the illusion of motion. Figure 1 shows an example of the
monochrome (CURS) Beach Ball cursor resources commonly seen in HyperCard.
Figure 1. Beach Ball cursors (CURS)
In addition to creating the necessary cursor resources, a resource must be
created to store the information about the sequencing of the cursor ‘frames’. This
resource is supported by the latest versions of ResEdit and is given the type name
‘acur’ (animated cursor). Figure 2 shows the ‘acur’ resource, as displayed by
ResEdit, needed to animate the Beach Ball cursors.
The ‘acur’ resource contains a count of the number of cursor resources in the
animation sequence followed by the resource IDs of the cursors in the order that they
will appear in the sequence. The counter ‘Number of “Frames”’ is not maintained
automatically for you; you must make sure to update it after adding additional cursor
‘frames’. To insert new ‘frames’ in the resource one merely selects the ‘*****’
string and then chooses ‘Insert New Field’ from the Resource menu in ResEdit to insert
a space for the new cursor resource ID. The “Frame Counter” field is simply a filler
and its value is unimportant. This value will, however, be used to keep track of the
current frame after the ‘acur’ resource has been loaded and the cursor animation
begins.
Smooth Animation
MPW and HyperCard both use a cursor animation method that requires the
execution of specific commands to cause the animation to proceed to the next frame. In
the MPW cursor control library these functions are called SpinCursor() and
RotateCursor(). Each are similar in function but take different arguments. In
HyperCard, the command ‘set cursor to busy’ performs the same function. This
technique requires the programmer to sprinkle cursor commands generously
throughout the code of a function that may cause a noticeable delay to the user. Not only
does this destroy the readability of a code segment but it is difficult in practice to space
the calls to SpinCursor() or RotateCursor() at appropriate locations that will generate
smooth animation of the cursor. It is more common for the cursor to display somewhat