[comp.sys.mac.programmer] acur resources and animating the cursor

kenk@sunHd.tellabs.com (Ken Konecki) (07/10/90)

Is there any documentation on how to use acur resources? I haven't
found anything in IMI-V (at least not in the indices) nor in the
tech notes index. Having poked around with resedit, I know what the
acur resource is, but have no idea how to use it to animate cursors,
except the brute force way of call SetCursor() with each frame in the
acur resource.

Thanks,
    -Ken K
--
Ken Konecki
"Eat well, stay fit, and die anyway"
e-mail:kenk@tellabs.com    -or-    ...!uunet!tellab5!kenk	
U.S. Mail: 1271 Portchester Circle, Carol Stream, IL 60188

keith@Apple.COM (Keith Rollin) (07/11/90)

In article <2966@tellab5.tellabs.com> kenk@sunHd.tellabs.com (Ken Konecki) writes:
>Is there any documentation on how to use acur resources? I haven't
>found anything in IMI-V (at least not in the indices) nor in the
>tech notes index. Having poked around with resedit, I know what the
>acur resource is, but have no idea how to use it to animate cursors,
>except the brute force way of call SetCursor() with each frame in the
>acur resource.

The Cursor Rotating routines are part of a library that comes with MPW.
Documentation for them is scarce, mostly taking form as comments in the
header/interface files. Here is the C version. This should have enough
information for you to create your own implementation.

/************************************************************

Created: Thursday, September 7, 1989 at 9:11 PM
	CursorCtl.h
	C Interface to the Macintosh Libraries


	
	<<< CursorCtl - Cursor Control Header File >>>
	
	Copyright Apple Computer, Inc. 1985-1989
	All rights reserved
	
	This file contains:
	
	InitCursorCtl(newCursors) - Init CursorCtl to load the 'acur' resource
	RotateCursor(counter)	  - Sequence through cursor frames for counter mod 32
	SpinCursor(increment)	  - Sequence mod 32 incrementing internal counter
	Hide_Cursor()			  - Hide the current cursor
	Show_Cursor(cursorKind)   - Show the cursor

************************************************************/


#ifndef __CURSORCTL__
#define __CURSORCTL__

enum {HIDDEN_CURSOR,I_BEAM_CURSOR,CROSS_CURSOR,PLUS_CURSOR,WATCH_CURSOR,
	ARROW_CURSOR};
typedef unsigned char Cursors;

