/***************************************************************************
 * MOUSEPOINTER.C
 * This file contains all the stuff involved with generating the custom
 * mousepointer used when the ruler is being shown.
 ***************************************************************************/

#include <intuition/intuition.h>
#include <functions.h>
#include <stdio.h>


USHORT pointer_image[] =	/* MAY HAVE TO BE IN CHIP MEMORY!		*/
{
	0x0000, 0x0000,			/* The first 2 words must be zero.		*/
	0x0080, 0x0000,			/* The next 8 pairs form the vert. bar	*/
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0000, 0x0000,
	0x0080, 0x7EBF,			/* The horizontal bars and hot spot.	*/
	0x0000, 0x0000,
	0x0080, 0x0000,			/* The next 8 pairs form the vert. bar	*/
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0080, 0x0000,
	0x0000, 0x0000,			/* The last 4 words must be zero.	*/
	0x0000, 0x0000
};							/* end of pointer image data.		*/

#define MPTRSIZE sizeof(pointer_image)


/*--------------------------------------------------------------------------*
 * This struct mirrors a chunk of the Window struct that describes the 
 * Mouse Pointer. It is used to save the original Host pointer parameters
 * before we call SetPointer() to install our own pointer image.
 *--------------------------------------------------------------------------*/

struct Mpointer
{
	USHORT	*Pointer;				/* Image data							*/
	BYTE	Height;					/* number of scan lines.				*/
	BYTE	Width;					/* in pixels. Must be <= 16 			*/
	BYTE	Xoffset, Yoffset;		/* Location of Hot Spot within sprite	*/
};

struct Mpointer Host_pointer;		/* For saving original Host data		*/

struct Mpointer	Leach_pointer =		/* Data for Leach pointer image.		*/
{
	pointer_image,
	(MPTRSIZE / 4) - 4,
	16,
	-9, -9
};

extern struct Window	*HostWind;


/****************************************************************************
 * This function saves the Host's mouse pointer data, then activates its
 * own pointer by calling the Intuition function SetPointer().
 ****************************************************************************/

set_pointer()
{

Host_pointer.Pointer	= HostWind->Pointer;
Host_pointer.Height		= HostWind->PtrHeight;
Host_pointer.Width		= HostWind->PtrWidth;
Host_pointer.Xoffset	= HostWind->XOffset;
Host_pointer.Yoffset	= HostWind->YOffset;

SetPointer(HostWind, Leach_pointer.Pointer, (long) Leach_pointer.Height, 
			  (long) Leach_pointer.Width,   (long) Leach_pointer.Xoffset, 
											(long) Leach_pointer.Yoffset ); 

return;

} /*  End of set_pointer()  */


/****************************************************************************
 * This simple function restores the Host's mouse pointer data, by calling 
 * the Intuition function SetPointer(). Note that no harm is done if this
 * gets called when the Default is already the current one.
 ****************************************************************************/

restore_pointer()
{

if ( Host_pointer.Pointer)	/* If the Host had a custom pointer, restore it */
{
	SetPointer(HostWind, Host_pointer.Pointer,	(long) Host_pointer.Height, 
				  (long) Host_pointer.Width,	(long) Host_pointer.Xoffset, 
												(long) Host_pointer.Yoffset );
}
else						/* Reactivate the default Intuition pointer.	*/
{
	ClearPointer(HostWind);
}
return;

} /* End of restore_pointer()  */ 
