#ifndef _MACINPUT_H_
#define _MACINPUT_H_

/**> HEADER FILES <**/
#include <stdlib.h>
#include <stdio.h>
#include <InputSprocket.h>
#include <drawsprocket.h>
#include <Devices.h>
#include <Dialogs.h>
#include <DriverServices.h>
#include <Events.h>
#include <TextEdit.h>
#include <ToolUtils.h>
#include <Windows.h>
#include <LowMem.h>

#include <math.h>
#include <string.h>
#include <agl.h>


#include <gl.h>
#include <glu.h>							// Header File For The GLu32 Library



/**> CONSTANT DECLARATIONS <**/
// Mac Keyboard Codes
#define	MAC_1_KEY					0x12
#define	MAC_2_KEY					0x13
#define	MAC_3_KEY					0x14
#define	MAC_4_KEY					0x15
#define	MAC_5_KEY					0x17
#define	MAC_6_KEY					0x16
#define	MAC_7_KEY					0x1A
#define	MAC_8_KEY					0x1C
#define	MAC_9_KEY					0x19
#define	MAC_0_KEY					0x1D
#define	MAC_A_KEY					0x00
#define	MAC_B_KEY					0x0B
#define	MAC_C_KEY					0x08
#define	MAC_D_KEY					0x02
#define	MAC_E_KEY					0x0E
#define	MAC_F_KEY					0x03
#define	MAC_G_KEY					0x05
#define	MAC_H_KEY					0x04
#define	MAC_I_KEY					0x22
#define	MAC_J_KEY					0x26
#define	MAC_K_KEY					0x28
#define	MAC_L_KEY					0x25
#define	MAC_M_KEY					0x2E
#define	MAC_N_KEY					0x2D
#define	MAC_O_KEY					0x1F
#define	MAC_P_KEY					0x23
#define	MAC_Q_KEY					0x0C
#define	MAC_R_KEY					0x0F
#define	MAC_S_KEY					0x01
#define	MAC_T_KEY					0x11
#define	MAC_U_KEY					0x20
#define	MAC_V_KEY					0x09
#define	MAC_W_KEY					0x0D
#define	MAC_X_KEY					0x07
#define	MAC_Y_KEY					0x10
#define	MAC_Z_KEY					0x06
#define	MAC_F1_KEY					0x7A
#define	MAC_F2_KEY					0x78
#define	MAC_F3_KEY					0x63
#define	MAC_F4_KEY					0x76
#define	MAC_F5_KEY					0x60
#define	MAC_F6_KEY					0x61
#define	MAC_F7_KEY					0x62
#define	MAC_F8_KEY					0x64
#define	MAC_F9_KEY					0x65
#define	MAC_F10_KEY					0x6D
#define	MAC_F11_KEY					0x67
#define	MAC_F12_KEY					0x6F
#define	MAC_RETURN_KEY				0x24
#define	MAC_ENTER_KEY				0x4C
#define	MAC_TAB_KEY					0x30
#define	MAC_SPACE_KEY				0x31
#define	MAC_DELETE_KEY				0x33
#define	MAC_ESCAPE_KEY				0x35
#define	MAC_COMMAND_KEY				0x37
#define	MAC_SHIFT_KEY				0x38
#define	MAC_CAPS_LOCK_KEY			0x39
#define	MAC_OPTION_KEY				0x3A
#define	MAC_CONTROL_KEY				0x3B
#define	MAC_PAGE_UP_KEY				0x74
#define	MAC_PAGE_DOWN_KEY			0x79
#define	MAC_ARROW_UP_KEY			0x7E
#define	MAC_ARROW_DOWN_KEY			0x7D
#define	MAC_ARROW_LEFT_KEY			0x7B
#define	MAC_ARROW_RIGHT_KEY			0x7C


#undef	MIN
#undef	MAX
#define MIN(a,b)        (((a)<(b)) ? (a) : (b))
#define MAX(a,b)        (((a)>(b)) ? (a) : (b))

#define M_PI			3.14159265358979323846

#define RAD_TO_DEG		(180/M_PI)
#define DEG_TO_RAD		(M_PI/180)


struct structGLInfo // storage for setup info
{
	GLint aglAttributes[64]; 	// input: pixel format attributes always required
	AGLPixelFormat	fmt;		// input: none; output pixel format...
	int freq;					// input: frequency request for display; output: actual
};
typedef struct structGLInfo structGLInfo;
typedef struct structGLInfo * pstructGLInfo;

