#include "MainMenu.h"
#include "..\DXFunctions\FontManager.h"
#include "..\GameGUI\MenuManager.h"

#include "ShadowApp.h"
#include "ShadowScene.h"

MainMenu::MainMenu(MenuManager* const pManager, ShadowApp* const pApp) : Menu(pManager, 0)
{
	m_pApp = pApp;

	m_pnBack = new Panel(GetManager(), 1534);
	m_pnBack->SetPosition(-3, 85);
	m_pnBack->SetSize(250, 500);
	m_pnBack->SetOpacity(0.8f);
	m_pnBack->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_pnBack->SetAlphaBlend(true);
	m_pnBack->SetFixedBorder(4);

	AddChild(m_pnBack);


	FontParam fp;
	fp.m_Height = 16;
	Font* font = GetManager()->GetDevice()->GetFontManager()->Create(fp);

	Label *lbscene = new Label(GetManager(), 2);
	lbscene->SetPosition(10, 15);
	lbscene->SetSize(100, 20);
	lbscene->SetText("Scene: ");
	lbscene->SetFont(font);

	m_pnBack->AddChild(lbscene);

	m_rbTerrain = new RadioButton(GetManager(), 33);
	m_rbTerrain->SetPosition(75, 17);
	m_rbTerrain->SetSize(100, 19);
	m_rbTerrain->SetText("Terrain");
	m_rbTerrain->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\rb.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\rbc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_rbTerrain->SetAlphaBlend(true);
	m_rbTerrain->SetChecked(m_pApp->GetSceneIndex() == 0);
	m_rbTerrain->SetFont(font);
	m_rbTerrain->SetEventHandler(GE_VALUECHANGED, OnTerrainChanged);

	m_pnBack->AddChild(m_rbTerrain);

	m_rbPowerPlant = new RadioButton(GetManager(), 34);
	m_rbPowerPlant->SetPosition(145, 17);
	m_rbPowerPlant->SetSize(100, 19);
	m_rbPowerPlant->SetText("PowerPlant");
	m_rbPowerPlant->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\rb.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\rbc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_rbPowerPlant->SetAlphaBlend(true);
	m_rbPowerPlant->SetChecked(m_pApp->GetSceneIndex() == 1);
	m_rbPowerPlant->SetFont(font);
	m_rbPowerPlant->SetEventHandler(GE_VALUECHANGED, OnPowerPlantChanged);

	m_pnBack->AddChild(m_rbPowerPlant);

	m_ckUseLispSM = new CheckBox(GetManager(), 2);
	m_ckUseLispSM->SetPosition(10, 165);
	m_ckUseLispSM->SetSize(100, 20);
	m_ckUseLispSM->SetChecked(m_pApp->GetLispSMEnabled());
	m_ckUseLispSM->SetText("Use LispSM [F2]");
	m_ckUseLispSM->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ckc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_ckUseLispSM->SetAlphaBlend(true);
	m_ckUseLispSM->SetFont(font);
	m_ckUseLispSM->SetEventHandler(GE_VALUECHANGED, OnLispSMCheck);

	m_pnBack->AddChild(m_ckUseLispSM);


	m_ckDrawObjects = new CheckBox(GetManager(), 2);
	m_ckDrawObjects->SetPosition(10, 190);
	m_ckDrawObjects->SetSize(100, 20);
	m_ckDrawObjects->SetChecked(m_pApp->GetDrawObjects());
	m_ckDrawObjects->SetText("Draw Objects");
	m_ckDrawObjects->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ckc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_ckDrawObjects->SetAlphaBlend(true);
	m_ckDrawObjects->SetFont(font);
	m_ckDrawObjects->SetEventHandler(GE_VALUECHANGED, OnDrawObjectsCheck);

	m_pnBack->AddChild(m_ckDrawObjects);


	m_ckUpdateDynamicObjects = new CheckBox(GetManager(), 2);
	m_ckUpdateDynamicObjects->SetPosition(10, 215);
	m_ckUpdateDynamicObjects->SetSize(100, 20);
	m_ckUpdateDynamicObjects->SetChecked(m_pApp->GetUpdateDynamicObjects());
	m_ckUpdateDynamicObjects->SetText("Update Daynamic Objects");
	m_ckUpdateDynamicObjects->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ckc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_ckUpdateDynamicObjects->SetAlphaBlend(true);
	m_ckUpdateDynamicObjects->SetFont(font);
	m_ckUpdateDynamicObjects->SetEventHandler(GE_VALUECHANGED, OnDrawUpdateDynamicObjectsCheck);

	m_pnBack->AddChild(m_ckUpdateDynamicObjects);


	m_ckWireframe = new CheckBox(GetManager(), 24);
	m_ckWireframe->SetPosition(10, 265);
	m_ckWireframe->SetSize(100, 20);
	m_ckWireframe->SetChecked(m_pApp->GetDrawWireframe());
	m_ckWireframe->SetText("Wireframe [F8]");
	m_ckWireframe->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ckc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_ckWireframe->SetAlphaBlend(true);
	m_ckWireframe->SetFont(font);
	m_ckWireframe->SetEventHandler(GE_VALUECHANGED, OnWireframeCheck);

	m_pnBack->AddChild(m_ckWireframe);


	m_ckShowSM = new CheckBox(GetManager(), 24);
	m_ckShowSM->SetPosition(10, 290);
	m_ckShowSM->SetSize(100, 20);
	m_ckShowSM->SetChecked(m_pApp->GetShowSM());
	m_ckShowSM->SetText("Show ShadowMap [F3]");
	m_ckShowSM->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ckc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_ckShowSM->SetAlphaBlend(true);
	m_ckShowSM->SetFont(font);
	m_ckShowSM->SetEventHandler(GE_VALUECHANGED, OnShowSMCheck);

	m_pnBack->AddChild(m_ckShowSM);


	m_ckUseDebugCam = new CheckBox(GetManager(), 24);
	m_ckUseDebugCam->SetPosition(10, 365);
	m_ckUseDebugCam->SetSize(100, 20);
	m_ckUseDebugCam->SetChecked(m_pApp->GetUseDebugCam());
	m_ckUseDebugCam->SetText("Use Debug Cam [c]");
	m_ckUseDebugCam->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ckc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_ckUseDebugCam->SetAlphaBlend(true);
	m_ckUseDebugCam->SetFont(font);
	m_ckUseDebugCam->SetEventHandler(GE_VALUECHANGED, OnUseDebugCamCheck);

	m_pnBack->AddChild(m_ckUseDebugCam);


	m_ckUseID = new CheckBox(GetManager(), 24);
	m_ckUseID->SetPosition(10, 340);
	m_ckUseID->SetSize(100, 20);
	m_ckUseID->SetChecked(m_pApp->GetUseIDBuffer());
	m_ckUseID->SetText("ID Buffer");
	m_ckUseID->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ckc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_ckUseID->SetAlphaBlend(true);
	m_ckUseID->SetFont(font);
	m_ckUseID->SetEventHandler(GE_VALUECHANGED, OnUseIDCheck);

	m_pnBack->AddChild(m_ckUseID);

	m_ckUsePrimID = new CheckBox(GetManager(), 24);
	m_ckUsePrimID->SetPosition(150, 340);
	m_ckUsePrimID->SetSize(100, 20);
	m_ckUsePrimID->SetChecked(m_pApp->GetUsePrimID());
	m_ckUsePrimID->SetText("Prim ID");
	m_ckUsePrimID->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ckc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_ckUsePrimID->SetAlphaBlend(true);
	m_ckUsePrimID->SetFont(font);
	m_ckUsePrimID->SetEventHandler(GE_VALUECHANGED, OnUsePrimIDCheck);

	m_pnBack->AddChild(m_ckUsePrimID);


	m_ckUseSSAO = new CheckBox(GetManager(), 24);
	m_ckUseSSAO->SetPosition(10, 390);
	m_ckUseSSAO->SetSize(100, 20);
	m_ckUseSSAO->SetChecked(m_pApp->GetUseSSAO());
	m_ckUseSSAO->SetText("SSAO");
	m_ckUseSSAO->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ckc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_ckUseSSAO->SetAlphaBlend(true);
	m_ckUseSSAO->SetFont(font);
	m_ckUseSSAO->SetEventHandler(GE_VALUECHANGED, OnUseSSAO);

	m_pnBack->AddChild(m_ckUseSSAO);

	m_ckSMFiltering = new CheckBox(GetManager(), 24);
	m_ckSMFiltering->SetPosition(10, 415);
	m_ckSMFiltering->SetSize(100, 20);
	m_ckSMFiltering->SetChecked(m_pApp->GetSMFiltering());
	m_ckSMFiltering->SetText("SM Filtering");
	m_ckSMFiltering->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ckc.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_ckSMFiltering->SetAlphaBlend(true);
	m_ckSMFiltering->SetFont(font);
	m_ckSMFiltering->SetEventHandler(GE_VALUECHANGED, OnSMFiltering);

	m_pnBack->AddChild(m_ckSMFiltering);
	

	m_btnResetCam = new Button(GetManager(), 43);
	m_btnResetCam->SetCaption("Reset Cam");
	m_btnResetCam->SetFont(font);
	m_btnResetCam->SetSize(105, 32);
	m_btnResetCam->SetFixedBorder(4);
	m_btnResetCam->SetPosition(10, 445);
	m_btnResetCam->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_btnResetCam->SetAlphaBlend(true);
	m_btnResetCam->SetEventHandler(GE_BUTTONCLICK, OnResetCam);

	m_pnBack->AddChild(m_btnResetCam);


	m_btnReloadShaders = new Button(GetManager(), 43);
	m_btnReloadShaders->SetCaption("Reload Shaders");
	m_btnReloadShaders->SetFont(font);
	m_btnReloadShaders->SetSize(106, 32);
	m_btnReloadShaders->SetFixedBorder(4);
	m_btnReloadShaders->SetPosition(125, 445);
	m_btnReloadShaders->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\ck.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_btnReloadShaders->SetAlphaBlend(true);
	m_btnReloadShaders->SetEventHandler(GE_BUTTONCLICK, OnReloadShaders);

	m_pnBack->AddChild(m_btnReloadShaders);


	Label* lbConstBias = new Label(m_pApp->GetMenuManager(), 0);
	lbConstBias->SetSize(110, 20);
	lbConstBias->SetPosition(10, 90);
	lbConstBias->SetFont(font);
	lbConstBias->SetText("Const Bias:");

	m_pnBack->AddChild(lbConstBias);

	m_lbConstBias = new Label(m_pApp->GetMenuManager(), 0);
	m_lbConstBias->SetUserData(this);
	m_lbConstBias->SetSize(40, 20);
	m_lbConstBias->SetPosition(60, 90);
	m_lbConstBias->SetFont(font);
	m_lbConstBias->SetText("x.xx");
	m_lbConstBias->SetTextAlign(AL_RIGHTBOTTOM);

	m_pnBack->AddChild(m_lbConstBias);

	m_slConstBias = new Slider(m_pApp->GetMenuManager(), 345);
	m_slConstBias->SetUserData(this);
	m_slConstBias->SetPosition(100, 92);
	m_slConstBias->SetSize(130, 20);
	m_slConstBias->SetRange(0, 40);
	m_slConstBias->SetSliderSize(10, 20, 20, 10);
	m_slConstBias->SetTexture(m_pApp->GetDevice()->GetTextureManager()->CreateTexture("GUI\\slider.png", FMT_A8R8G8B8, POOL_MANAGED), 
					m_pApp->GetDevice()->GetTextureManager()->CreateTexture("GUI\\nob.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_slConstBias->SetAlphaBlend(true);

	m_pnBack->AddChild(m_slConstBias);
	m_slConstBias->SetEventHandler(GE_VALUECHANGED, OnConstBiasChanged);
	m_slConstBias->SetValue((int)(m_pApp->GetConstBias() * 20));


	Label* lbSlopeBias = new Label(m_pApp->GetMenuManager(), 0);
	lbSlopeBias->SetSize(110, 20);
	lbSlopeBias->SetPosition(10, 115);
	lbSlopeBias->SetFont(font);
	lbSlopeBias->SetText("Slope Bias:");

	m_pnBack->AddChild(lbSlopeBias);

	m_lbSlopeBias = new Label(m_pApp->GetMenuManager(), 0);
	m_lbSlopeBias->SetUserData(this);
	m_lbSlopeBias->SetSize(40, 20);
	m_lbSlopeBias->SetPosition(60, 115);
	m_lbSlopeBias->SetFont(font);
	m_lbSlopeBias->SetText("x.xx");
	m_lbSlopeBias->SetTextAlign(AL_RIGHTBOTTOM);

	m_pnBack->AddChild(m_lbSlopeBias);

	m_slSlopeBias = new Slider(m_pApp->GetMenuManager(), 345);
	m_slSlopeBias->SetUserData(this);
	m_slSlopeBias->SetPosition(100, 117);
	m_slSlopeBias->SetSize(130, 20);
	m_slSlopeBias->SetRange(0, 40);
	m_slSlopeBias->SetSliderSize(10, 20, 20, 10);
	m_slSlopeBias->SetTexture(m_pApp->GetDevice()->GetTextureManager()->CreateTexture("GUI\\slider.png", FMT_A8R8G8B8, POOL_MANAGED), 
					m_pApp->GetDevice()->GetTextureManager()->CreateTexture("GUI\\nob.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_slSlopeBias->SetAlphaBlend(true);

	m_pnBack->AddChild(m_slSlopeBias);
	m_slSlopeBias->SetEventHandler(GE_VALUECHANGED, OnSlopeBiasChanged);
	m_slSlopeBias->SetValue((int)(m_pApp->GetSlopeBias() * 10));


	Label* lbLambertScale = new Label(m_pApp->GetMenuManager(), 0);
	lbLambertScale->SetSize(110, 20);
	lbLambertScale->SetPosition(10, 140);
	lbLambertScale->SetFont(font);
	lbLambertScale->SetText("Lambert:");

	m_pnBack->AddChild(lbLambertScale);

	m_lbLambertScale = new Label(m_pApp->GetMenuManager(), 0);
	m_lbLambertScale->SetUserData(this);
	m_lbLambertScale->SetSize(40, 20);
	m_lbLambertScale->SetPosition(60, 140);
	m_lbLambertScale->SetFont(font);
	m_lbLambertScale->SetText("x.xx");
	m_lbLambertScale->SetTextAlign(AL_RIGHTBOTTOM);

	m_pnBack->AddChild(m_lbLambertScale);

	m_slLambertScale = new Slider(m_pApp->GetMenuManager(), 345);
	m_slLambertScale->SetUserData(this);
	m_slLambertScale->SetPosition(100, 142);
	m_slLambertScale->SetSize(130, 20);
	m_slLambertScale->SetRange(0, 20);
	m_slLambertScale->SetSliderSize(10, 20, 20, 10);
	m_slLambertScale->SetTexture(m_pApp->GetDevice()->GetTextureManager()->CreateTexture("GUI\\slider.png", FMT_A8R8G8B8, POOL_MANAGED), 
					m_pApp->GetDevice()->GetTextureManager()->CreateTexture("GUI\\nob.png", FMT_A8R8G8B8, POOL_MANAGED));
	m_slLambertScale->SetAlphaBlend(true);

	m_pnBack->AddChild(m_slLambertScale);
	m_slLambertScale->SetEventHandler(GE_VALUECHANGED, OnLambertScaleChanged);
	m_slLambertScale->SetValue((int)(m_pApp->GetLambertScale() * 20));

	//combo boxes, add them last so that drop down is always on top

	/*Label *lbjitter = new Label(GetManager(), 2);
	lbjitter->SetPosition(10, 170);
	lbjitter->SetSize(100, 20);
	lbjitter->SetText("Jitter Type: ");
	lbjitter->SetFont(font);
	
	m_pnBack->AddChild(lbjitter);


	m_cbJitterType = new ComboBox(GetManager(), 12344);
	m_cbJitterType->SetPosition(120, 170);
	m_cbJitterType->SetSize(100, 22);
	m_cbJitterType->SetDropDownHeight(102);
	m_cbJitterType->SetDropDownItemHeight(19);
	m_cbJitterType->AddItem("None");
	m_cbJitterType->AddItem("Halton");
	m_cbJitterType->AddItem("Random");
	m_cbJitterType->AddItem("Rotation");
	m_cbJitterType->AddItem("LispSM N");
	m_cbJitterType->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\input.png", FMT_A8R8G8B8, POOL_MANAGED), false, 3, 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\combo.png", FMT_A8R8G8B8, POOL_MANAGED), true,
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\list.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\listsel.png", FMT_A8R8G8B8, POOL_MANAGED), false, 4);
	m_cbJitterType->SetTextColor(D3DXCOLOR(0,0,0,1), D3DXCOLOR(1,1,1,1));
	m_cbJitterType->SetFont(font);
	m_cbJitterType->SetClientBorder(5);
	m_cbJitterType->SetSelectedIndex(m_pApp->GetJitterType());
	m_cbJitterType->SetEventHandler(GE_VALUECHANGED, OnJitterTypeChanged);

	m_pnBack->AddChild(m_cbJitterType);*/

	Label *lbwpt = new Label(GetManager(), 2);
	lbwpt->SetPosition(10, 315);
	lbwpt->SetSize(100, 20);
	lbwpt->SetText("WorldPosType:");
	lbwpt->SetFont(font);
	
	m_pnBack->AddChild(lbwpt);

	m_cbWPT = new ComboBox(GetManager(), 12344);
	m_cbWPT->SetPosition(120, 315);
	m_cbWPT->SetSize(105, 22);
	m_cbWPT->SetDropDownHeight(67);
	m_cbWPT->SetDropDownItemHeight(19);
	m_cbWPT->AddItem("Depth");
	m_cbWPT->AddItem("LinearDepth");
	m_cbWPT->AddItem("WorldPos");
	m_cbWPT->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\input.png", FMT_A8R8G8B8, POOL_MANAGED), false, 3, 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\combo.png", FMT_A8R8G8B8, POOL_MANAGED), true,
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\list.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\listsel.png", FMT_A8R8G8B8, POOL_MANAGED), false, 4);
	m_cbWPT->SetTextColor(D3DXCOLOR(0,0,0,1), D3DXCOLOR(1,1,1,1));
	m_cbWPT->SetFont(font);
	m_cbWPT->SetClientBorder(5);
	m_cbWPT->SetSelectedIndex((int)m_pApp->GetWorldPosType());
	m_cbWPT->SetEventHandler(GE_VALUECHANGED, OnWPTChanged);

	m_pnBack->AddChild(m_cbWPT);


	Label *lbvis = new Label(GetManager(), 2);
	lbvis->SetPosition(10, 240);
	lbvis->SetSize(100, 20);
	lbvis->SetText("Visualization: ");
	lbvis->SetFont(font);
	
	m_pnBack->AddChild(lbvis);

	m_cbVisType = new ComboBox(GetManager(), 12344);
	m_cbVisType->SetPosition(120, 240);
	m_cbVisType->SetSize(100, 22);
	m_cbVisType->SetDropDownHeight(160);
	m_cbVisType->SetDropDownItemHeight(19);
	m_cbVisType->AddItem("None");
	m_cbVisType->AddItem("Sample");
	m_cbVisType->AddItem("Pass");
	m_cbVisType->AddItem("FinalConf");
	m_cbVisType->AddItem("OptConf");
	m_cbVisType->AddItem("ID");
	m_cbVisType->AddItem("SSAO");
	m_cbVisType->AddItem("ReqRes");
	m_cbVisType->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\input.png", FMT_A8R8G8B8, POOL_MANAGED), false, 3, 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\combo.png", FMT_A8R8G8B8, POOL_MANAGED), true,
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\list.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\listsel.png", FMT_A8R8G8B8, POOL_MANAGED), false, 4);
	m_cbVisType->SetTextColor(D3DXCOLOR(0,0,0,1), D3DXCOLOR(1,1,1,1));
	m_cbVisType->SetFont(font);
	m_cbVisType->SetClientBorder(5);
	m_cbVisType->SetSelectedIndex((int)m_pApp->GetVisType());
	m_cbVisType->SetEventHandler(GE_VALUECHANGED, OnVisTypeChanged);

	m_pnBack->AddChild(m_cbVisType);


	Label* lbsmsize =new Label(GetManager(), 0);
	lbsmsize->SetSize(110, 20);
	lbsmsize->SetPosition(10, 65);
	lbsmsize->SetFont(font);
	lbsmsize->SetText("ShadowMap Size:");

	m_pnBack->AddChild(lbsmsize);


	m_cbSMSize = new ComboBox(GetManager(), 12344);
	m_cbSMSize->SetPosition(120, 65);
	m_cbSMSize->SetSize(100, 22);
	m_cbSMSize->SetDropDownHeight(102);
	m_cbSMSize->SetDropDownItemHeight(19);
	m_cbSMSize->AddItem("512");
	m_cbSMSize->AddItem("1024");
	m_cbSMSize->AddItem("2048");
	m_cbSMSize->AddItem("4096");
	m_cbSMSize->AddItem("8192");
	m_cbSMSize->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\input.png", FMT_A8R8G8B8, POOL_MANAGED), false, 3, 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\combo.png", FMT_A8R8G8B8, POOL_MANAGED), true,
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\list.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\listsel.png", FMT_A8R8G8B8, POOL_MANAGED), false, 4);
	m_cbSMSize->SetTextColor(D3DXCOLOR(0,0,0,1), D3DXCOLOR(1,1,1,1));
	m_cbSMSize->SetFont(font);
	m_cbSMSize->SetClientBorder(5);
	m_cbSMSize->SetSelectedIndex(logn(2, m_pApp->GetSMSize() >> 9));
	m_cbSMSize->SetEventHandler(GE_VALUECHANGED, OnSMSizeChanged);

	m_pnBack->AddChild(m_cbSMSize);


	Label* lbshmethod =new Label(GetManager(), 0);
	lbshmethod->SetSize(110, 20);
	lbshmethod->SetPosition(10, 40);
	lbshmethod->SetFont(font);
	lbshmethod->SetText("Shadow Method:");

	m_pnBack->AddChild(lbshmethod);


	m_cbShadowMethod = new ComboBox(GetManager(), 12344);
	m_cbShadowMethod->SetPosition(120, 40);
	m_cbShadowMethod->SetSize(100, 22);
	m_cbShadowMethod->SetDropDownHeight(122);
	m_cbShadowMethod->SetDropDownItemHeight(19);
	m_cbShadowMethod->AddItem("Common");
	m_cbShadowMethod->AddItem("Deferred");
	m_cbShadowMethod->AddItem("Confidence");
	m_cbShadowMethod->AddItem("Z-Tiled");
	m_cbShadowMethod->AddItem("SS-Tiled");
	m_cbShadowMethod->AddItem("SM-Tiled");
	m_cbShadowMethod->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\input.png", FMT_A8R8G8B8, POOL_MANAGED), false, 3, 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\combo.png", FMT_A8R8G8B8, POOL_MANAGED), true,
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\list.png", FMT_A8R8G8B8, POOL_MANAGED), 
					GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\listsel.png", FMT_A8R8G8B8, POOL_MANAGED), false, 4);
	m_cbShadowMethod->SetTextColor(D3DXCOLOR(0,0,0,1), D3DXCOLOR(1,1,1,1));
	m_cbShadowMethod->SetFont(font);
	m_cbShadowMethod->SetClientBorder(5);
	m_cbShadowMethod->SetSelectedIndex((int)m_pApp->GetShadowMethod());
	m_cbShadowMethod->SetEventHandler(GE_VALUECHANGED, OnShadowMethodChanged);

	m_pnBack->AddChild(m_cbShadowMethod);


	//Slider *sl = new Slider(GetManager(), 100);
	//sl->SetPosition(10,160);
	//sl->SetSize(200, 30);
	//sl->SetSliderSize(12, 25, 25, 12);
	//sl->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\slider.png", FMT_A8R8G8B8, POOL_MANAGED), 
	//				GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\nob.png", FMT_A8R8G8B8, POOL_MANAGED));
	//sl->SetAlphaBlend(true);

	//AddChild(sl);


	//ListBox* lb = new ListBox(GetManager(), 1123);
	//lb->SetPosition(10, 190);
	//lb->SetSize(200, 105);
	//lb->SetItemHeight(21);
	//lb->SetTexture(GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\list.png", FMT_A8R8G8B8, POOL_MANAGED), 
	//				GetManager()->GetDevice()->GetTextureManager()->CreateTexture("GUI\\listsel.png", FMT_A8R8G8B8, POOL_MANAGED), false, 3);
	//lb->SetFont(font);
	//lb->AddItem("This");
	//lb->AddItem("is");
	//lb->AddItem("a");
	//lb->AddItem("ListBox");
	//lb->SetClientBorder(5);
	//lb->SetSelectedIndex(2);

	//AddChild(lb);


}

