#pragma once
//===========================================================================//
// File:	 Pane.hpp														 //
// Project:  GOSScript				                                         //
// Contents: Representation of bitmap in 3D environment						 //
//---------------------------------------------------------------------------//
// Date      Who    Modification                                             //
// 07/31/98  JTR    Created													 //
//																			 //
//---------------------------------------------------------------------------//
// Copyright (C) 2000 Microsoft Corp.						                 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

struct Quad;
struct PaneTextures;
struct PaneTextureList;
struct SharedTextureRect;
struct SharedTexture;
class gos_Pane;

typedef struct
{
	float x;
	float y;
	float z;
} FPOSITION;



struct PaneTextures
{
	PaneTextures*	pNext;
	DWORD			Handle;
};

struct PaneTextureList
{
	PaneTextures *	pListStart;
	Quad *			m_pListOfQuads;
	int				hasAlpha;
	HGOSSURFACE		hSurf;
	DWORD			m_height; 
	DWORD			m_width;
	int				refCount;
	PaneTextureList * pNext;
	char			LongFileName[1];
};

struct SharedTextureRect
{
	int				top;
	int				left;
	int				width;
	int				height;
	enum { free, parent_h, parent_v, used } status;
	SharedTextureRect *pParent;
	SharedTextureRect *pChild1;
	SharedTextureRect *pChild2;
	SharedTexture *pSharedTexture;
};

struct SharedTexture
{
	SharedTextureRect *pRootRect;
	DWORD			totalFreeTexels;
	SharedTexture * pNext;
	SharedTexture ** pPrev_pNext;	// pointer to pNext from previous entry or start of list pointer
	DWORD			texture;
};

struct Quad
{
	gos_VERTEX v[4];
	Quad * pNext;
	DWORD texture;
	SharedTextureRect *pSharedRect;	// If this is NULL, this is not a SharedTextureRect
	WORD width;
	WORD height;
};

class gos_Pane 
{
	public:
		unsigned long 
			m_latticeX,
			m_latticeY,
			m_color;

		gos_AlphaMode 
			m_alphaMode;

		float 
			currentScaleX,
			currentScaleY;

		FPOSITION
			currentOffset,
			currentTranslation,
			currentRotation;


		HGOSVIDEO hVideo;
		DWORD hVideoTexture;

		PaneTextureList*	m_pTextureList;
		bool				m_fIsVolatile;

	public:
		gos_Pane(HGOSSURFACE surf, int alpha, bool volit);
		gos_Pane(char * name);
		gos_Pane(char * name, int alpha, bool volit);
		gos_Pane(int w, int h, int alpha, bool volit);
		~gos_Pane();
		void Render(int x, int y);
		void Update();
		HGOSSURFACE GetSurface(){return m_pTextureList->hSurf;}
		int GetWidth(){return m_pTextureList->m_width;}
		int GetHeight(){return m_pTextureList->m_height;}
		char * GetSurfacePath()
		{
			return m_pTextureList->LongFileName;
		}
		void PrepareTextures();
		void Texture(HGOSSURFACE surf);
		void Rotate(float x, float y, float z);
		void Scale(float x, float y, float z);
		void Translate(float x, float y, float z);
		void Origin(int x, int y, int z);
		void Wrap(float u, float v);
		void Color(DWORD color);
		void AlphaMode( enum gos_AlphaMode mode);
		void MakeQuads();
		bool NeedClip(float x, float y);

		// Movie Playback to the Pane
		void Play();
		void Loop();
		void Stop();


		DWORD AddTexture( DWORD Size );
		void AddQuad( DWORD X, DWORD Y, DWORD Width, DWORD Height, DWORD Texture, DWORD U, DWORD V, DWORD TextureSize, SharedTextureRect *pSharedRect = NULL );
		void AddSharedQuad( DWORD left, DWORD top, DWORD width, DWORD height );
		void FreeSharedQuad( SharedTextureRect *pQuad );
		void FillQuadRandom( SharedTextureRect *pQuad );

};