struct Acur {
	short n;		/*Number of cursors ("frames of film")*/
	short index;	/* Next frame to show <for internal use>*/
	short frame1;	/*'CURS' resource id for frame #1*/
	short fill1;	/*<for internal use>*/
	short frame2;	/*'CURS' resource id for frame #2*/
	short fill2;	/*<for internal CursorCtl unit. This should be called once prior to calling
	RotateCursor or SpinCursor. It need not be called if only Hide_Cursor or
	Show_Cursor are used. If NewCursors is NULL, InitCursorCtl loads in the
	'acur' resource and the 'CURS' resources specified by the 'acur' resource
	ids.  If any of the resources cannot be loaded, the cursor will not be
	changed.
	
	The 'acur' resource is assumed to either be in the currently running tool or
	application, or the MPW Shell for a tool, or in the System file.  The 'acur'
	resource id must be 0 for a tool or application, 1 for the Shell, and 2 for
	the System file.
	
 then RotateCursor and SpinCursor will do the call for
	the user the first time it is called.  However, the possible disadvantage of
	using this technique is that the resource memory allocated may have
	undesirable affect (fragmentation?) on the application. Using InitCursorCtl
	has the advantage of causing the allocation at a specific time determined by
	the user.
	
	Caution: InitCursorCtl MODIFIES the 'acur' resource in memory.	Specifically,
	it changes each FrameN/fillN integer pair to a handle to the corresponding
	'CURS' resource also in memory.  Thus if NewCursors is not NULL when
	InitCursorCtl is called, the caller must guarantee NewCursors always points to
	a "fresh" copy of an 'acur' resource.  This need only be of concern to a
	caller who wants to repeatly use multiple 'acur' resources during execution of
	their programs.
*/

pascal void RotateCursor(long counter); 
/*
	RotateCursor is called to rotate the "I am active" "beach ball" cursor, or to
	animate whatever sequence of cursors set up by InitCursorCtl. The next cursor
	("frame") is used when Counter % 32 = 0 (Counter is some kind of incrementing
	or decrementing index maintained by the caller). A positive counter sequences
	forward through the cursors (e.g., it rotates the "beach ball" cursor
	clockwise), and a negative cursor sequences through the cursors backwards
	(e.g., it rotates the "beach ball" cursor counterclockwise).  Note,
	RotateCursor just does a Mac SetCursor call for the proper curd to a counter maintained
	here.  SpinCursor is provided for those users who do not happen to have a
	convenient counter handy but still want to use the spinning "beach ball"
	cursor, or any sequence of cursors set up by InitCur increment resets the counter to zero.  Note, it is the increment, and
	not the value of the counter that determines the sequencing direction of the
	cursor (and hence the spin direction of the "beach ball" cursor).
*/

pascal void Hide_Cursor(void);
/*
	Hide the cursor if it is showing.This is this unit's call to the Mac
	HideCursor routine.Thus the Mac cursor level is decremented by one when this
	routine is called.
*/

pascal void Show_Cursor(Cursors cursorKind);
/*
	Increment the cursor level, which may have been decremented by Hide_Cursor,
	and display the specified cursor if the level becomes 0 (it is never
	incremented beyond 0).The CursorKind is the kind of cursor to show.  It is
	one of the values HIDDEN_CURSOR, I_BEAM_CURSOR, CROSS_CURSOR, PLUS_CURSOR,
	WATCH_CURSOR, and ARROW_CURSOR. Except for HIDDEN_CURSOR, a Mac SetCursor is
	done for the specified cursor prior to doing a ShowCursor.	HIDDEN_CURSOR just
	causes a ShowCursor call.  Note, ARROW_CURSOR will only work correctly if
	there is already a grafPort set up pointed to by 0(A5).
*/
#ifdef __cplusplus
}
#endif

#endif

-- 
------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc.  ---  Developer Technical Support
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions

kenk@tellabs.com (Ken Konecki) (07/13/90)

In article <42857@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes:
|The Cursor Rotating routines are part of a library that comes with MPW.
|Documentation for them is scarce, mostly taking form as comments in the
|header/interface files. Here is the C version. This should have enough
|information for you to create your own implementation.

I'm assuming from the last statement that there's only an MPW
implementation. Does anybody know if there's a ThinkC implementation?

Thanks,
    -Ken K
--
Ken Konecki
"Eat well, stay fit, and die anyway"
e-mail:kenk@tellabs.com    -or-    ...!uunet!tellab5!kenk	
U.S. Mail: 1271 Portchester Circle, Carol Stream, IL 60188

keith@Apple.COM (Keith Rollin) (07/16/90)

>In article <42857@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes:
>|The Cursor Rotating routines are part of a library that comes with MPW.
>|Documentation for them is scarce, mostly taking form as comments in the
>|header/interface files. Here is the C version. This should have enough
>|information for you to create your own implementation.

Before someone corrects me on this, I better mention that the Cursor
Rotating routines are indeed documented to a greater extent in Appendix
F of the MPW 3.0 Reference. Not that that helps people who don't have
MPW much, but I did want to paint a more accurate picture. I'm 0 for 2
over in the Munger threads...

-- 
------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc.  ---  Developer Technical Support
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions

oster@well.sf.ca.us (David Phillip Oster) (07/18/90)

Enclosed is a complete subroutine package to animate your cursors using
acurs resources.
I am the author.

/* 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;

/* globals 
 */
CursorHList	acurs = NIL;		/* used in SpinCursor */
short		deltaCursor = 0;	/* used in LSPINT, RSPINIT macros */

/* InitCursors - initialize our anuimated cursor structure
 */
public 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);
			MoveHHi((Handle) h);
			HLock((Handle) h);
			(**acurs).curs[i].h = h;
		}
	}
}

/* SpinCursor - transit the cursor to the next in the series.
	delta should be 1 to go forward,
	-1 to go backward
 */
public 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 address. Old one has gone Bye Bye.
-- oster@well.sf.ca.us = {backbone}!well!oster