MainMenu::~MainMenu(void)
{
}

void MainMenu::OnUpdate(void)
{
	if (m_pApp->m_SelectBench)
		return;

	if (GetManager()->GetInputDevice()->GetKey(DIK_F8) & KEY_UP)
		m_ckWireframe->SetChecked(!m_ckWireframe->IsChecked());
		
	if (GetManager()->GetInputDevice()->GetKey(DIK_C) & KEY_UP)
		m_ckUseDebugCam->SetChecked(!m_ckUseDebugCam->IsChecked());

	if (GetManager()->GetInputDevice()->GetKey(DIK_F3) & KEY_UP)
		m_ckShowSM->SetChecked(!m_ckShowSM->IsChecked());

	if (GetManager()->GetInputDevice()->GetKey(DIK_F2) & KEY_UP)
		m_ckUseLispSM->SetChecked(!m_ckUseLispSM->IsChecked());

	if (GetManager()->GetInputDevice()->GetKey(DIK_R) & KEY_UP)
		OnResetCam(m_btnResetCam, GE_BUTTONCLICK, NULL);

	if (GetManager()->GetInputDevice()->GetKey(DIK_BACK) & KEY_UP)
		OnReloadShaders(m_btnReloadShaders, GE_BUTTONCLICK, NULL);

	if (GetManager()->GetInputDevice()->GetKey(DIK_T) & KEY_UP)
	{
		int mth = m_pApp->GetShadowMethod() + 1;
		if (mth >= SM_COUNT)
			mth = 0;
		m_cbShadowMethod->SetSelectedIndex((SHMETHOD)mth);
	}
	else if (GetManager()->GetInputDevice()->GetKey(DIK_G) & KEY_UP)
	{
		int mth = m_pApp->GetShadowMethod() - 1;
		if (mth < 0)
			mth = SM_COUNT - 1;
		m_cbShadowMethod->SetSelectedIndex((SHMETHOD)mth);
	}
}

