// SplineControl.cpp : implementation file
//

#include "stdafx.h"
#include "TCTb.h"
#include "SplineControl.h"

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


/////////////////////////////////////////////////////////////////////////////
// CSplineControl property page

IMPLEMENT_DYNCREATE(CSplineControl, CPropertyPage)

CSplineControl::CSplineControl() : CCamInfoPage(CSplineControl::IDD)
{
	//{{AFX_DATA_INIT(CSplineControl)
	m_TmeSli = 0;
	m_VelSli = 0;
	//}}AFX_DATA_INIT
}

CSplineControl::~CSplineControl()
{
}

void CSplineControl::DoDataExchange(CDataExchange* pDX)
{
	CCamInfoPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSplineControl)
	DDX_Control(pDX, IDC_VELTEXT, m_VelText);
	DDX_Control(pDX, IDC_POSTEXT, m_PosText);
	DDX_Control(pDX, IDC_VELSLI, m_VelSliCtrl);
	DDX_Control(pDX, IDC_SPOSSLI, m_TmeSliCtrl);
	DDX_Slider(pDX, IDC_SPOSSLI, m_TmeSli);
	DDX_Slider(pDX, IDC_VELSLI, m_VelSli);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSplineControl, CCamInfoPage)
	//{{AFX_MSG_MAP(CSplineControl)
	ON_WM_HSCROLL()
	ON_BN_CLICKED(IDC_ANIMATE, OnAnimate)
	ON_BN_CLICKED(IDC_RESETCURVE, OnResetcurve)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSplineControl message handlers
void CSplineControl::DataIn()
{
m_TmeSliCtrl.SetRange(0,100);
m_VelSliCtrl.SetRange(-100,100);
m_TmeSli=((int)(CamInfo->GetTime()*100));
m_VelSli=((int)(CamInfo->GetVel()*100));
CheckDlgButton(IDC_ANIMATE,CamInfo->Animate);
}

void CSplineControl::DataOut()
{
}

void CSplineControl::UpdateControlStates()
{
}

void CSplineControl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
CString tstr;

if(pScrollBar==(CScrollBar* )&m_TmeSliCtrl || pScrollBar==(CScrollBar* )&m_VelSliCtrl)
	CamInfo->SetMode(CameraInfo::CM_TRACK);

if(pScrollBar==(CScrollBar* )&m_TmeSliCtrl)
	{
	CamInfo->Animate=false;
	CheckDlgButton(IDC_ANIMATE,CamInfo->Animate);
	tstr.Format("%i%%",m_TmeSliCtrl.GetPos());
	m_PosText.SetWindowText(tstr);
	CamInfo->SetTime(m_TmeSliCtrl.GetPos()/100.0f);
	}

if(pScrollBar==(CScrollBar* )&m_VelSliCtrl)
	{
	tstr.Format("%i%%",m_VelSliCtrl.GetPos());
	m_VelText.SetWindowText(tstr);
	CamInfo->SetVel(m_VelSliCtrl.GetPos()/100.0f);
	CheckDlgButton(IDC_ANIMATE,TRUE);
	CamInfo->Animate=true;
	}
 
}

void CSplineControl::OnAnimate() 
{
CamInfo->Animate=IsDlgButtonChecked(IDC_ANIMATE)?true:false;
UpdateControlStates();
}

void CSplineControl::OnResetcurve() 
{
if(!CamInfo || !CamInfo->ViewLoop) return;
CamInfo->ViewLoop->ResetCurve(); 
}
