unit cursorAnimation; { cursorAnimation } { Copyright © 1991 by Michael J. Gibbs, all rights reserved. } { } { This unit provides a class that can be used by applications that want to } { animate the cursor during lengthy operations. The class provides three } { methods to control the cursor's actions. } { } { iAnimatedCursor initializes a new animated cursor object and is } { passed the resource ID of an animated cursor resource } { ('acur'). The default minimum interval between } { animation frames is set to 15 ticks. } { animateCursor called repeatedly during lengthy operations, animtate-} { Cursor displays the next frame in the animation } { sequence. } { setCursorInterval sets the minimum interval between frames of the } { animation. This allows the application to call } { animateCursor without concern for flickering of the } { cursor due to changing frames too quickly. The } { interval is set in ticks. } { } { 9109091318 M. Gibbs: initial release } interface uses objIntf, Quickdraw, Resources; type acurType = packed record numFrames: integer; frames: array[0..255] of longint; end; acurPtr = ^acurType; acurHandle = ^acurPtr; CAnimatedCursor = object(TObject) cursors: acurHandle; { handle to acur resource } currentFrame: integer; { index of current frame } lastTime: longint; { system clock at last frame change } minInterval: integer; { minimum frame interval } procedure iAnimatedCursor (aCursorID: integer); { initialize object } procedure animateCursor; { advance to next frame } procedure setCursorInterval (minTime: integer); { set min frame time } end; implementation const defaultInterval = 15; type cursorPtr = ^cursor; cursorHandle = ^cursorPtr; procedure CAnimatedCursor.iAnimatedCursor (aCursorID: integer); begin cursors := acurHandle(GetResource('acur', aCursorID)); currentFrame := 0; lastTime := 0; minInterval := defaultInterval; end; procedure CAnimatedCursor.animateCursor; var currentTime: longint; thisCursor: cursorHandle; begin currentTime := tickCount; if currentTime - lastTime > minInterval then begin lastTime := currentTime; thisCursor := cursorHandle(GetResource('CURS', cursors^^.frames[currentFrame])); SetCursor(thisCursor^^); currentFrame := (currentFrame + 1) mod cursors^^.numFrames; end; end; procedure CAnimatedCursor.setCursorInterval (minTime: integer); begin minInterval := minTime; end; end.