void MainMenu::OnLispSMCheck(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	CheckBox* ck = dynamic_cast<CheckBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m && ck)
	{
		m->m_pApp->SetLispSMEnabled(ck->IsChecked());
	}
}

void MainMenu::OnDrawObjectsCheck(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	CheckBox* ck = dynamic_cast<CheckBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m && ck)
	{
		m->m_pApp->SetDrawObjects(ck->IsChecked());
	}
}

void MainMenu::OnDrawUpdateDynamicObjectsCheck(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	CheckBox* ck = dynamic_cast<CheckBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m && ck)
	{
		m->m_pApp->SetUpdateDynamicObjects(ck->IsChecked());
	}
}
	
void MainMenu::OnWireframeCheck(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	CheckBox* ck = dynamic_cast<CheckBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m && ck)
	{
		m->m_pApp->SetDrawWireframe(ck->IsChecked());
	}
}

void MainMenu::OnShowSMCheck(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	CheckBox* ck = dynamic_cast<CheckBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m && ck)
	{
		m->m_pApp->SetShowSM(ck->IsChecked());
	}
}

void MainMenu::OnUseDebugCamCheck(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	CheckBox* ck = dynamic_cast<CheckBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m && ck)
	{
		m->m_pApp->SetUseDebugCam(ck->IsChecked());
	}
}

