// main.h


#define		DEFAULT_FOV		80.0		// in degrees
#define		MIN_FOV			10.0
#define		MAX_FOV			140.0

#define		FOV_ZOOM_SPEED	40.0

#define		MOUSE_SENSITIVITY	1.8f

#define	SPRITE_WINDOW_RANGE	400			// sprite x,y coords go from 0,0 to n,n

#define	CUBE_FADE_SPEED		1.0f

#define	PI		M_PI

#define	MAX_INSTANCES		20


typedef struct
{
	GLfloat		x,y,z;
}Point3D;

typedef struct
{
	GLfloat		u,v;
}TextureUV;


enum									// web browser types
{
	BROWSER_SAFARI,
	BROWSER_FIREFOX,
	BROWSER_NETSCAPE,
	BROWSER_UNKNOWN
};

enum									// sprites
{
	SP_UIBAR,
	SP_ZOOMIN_OFF,
	SP_ZOOMIN_ON,
	SP_ZOOMOUT_OFF,
	SP_ZOOMOUT_ON,
	SP_MINIMIZE,
	SP_MAXIMIZE,
	SP_LOGO,
	SP_PREFS_OFF,
	SP_PREFS_ON,

	NUM_SPRITES
};


typedef struct
{
	Ptr		buffer;
	int		width, height;
	float	aspectRatio;
	GLuint	textureName;
}MySpriteType;


typedef struct
{
	Boolean		isUsed;						// true if this instance record is active and in use

	NPP			instance;	

#ifdef TARGET_OS_MAC
	CGrafPtr	grafPtr;
	WindowPtr	macWindow;
	AGLContext	drawContext;
	FSSpec		dataFileSpec;					
#endif	

	short		browserType;
	char		streamURL[1024];
	
	char		thumbnailFilename[255];
	Boolean		thumbnailLoaded;
	Ptr			thumbnailPixels;
	GLuint		thumbnailTexture;
	float		thumbnailScale;
	int			thumbShape;					// 1 = 1:1 square, 2 = 2:1 rectangle
	
	Str255		userString;
	float		userStringAlpha;
	int			fontSize;
	Boolean		fontLoaded;
	
	NPWindow	*npWindow;
	int			pluginPortX, pluginPortY;

	Boolean		srcfileQueued;				// true if there's a src file queued up since we got it before a draw context was created
	int			srcFileSize;
	int			bytesDownloaded;
	Boolean		drawLoadingBar, drawDecodingBar;
	int			decodeStep;					// 0..5, goes up once for each cube face decoded as we parse the .mov file

	int			maxTextureSizeH, maxTextureSizeV;
	float		fov;
	
	Boolean		doEquirectangular;					// set to true if using equirectangular image instead of quicktime mov file.
	
	float		cubeFade, loadingFade;
	float		cubeRotDX, cubeRotDY;
	float		cubeRotX, cubeRotY;
	float		minRotX, maxRotX;
	Boolean		autoPan;
	
	Boolean		doDragFriction;
	
	float		fps, oneOverFPS;
	
	int			paneWidth, paneHeight;
	Rect		paneClip;
	
	float		aspectRatio;
	GLuint		fontList;
	
	Boolean		texturesLoaded;
	GLuint		textureNames[8];
	Ptr			textureBuffers[8];
	GWorldPtr	textureGWorlds[8];
	int			textureWidth, textureHeight;
	
	MySpriteType	sprites[NUM_SPRITES];
	
	Boolean		hiliteZoomIn;
	Boolean		hiliteZoomOut;
	Boolean		hilitePrefsIcon;
	
	Boolean		minimizeController, showController, controllerMoved;
	float		controllerScale;
	float		controllerX;
	float		controllerDX;
	
	Boolean		nonPower2;					// set if OpenGL can do non-power of 2 textures
	Boolean		compressTextures;
	Boolean		disableCompression;
	
	int			frameCount;

}MyInstanceType;



			/* PREFS */
			
enum
{
	TEXTURE_COMP_MODE_ALWAYS = 1,
	TEXTURE_COMP_MODE_NEVER,
	TEXTURE_COMP_MODE_HTML
};			

