// EventProps.cpp : implementation file
//

#include "stdafx.h"
#include "pixelwhippro.h"
#include "EventProps.h"



/////////////////////////////////////////////////////////////////////////////
// CEventProps dialog


CEventProps::CEventProps(CWnd* pParent /*=NULL*/)
: CDialog(CEventProps::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEventProps)
	m_ETime = 0.0f;
	m_xpos = 0.0f;
	m_ypos = 0.0f;
	m_zpos = 0.0f;
	m_LoopFlag = FALSE;
	m_SimSpace = -1;
	m_EndDist = 0.0f;
	m_StartDist = 0.0f;
	//}}AFX_DATA_INIT
	CurEvt=NULL;
}


void CEventProps::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEventProps)
	DDX_Text(pDX, IDC_EVENTTIME, m_ETime);
	DDV_MinMaxFloat(pDX, m_ETime, 0.f, 1.f);
	DDX_Text(pDX, IDC_XPOS, m_xpos);
	DDX_Text(pDX, IDC_YPOS, m_ypos);
	DDX_Text(pDX, IDC_ZPOS, m_zpos);
	DDX_Check(pDX, IDC_LOOPING, m_LoopFlag);
	DDX_CBIndex(pDX, IDC_SIMSPACE, m_SimSpace);
	DDX_Text(pDX, IDC_ENDDIST, m_EndDist);
	DDX_Text(pDX, IDC_STARTDIST, m_StartDist);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CEventProps, CDialog)
//{{AFX_MSG_MAP(CEventProps)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEventProps message handlers

BOOL CEventProps::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	/*
	// TODO: Add extra initialization here
	int effnum,inum;
	
	  
		for(effnum=0;effnum<gosFX::EffectLibrary::Instance->m_effects.GetLength();effnum++)
		if(effnum!=ParSpec->m_effectID)
		{
		gosFX::Effect::Specification *spec = gosFX::EffectLibrary::Instance->m_effects[effnum];
		inum=m_EList.AddString(spec->m_name);
		m_EList.SetItemDataPtr(inum,(void *)spec);
		}
		
		  m_EList.SetCurSel(0);	
	*/
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


void CEventProps::OnCancel() 
{
	
	CDialog::OnCancel();
}

void CEventProps::OnOK() 
{
	UpdateData(TRUE);
	/*
	gosFX::Effect::Specification *spec=(gosFX::Effect::Specification *)m_EList.GetItemDataPtr(m_EList.GetCurSel());
	CurEvt->m_effectID=spec->m_effectID;
	*/
	CurEvt->m_time=m_ETime;
	
	Stuff::Point3D pnt(0,0,0);
	pnt.x=m_xpos;
	pnt.y=m_ypos;
	pnt.z=m_zpos;
	CurEvt->m_localToParent=pnt;
	CurEvt->m_nearLimit=m_StartDist*m_StartDist;
	CurEvt->m_farLimit=m_EndDist*m_EndDist;

CurEvt->m_flags=0;



if(m_LoopFlag)
	CurEvt->m_flags|=gosFX::Effect::LoopFlag;

switch(m_SimSpace)
{
case 0: 
	CurEvt->m_flags|=gosFX::Effect::ParentSimulationMode;
	break;
case 1: 
	CurEvt->m_flags|=gosFX::Effect::LocalSpaceSimulationMode;
	 break;
case 2: 
	CurEvt->m_flags|=gosFX::Effect::StaticWorldSpaceSimulationMode;
	 break;
case 3: 
	CurEvt->m_flags|=gosFX::Effect::DynamicWorldSpaceSimulationMode;
	 break;
}
	
	
	CDialog::OnOK();
}

int CEventProps::DoModal(gosFX::Event *evt) 
{
	Check_Object(evt);
	
	CurEvt=evt;
	Stuff::Point3D pnt(0,0,0);
m_ETime=CurEvt->m_time;
	pnt*=CurEvt->m_localToParent;
	m_xpos=pnt.x;
	m_ypos=pnt.y;
	m_zpos=pnt.z;
	m_LoopFlag=(CurEvt->m_flags&gosFX::Effect::LoopFlag)?TRUE:FALSE;
	m_StartDist=(float)sqrt(CurEvt->m_nearLimit);
	m_EndDist=(float)sqrt(CurEvt->m_farLimit);

	DWORD AllFlags=	(gosFX::Effect::StaticWorldSpaceSimulationMode|
		gosFX::Effect::DynamicWorldSpaceSimulationMode|
		gosFX::Effect::ParentSimulationMode|
		gosFX::Effect::LocalSpaceSimulationMode
		);

	DWORD tflag=CurEvt->m_flags&AllFlags;

	if(tflag==gosFX::Effect::StaticWorldSpaceSimulationMode)
		m_SimSpace=2;

	if(tflag==gosFX::Effect::DynamicWorldSpaceSimulationMode)
		m_SimSpace=3;

	if(tflag==gosFX::Effect::ParentSimulationMode)
		m_SimSpace=0;

	if(tflag==gosFX::Effect::LocalSpaceSimulationMode)
		m_SimSpace=1;
				
				return CDialog::DoModal();
}