void MainMenu::OnUseIDCheck(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	CheckBox* ck = dynamic_cast<CheckBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m && ck)
	{
		m->m_pApp->SetUseIDBuffer(ck->IsChecked());
	}
}

void MainMenu::OnUsePrimIDCheck(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	CheckBox* ck = dynamic_cast<CheckBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m && ck)
	{
		m->m_pApp->SetUsePrimID(ck->IsChecked());
	}
}

void MainMenu::OnUseSSAO(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	CheckBox* ck = dynamic_cast<CheckBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m && ck)
	{
		m->m_pApp->SetUseSSAO(ck->IsChecked());
	}
}

void MainMenu::OnSMFiltering(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	CheckBox* ck = dynamic_cast<CheckBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m && ck)
	{
		m->m_pApp->SetSMFiltering(ck->IsChecked());
	}
}

void MainMenu::OnResetCam(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m)
	{
		m->m_pApp->GetActiveScene()->ResetCam();
	}
}

void MainMenu::OnReloadShaders(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());
	
	if (m)
	{
		m->m_pApp->ReloadShaders();
	}
}

void MainMenu::OnTerrainChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	RadioButton* rb = dynamic_cast<RadioButton*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());

	if (m && rb && rb->IsChecked())
	{
		m->m_pApp->SetScene(0);
	}
}

