// CamState.cpp : implementation file
//

#include "stdafx.h"
#include "TCTb.h"
#include "CamState.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCamState property page

IMPLEMENT_DYNCREATE(CCamState, CPropertyPage)

CCamState::CCamState() : CCamInfoPage(CCamState::IDD)
{
	//{{AFX_DATA_INIT(CCamState)
	m_AMode = -1;
	m_WFMode = -1;
	m_FilterMode = -1;
	//}}AFX_DATA_INIT
}

CCamState::~CCamState()
{
}

void CCamState::DoDataExchange(CDataExchange* pDX)
{
	CCamInfoPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCamState)
	DDX_CBIndex(pDX, IDC_AMODE, m_AMode);
	DDX_CBIndex(pDX, IDC_WIREFRAME, m_WFMode);
	DDX_CBIndex(pDX, IDC_FILTERMODE, m_FilterMode);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCamState, CCamInfoPage)
	//{{AFX_MSG_MAP(CCamState)
	ON_BN_CLICKED(IDC_BACKFACE, OnBackface)
	ON_BN_CLICKED(IDC_DITHERING, OnDithering)
	ON_BN_CLICKED(IDC_ZBCOMPARE, OnZbcompare)
	ON_BN_CLICKED(IDC_ZBWRITE, OnZbwrite)
	ON_BN_CLICKED(IDC_TEXTURES, OnTextures)
	ON_BN_CLICKED(IDC_PCORRECT, OnPcorrect)
	ON_BN_CLICKED(IDC_FOG, OnFog)
	ON_CBN_DROPDOWN(IDC_AMODE, OnDropdownAmode)
	ON_CBN_CLOSEUP(IDC_AMODE, OnCloseupAmode)
	ON_CBN_CLOSEUP(IDC_WIREFRAME, OnCloseupWireframe)
	ON_CBN_DROPDOWN(IDC_WIREFRAME, OnDropdownWireframe)
	ON_CBN_CLOSEUP(IDC_FILTERMODE, OnCloseupFiltermode)
	ON_CBN_DROPDOWN(IDC_FILTERMODE, OnDropdownFiltermode)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCamState message handlers

void CCamState::DataIn()
{

switch(CamInfo->State.GetAlphaMode())
{
	case StateChange::OneZeroMode:		m_AMode=0; break;
	case StateChange::OneOneMode:		m_AMode=1; break;
	case StateChange::AlphaOneMode :	m_AMode=2; break;
	case StateChange::OneAlphaMode :	m_AMode=3; break;
	case StateChange::AlphaInvAlphaMode:m_AMode=4; break;
}

switch(CamInfo->State.GetFilterMode())
{
	case StateChange::PointSampleMode:	m_FilterMode=0;		break;
	case StateChange::BilinearMode:		m_FilterMode=1;		break;
	case StateChange::TrilinearMode:	m_FilterMode=2;		break;		
}

switch(CamInfo->State.GetWireFrameMode())
{
	case StateChange::WireMode	:		m_WFMode=0;			break;
	case StateChange::SolidAndWireMode:	m_WFMode=1;			break;
	case StateChange::SolidMode	:		m_WFMode=2;			break;
}

CheckDlgButton(IDC_ZBCOMPARE,CamInfo->State.IsZBufferCompareEnabled()?TRUE:FALSE);
CheckDlgButton(IDC_ZBWRITE,CamInfo->State.IsZBufferWriteEnabled()?TRUE:FALSE);
CheckDlgButton(IDC_BACKFACE,CamInfo->State.IsBackfaceCullingEnabled()?TRUE:FALSE);
CheckDlgButton(IDC_DITHERING,CamInfo->State.IsDitheringEnabled()?TRUE:FALSE);
//CheckDlgButton(IDC_FOG,CamInfo->State.IsFogEnabled()?TRUE:FALSE);
CheckDlgButton(IDC_PCORRECT,CamInfo->State.IsPerspectiveCorrectionEnabled()?TRUE:FALSE);

CheckDlgButton(IDC_TEXTURES,1?TRUE:FALSE);


}

void CCamState::DataOut()
{

}

void CCamState::UpdateControlStates()
{

}



void CCamState::OnBackface() 
{
	if (IsDlgButtonChecked(IDC_BACKFACE))
		CamInfo->State.EnableBackfaceCulling();
	else
		CamInfo->State.DisableBackfaceCulling();
	
}

void CCamState::OnDithering() 
{
	if (IsDlgButtonChecked(IDC_DITHERING))
		CamInfo->State.EnableDithering();
	else
		CamInfo->State.DisableDithering();
}

void CCamState::OnZbcompare() 
{
	if (IsDlgButtonChecked(IDC_ZBCOMPARE))
		CamInfo->State.EnableZBufferCompare();
	else
		CamInfo->State.DisableZBufferCompare();
}

void CCamState::OnZbwrite() 
{
	if (IsDlgButtonChecked(IDC_ZBWRITE))
		CamInfo->State.EnableZBufferWrite();
	else
		CamInfo->State.DisableZBufferWrite();
}


void CCamState::OnTextures() 
{
}

void CCamState::OnPcorrect() 
{
	if (IsDlgButtonChecked(IDC_PCORRECT))
		CamInfo->State.EnablePerspectiveCorrection();
	else
		CamInfo->State.DisablePerspectiveCorrection();
}

void CCamState::OnFog() 
{
/*
	if (IsDlgButtonChecked(IDC_FOG))
		CamInfo->State.EnableFog();
	else
		CamInfo->State.DisableFog();
*/
 }


void CCamState::OnDropdownFiltermode()  { SetUpdate(false); }
void CCamState::OnDropdownAmode()		{SetUpdate(false);}
void CCamState::OnDropdownWireframe()  { SetUpdate(false); }

void CCamState::OnCloseupAmode() 
{
UpdateData(TRUE);
	switch(m_AMode)
	{
		case 0: CamInfo->State.SetAlphaMode(StateChange::OneZeroMode); break;
		case 1: CamInfo->State.SetAlphaMode(StateChange::OneOneMode); break;
		case 2: CamInfo->State.SetAlphaMode(StateChange::AlphaOneMode); break;
		case 3: CamInfo->State.SetAlphaMode(StateChange::OneAlphaMode); break;
		case 4: CamInfo->State.SetAlphaMode(StateChange::AlphaInvAlphaMode); break;
	}	

	SetUpdate(true);
}

void CCamState::OnCloseupWireframe() 
{
	UpdateData(TRUE);

	switch(m_WFMode)
	{
		case 0: CamInfo->State.SetWireFrameMode(StateChange::WireMode); break;
		case 1: CamInfo->State.SetWireFrameMode(StateChange::SolidAndWireMode); break;
		case 2: CamInfo->State.SetWireFrameMode(StateChange::SolidMode); break;
	}	
	
	SetUpdate(true);
}


void CCamState::OnCloseupFiltermode() 
{
	UpdateData(TRUE);
	switch(m_FilterMode)
		{
		case 0: CamInfo->State.SetFilterMode(StateChange::PointSampleMode); break;
		case 1: CamInfo->State.SetFilterMode(StateChange::BilinearMode); break;
		case 2: CamInfo->State.SetFilterMode(StateChange::TrilinearMode); break;
		}
	
	SetUpdate(true);	
}

