// LodRangeDlg.cpp : implementation file
//

#include "stdafx.h"
#include "mfc gos.h"
#include "LodRangeDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLodRangeDlg dialog


CLodRangeDlg::CLodRangeDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLodRangeDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLodRangeDlg)
	m_Start = 0.0f;
	m_FadeIn = 0.0f;
	m_FadeOut = 0.0f;
	m_End = 0.0f;
	m_AlignStartAt = -1;
	m_AlignType = 0;
	m_NumLODs = 5;
	//}}AFX_DATA_INIT
}


void CLodRangeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLodRangeDlg)
	DDX_Text(pDX, IDC_START, m_Start);
	DDX_Text(pDX, IDC_FADEIN, m_FadeIn);
	DDX_Text(pDX, IDC_FADEOUT, m_FadeOut);
	DDX_Text(pDX, IDC_END, m_End);
	DDX_Control(pDX, IDC_ALIGN_X, m_checkAlignX);
	DDX_Control(pDX, IDC_ALIGN_Y, m_checkAlignY);
	DDX_Control(pDX, IDC_ALIGN_STARTLOD, m_comboStartLOD);
	//}}AFX_DATA_MAP
}

BOOL CLodRangeDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// Initialize the controls
	// Load billboarding stuff
	m_comboStartLOD.ResetContent();
	for (int i=0; i<m_NumLODs; i++) {
		CString str;
		str.Format("LOD%d", i);
		m_comboStartLOD.AddString(str);
	}
	m_comboStartLOD.AddString("None");

	if (m_AlignStartAt<0 || m_AlignStartAt>m_NumLODs)
		m_AlignStartAt = m_NumLODs;

	m_comboStartLOD.SetCurSel(m_AlignStartAt);
	m_checkAlignX.SetCheck(m_AlignType&ElementRenderer::Element::AlignXFlag);
	m_checkAlignY.SetCheck(m_AlignType&ElementRenderer::Element::AlignYFlag);
	OnSelectStartLOD();

	GetDlgItem(IDC_STATICALIGN)->ShowWindow(m_EditType==Billboard?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_ALIGN_STARTLOD)->ShowWindow(m_EditType==Billboard?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_ALIGN_X)->ShowWindow(m_EditType==Billboard?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_ALIGN_Y)->ShowWindow(m_EditType==Billboard?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_FADEIN)->ShowWindow(m_EditType==CrossFade?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_FADEOUT)->ShowWindow(m_EditType==CrossFade?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_STATICFADEIN)->ShowWindow(m_EditType==CrossFade?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_STATICFADEOUT)->ShowWindow(m_EditType==CrossFade?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_START)->ShowWindow(m_EditType!=Billboard?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_END)->ShowWindow(m_EditType!=Billboard?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_STATICSTART)->ShowWindow(m_EditType!=Billboard?SW_SHOW:SW_HIDE);
	GetDlgItem(IDC_STATICEND)->ShowWindow(m_EditType!=Billboard?SW_SHOW:SW_HIDE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLodRangeDlg::OnOK() 
{
	// Save billboarding stuff
	CString str;
	this->m_comboStartLOD.GetWindowText(str);
	if (str != "None") {
		bool bAlignX = this->m_checkAlignX.GetCheck() != 0;
		bool bAlignY = this->m_checkAlignY.GetCheck() != 0;
		m_AlignStartAt = atoi(str.Right(1));
		m_AlignType = 0;
		if (bAlignX || bAlignY)
		{
			if (bAlignX && bAlignY)
				m_AlignType = ElementRenderer::Element::AlignXFlag|ElementRenderer::Element::AlignYFlag;
			else if (bAlignX)
				m_AlignType = ElementRenderer::Element::AlignXFlag;
			else if (bAlignY)
				m_AlignType = ElementRenderer::Element::AlignYFlag;
		}
	}

	else {
		m_AlignStartAt = m_NumLODs;
		m_AlignType = 0;
	}
		
	CDialog::OnOK();
}

void CLodRangeDlg::OnSelectStartLOD() 
{
	CString startLOD;
	m_comboStartLOD.GetLBText(m_comboStartLOD.GetCurSel(), startLOD);

	m_checkAlignX.EnableWindow(startLOD!="None" && m_comboStartLOD.IsWindowEnabled());
	m_checkAlignY.EnableWindow(startLOD!="None" && m_comboStartLOD.IsWindowEnabled());
}

BEGIN_MESSAGE_MAP(CLodRangeDlg, CDialog)
	//{{AFX_MSG_MAP(CLodRangeDlg)
		// NOTE: the ClassWizard will add message map macros here
		ON_CBN_SELCHANGE(IDC_ALIGN_STARTLOD, OnSelectStartLOD)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLodRangeDlg message handlers