enum
{
	DRAGFRIC_MODE_ALWAYS = 1,
	DRAGFRIC_MODE_NEVER,
	DRAGFRIC_MODE_HTML
};			
			
			
typedef struct
{
	Byte	compressionMode;
	Byte	dragFrictionMode;

	Byte	unused[100];
}PrefsType;


//============================================================================


			/* DEFINITIONS FOR NPP */
			
NPError		NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
NPError		NPP_Destroy(NPP instance, NPSavedData** save);
NPError		NPP_SetWindow(NPP instance, NPWindow* window);
NPError		NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype);
NPError		NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason);
int32		NPP_WriteReady(NPP instance, NPStream* stream);
int32		NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer);
void		NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
void		NPP_Print(NPP instance, NPPrint* platformPrint);
int16		NPP_HandleEvent(NPP instance, void* event);
void		NPP_URLNotify(NPP instance, const char* URL, NPReason reason, void* notifyData);
NPError		NPP_GetValue(void *instance, NPPVariable variable, void *value);
NPError		NPP_SetValue(void *instance, NPNVariable variable, void *value);
void		NP_Shutdown(void);


void CalcMaxTextureSizeForHardware(int instanceNum);
void InteractivelyDragCube(int instanceNum);
void OGL_InitDrawContext(int instanceNum);
void OGL_DrawScene(int instanceNum);
void Set2DSpriteState(int instanceNum);
void OGL_DisposeDrawContext(int instanceNum);
void OGL_DrawInt(int instanceNum, int f, GLint x, GLint y);
void OGL_DrawFloat(int instanceNum, float f, GLint x, GLint y);
void OGL_DrawString(int instanceNum, Str255 s, GLint x, GLint y);
void OGL_PushState(void);
void OGL_PopState(void);
GLenum OGL_CheckError(void);
OSErr ParseQTMovie(int instanceNum);
void DrawTheCube(int instanceNum);
void DrawTheSphere(int instanceNum);
void UpdateCubeDrift(int	instanceNum, Boolean doFriction);
void	CalcAllowedTextureSize(int instanceNum, Rect *sourceSize, Rect *allowedSize);
void LoadSpritesForInstance(int i);
void DoPrefsDialog(int instanceNum);
void InitDefaultPrefs(void);
OSErr LoadPrefs(void);
void SavePrefs(void);
GLint MakeTextureFromBuffer(Boolean nonPower2, Ptr buffer, int width, int height, Boolean hasAlpha, Boolean compressIt);
Boolean CheckClickOnControllerIcon(int i, float x, float y);
void LoadEquirectangularImage(int instanceNum);
void LoadThumbnail(int instanceNum, const char *urlPath);
int DownloadURL(const char *urlString, Handle	data);
OSStatus LaunchURL(ConstStr255Param urlStr);
Boolean IsMouseInPluginPane(int i, int x, int y);





#ifdef TARGET_OS_MAC

OSErr	OGL_CreateDrawContext_Mac(int instanceNum);
void SetPaneClipRect_Mac(int instanceNum);
void OGL_DisposeDrawContext_Mac(int instanceNum);
void CalcFramesPerSecond_Mac(int instanceNum);
void OGL_InitFont_Mac(int instanceNum);
void OGL_FreeFont_Mac(int instanceNum);
void OGL_DrawString_Mac(int instanceNum, Str255 s, GLint x, GLint y);
OSErr	JPEGToTexture_Mac(int instanceNum, int	i, Ptr image);
OSErr DrawTIFFIntoBuffer_Mac(FSSpec *myFSSpec, Ptr *buffer);
OSErr DrawJPEGFromRAMIntoBuffer_Mac(Ptr compressedData, int size, GWorldPtr *theGWorld, Ptr *buffer);
void CopyPixelsFromBufferToBuffer_Mac(GWorldPtr fromWorld, GWorldPtr toWorld, const Rect *fromRect, const Rect *toRect);
NPError DoPlatformSpecificInit_Mac(void);
void DoPlatformSpecificShutdown_Mac(void);
void HandleBrowserEvent_Mac(int i, void *event);
GLint ScaleTempImageToTexture_Mac(int instanceNum, GWorldPtr	gworld, Ptr	buffer, Rect *textureRect, Boolean compressTextures);


#endif


