#pragma once

#include "dllinterface.h"
#include "..\dxfunctions\dllinterface.h"
#include "..\dxfunctions\devicestatemanager.h"
#include "..\dxfunctions\difunctions.h"
#include "..\Utilities\list.h"
#include "..\dxfunctions\BufferManager.h"
#include "..\dxfunctions\DXVector4.h"

class Menu;
class Label;
class Image;
class Panel;
class Console;
class GUIElement;

class GAMEGUI_API MenuManager
{
	DeviceStateManager*	m_Device;
	CDIFunctions*		m_InputDevice;
	//SoundDevice*		m_SoundDevice;
	Console*			m_Console;

	ShaderEffect*		m_Shader;
	LPDIRECT3DVERTEXDECLARATION9 m_VDeclTex;
	LPDIRECT3DVERTEXDECLARATION9 m_VDeclColor;

	DynamicVB*			m_VB;
	DynamicIB*			m_IB;
	
	LList<GUIElement>	m_CreatedElements;

	LList<Menu>			m_Menus;

	GUIElement*			m_MouseOver;
	MOUSEBUTTON			m_DragButton;
	GUIElement*			m_DragStart;

protected:
	friend GUIElement;

	void AddElement(GUIElement* const guiel);

public:

	struct TexVertex
	{		
		DXVector4 pos;
		float u,v;
	};

	struct ColorVertex
	{
		DXVector4 pos;
	};


	//MenuManager(DeviceStateManager *device,CDIFunctions* inputdevice,SoundDevice* sounddevice);
	MenuManager(DeviceStateManager *device,CDIFunctions* inputdevice);
	~MenuManager(void);

	DeviceStateManager* GetDevice(void){return m_Device;}
	CDIFunctions* GetInputDevice(void){return m_InputDevice;}
	//SoundDevice* GetSoundDevice(void){return m_SoundDevice;}
	
	void Update(void);
	void Draw(void);

	void DeleteElement(GUIElement* const guiel);

//	void Invalidate(void){m_VB.invalidate();}
//	void Restore(void){m_VB.restore();}

	void AddMenu(Menu*m);
	void RemoveMenu(Menu*m);

	LList<Menu>* GetMenus(void){return &m_Menus;}

	Console* GetConsole(void){return m_Console;}
	void SetConsole(Console*console);

	DynamicVB* GetVB(void) const { return m_VB; }
	DynamicIB* GetIB(void) const { return m_IB; }

	ShaderEffect* GetShader(void)const{return m_Shader;}
	void SetupRenderTex(const bool AlphaTest, const bool AlphaBlend, const DXTexture* Texture);
	void SetupRenderColor(const bool AlphaTest, const bool AlphaBlend, const D3DXCOLOR &Color);

	GUIElement* GetMouseOverElement(void) const { return m_MouseOver; }
	GUIElement* GetDragStartElement(void) const { return m_DragStart; }
};