void MainMenu::OnPowerPlantChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	RadioButton* rb = dynamic_cast<RadioButton*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());

	if (m && rb && rb->IsChecked())
	{
		m->m_pApp->SetScene(1);
	}
}

void MainMenu::OnShadowMethodChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	ComboBox* cb = dynamic_cast<ComboBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());

	if (m && cb && cb->GetSelectedIndex() >= 0)
	{
		m->m_pApp->SetShadowMethod((SHMETHOD)cb->GetSelectedIndex());
	}
}

void MainMenu::OnSMSizeChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	ComboBox* cb = dynamic_cast<ComboBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());

	if (m && cb && cb->GetSelectedIndex() >= 0)
	{
		int pow = cb->GetSelectedIndex();
		int size = 1 << (pow + 9);
		m->m_pApp->SetSMSize(size);
	}
}

/*void MainMenu::OnJitterTypeChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	ComboBox* cb = dynamic_cast<ComboBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());

	if (m && cb && cb->GetSelectedIndex() >= 0)
	{
		m->m_pApp->SetJitterType((SMJITTERTYPE)cb->GetSelectedIndex());
	}
}*/

void MainMenu::OnVisTypeChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	ComboBox* cb = dynamic_cast<ComboBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());

	if (m && cb && cb->GetSelectedIndex() >= 0)
	{
		m->m_pApp->SetVisType((VISTYPE)cb->GetSelectedIndex());
	}
}

