[comp.sys.mac.programmer] animated cursors

baulac@imag.imag.fr (Yves Baulac) (10/23/90)

How to get easily these nice animated watch cursors.I notice that the Finder has
a resource of type 'acur' where the different cursors IDs are specified. What I
don't know and couldn't find in tech. notes is how to use these 'acur'
resources.
Thank's a lot.
-- 
baulac@imag.imag.fr     LSDD-IMAG Campus BP 53X - 38041 GRENOBLE Cedex   France
Yves BAULAC   Telephone: (33) 76 51 45 54    Fax: (33) 76 51 45 55

oster@well.sf.ca.us (David Phillip Oster) (10/26/90)

In article <14469@imag.imag.fr> baulac@imag.fr (Yves Baulac) writes:
>How to get easily these nice animated watch cursors.I notice that the Finder has
>a resource of type 'acur' where the different cursors IDs are specified. 
Call InitCursors(); early in your program.
Call SpinCursor(1); periodically in your program. 
SpinCursor(-1) spins backwards.

You might want to wrap
SpinCursor(1); in a function to guarantee that SpinCursor(1); will not be
called more frequently than 3 times a second. I wrote these.

/* CursorList - these resources define the animated cursor data structure
 */
typedef union UHand {
	CursHandle h;
	struct {
		short i;
		short fill;
	} i;
} UHand;

typedef struct CursorList {
	short cnt;
	short current;
	UHand curs[1];
} CursorList, *CursorPList, **CursorHList;

/* InitCursors - initialize our anuimated cursor structure
 */
void InitCursors(){
	CursHandle h;
	short i;

	if(NIL != (acurs = (CursorHList) GetResource('acur', 0))){
		for(i = 0; i < (**acurs).cnt; i++){
			h = (CursHandle) GetCursor((**acurs).curs[i].i.i);
			HNoPurge((Handle) h);
			(**acurs).curs[i].h = h;
		}
	}
}

/* SpinCursor - transit the cursor to the next in the series. 
	SpinCursor(1) spins forward
	SpinCursor(-1) spins backward
 */
void SpinCursor(delta)short delta;{
	short c;

	if(acurs != NIL){
		c = (**acurs).current + delta;
		if(c >= (**acurs).cnt){
			c = 0;
		}else if(c < 0){
			c = (**acurs).cnt-1;
		}
		(**acurs).current = c;
		SetCursor( *((**acurs).curs[c].h) );
	}
}
-- 
-- David Phillip Oster - Note new signature. Old one has gone Bye Bye.
-- oster@well.sf.ca.us = {backbone}!well!oster

oster@well.sf.ca.us (David Phillip Oster) (10/26/90)

Whoops, the preceding code also needs one global variable:
/* globals 
 */
CursorHList	acurs = NIL;		/* used in SpinCursor */

-- 
-- David Phillip Oster - Note new signature. Old one has gone Bye Bye.
-- oster@well.sf.ca.us = {backbone}!well!oster