// structure fro creating a context from a window
struct structGLWindowInfo // storage for setup info
{
	GLint aglAttributes[64]; 	// input: pixel format attributes always required
	AGLPixelFormat	fmt;		// input: none; output pixel format...
	Boolean fDraggable;			// input: is window going to be dragable, 
								//        if so renderer check (accel, VRAM, textureRAM) will look at all 
								//			renderers vice just the current one
								//        if window is not dragable renderer check will either check the 
								//			single device or short 
								//			circuit to software if window spans multiple devices 
								//        	software renderer is consider to have unlimited VRAM, unlimited 
								//			textureRAM and to not be accelerated
};
typedef struct structGLWindowInfo structGLWindowInfo;
typedef struct structGLWindowInfo * pstructGLWindowInfo;


/**> GLOBAL VARIABLES <**/
//extern ISpElementReference		gInputElements[kNumInputs];
extern GLfloat 	vertices [822][3];
extern GLint 		indices [956][4];


extern int 			iNumVert, sNumVert;

extern Boolean 		gQuit, pDone;
extern Boolean		movingForward;
extern Boolean		movingBackward;
extern Boolean		movingLeft;
extern Boolean		movingRight;
extern Boolean		cRotate;
extern Boolean		sideways;
extern float		cameraX, cameraY, cameraZ, Azimuth;

extern WindowPtr 	gpWindow;
extern Rect 		rectWin;
extern AGLContext 	aglContext;
extern GLuint 		gFontList;
extern char 		gstrContext [256];
extern structGLWindowInfo 	glInfo;


static enum
{
	kNumRes = 10,
	kNumFreqs = 11,

	kMenuApple = 128,
	kMenuFile = 129,

	kAppleAbout = 1,
	kFileQuit = 1
};



/**************** FUNCTION PROTOTYPES ****************/

/* Function Prototyps within MacInput.cpp */
Boolean	IsKeyDown( unsigned char *keyMap, unsigned short theKey );


/* Function Prototyps within GL World */
void 		InitToolbox(void);
Boolean 	SetUpWindow (void);

void 		HandleMouseDown(EventRecord *event );
void		HandleKeyDown( EventRecord *event );
void 		DoDSEvent( EventRecord *event );

void 		DoMenu (SInt32 menuResult);
void 		UpdateWorld (WindowPtr pWindow);
void 		EventDSLoop (void);
void 		CleanUp (void);

void 		DrawGLScene(WindowPtr pWindow, AGLContext aglContext, GLuint fontList);
int 		InitGL(GLvoid);
void 		SetupObjcts();

void 		DrawFrameRate (GLuint fontList);
void		DrawMessages (GLuint fontList);
void 		DrawContextInfo (GLuint fontList);

void		DrawPStringGL (Str255 pstrOut, GLuint fontList);
void		DrawCStringGL (char * cstrOut, GLuint fontList);
GLuint 		BuildFontGL (AGLContext ctx, GLint fontID, Style face, GLint size);
void 		DeleteFontGL (GLuint fontList);


static OSStatus 	BuildDrawable (AGLDrawable* paglDraw, GDHandle hGD, pstructGLInfo pcontextInfo);
static OSStatus 	BuildGLonDrawable (AGLDrawable aglDraw, AGLContext* paglContext, 
						pstructGLWindowInfo pcontextInfo);
Boolean 			PreflightGL (Boolean checkFullscreen);
OSStatus 			BuildGL (AGLDrawable* paglDraw, AGLContext* paglContext, DSpContextReference* pdspContext, 
						  short* pnumDevice, pstructGLInfo pcontextInfo);
OSStatus 			DestroyGL (AGLDrawable* paglDraw, AGLContext* paglContext, DSpContextReference* pdspContext, 
						pstructGLInfo pcontextInfo);
OSStatus 			BuildGLFromWindow (AGLDrawable aglDraw, AGLContext* paglContext, 
						pstructGLWindowInfo pcontextInfo);
OSStatus 			DestroyGLFromWindow (AGLContext* paglContext, pstructGLWindowInfo pcontextInfo);
OSStatus 			PauseGL (AGLContext aglContext);
OSStatus 			ResumeGL (AGLDrawable aglDraw, AGLContext aglContext);


void 				CameraManip();

#endif