void MainMenu::OnWPTChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	ComboBox* cb = dynamic_cast<ComboBox*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());

	if (m && cb && cb->GetSelectedIndex() >= 0)
	{
		m->m_pApp->SetWorldPosType((DSWORLDPOSTYPE)cb->GetSelectedIndex());
	}
}

void MainMenu::OnConstBiasChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	Slider* sl = dynamic_cast<Slider*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());

	if (m && sl)
	{
		float bias = sl->GetValue() / 20.0f;
		m->m_lbConstBias->SetText(XString(bias));
		m->m_pApp->SetConstBias(bias);
	}
}

void MainMenu::OnSlopeBiasChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	Slider* sl = dynamic_cast<Slider*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());

	if (m && sl)
	{
		float bias = sl->GetValue() / 10.0f;
		m->m_lbSlopeBias->SetText(XString(bias));
		m->m_pApp->SetSlopeBias(bias);
	}
}

void MainMenu::OnLambertScaleChanged(GUIElement* const sender, const GUIEVENT evnt, void* pData)
{
	Slider* sl = dynamic_cast<Slider*>(sender);
	MainMenu* m = dynamic_cast<MainMenu*>(sender->GetParent()->GetParent());

	if (m && sl)
	{
		float scale = sl->GetValue() / 20.0f;
		m->m_lbLambertScale->SetText(XString(scale));
		m->m_pApp->SetLambertScale(scale);
	}
}