// LightPanel.cpp : implementation file
//

#include "stdafx.h"
#include "mw4gameed2.h"
#include "LightPanel.h"
#include "GUILight.h"
#include "refresher.h"
#include "ColorDlgProDlg.h"


/////////////////////////////////////////////////////////////////////////////
// CLightPanel dialog


CLightPanel::CLightPanel(GUILight *gobj,UndoCommand **cmd,CWnd* pParent)
	: CPanelDlg(CLightPanel::IDD, pParent)
{
	MyObj=gobj;
	CmdLst=cmd;
	OldIntensity=MyObj->GetIntensity();
	OldColor=MyObj->GetColor();
	ColDlg=NULL;
	//{{AFX_DATA_INIT(CLightPanel)
	m_Intensity = 0.0f;
	//}}AFX_DATA_INIT
}


void CLightPanel::DoDataExchange(CDataExchange* pDX)
{
	CPanelDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLightPanel)
	DDX_Control(pDX, IDC_LIGHTCOLOR, m_ColBut);
	DDX_Text(pDX, IDC_INTENSITY, m_Intensity);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLightPanel, CPanelDlg)
	//{{AFX_MSG_MAP(CLightPanel)
	ON_BN_CLICKED(IDC_LIGHTCOLOR, OnLightcolor)
	ON_EN_CHANGE(IDC_INTENSITY, OnChangeIntensity)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLightPanel message handlers

void CLightPanel::OnOK() 
{
UpdateData(TRUE);

	MyObj->SetIntensity(m_Intensity);
	MyObj->SetColor(m_ColBut.GetRGBColor());

}

void CLightPanel::OnCancel() 
{
	MyObj->SetIntensity(OldIntensity);
	MyObj->SetColor(OldColor);
}


BOOL CLightPanel::OnInitDialog() 
{
	CPanelDlg::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_ColBut.SetColor(MyObj->GetColor());
	m_Intensity=MyObj->GetIntensity();

UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLightPanel::OnLightcolor() 
{
ColDlg=new CColorDlgProDlg(&m_ColBut.Color,this);

	if(ColDlg->DoModal()==IDOK)
	{
	m_ColBut.SetColor(ColDlg->m_Color);
	}
UpdateGame();
delete ColDlg;
ColDlg=NULL;
}

void CLightPanel::UpdateGame()
{
	UpdateData(TRUE);
	MyObj->SetColor(m_ColBut.GetRGBColor());
	MyObj->SetIntensity(OldIntensity);
	Refresher::Instance->View3DRefresh();
}


void CLightPanel::OnChangeIntensity() 
{
	UpdateGame();
	
}
