// FloatPanel.cpp : implementation file
//

#include "stdafx.h"
#include "pixelwhippro.h"
#include "FloatPanel.h"
#include "CurveSet.h"


extern CPixelWhipProApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CFloatPanel dialog


CFloatPanel::CFloatPanel(CWnd* pParent /*=NULL*/)
	: CDynaPanel(CFloatPanel::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFloatPanel)
	m_FloatVal = 0;
	//}}AFX_DATA_INIT
NeedUpdate=false;
}


void CFloatPanel::DoDataExchange(CDataExchange* pDX)
{
	CDynaPanel::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFloatPanel)
	DDX_Text(pDX, IDC_FLOATNUM, m_FloatVal);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFloatPanel, CDynaPanel)
	//{{AFX_MSG_MAP(CFloatPanel)
	ON_EN_CHANGE(IDC_FLOATNUM, OnChangeFloat)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFloatPanel message handlers

void CFloatPanel::UpdateControl()
{
	m_FloatVal=1/(*floatval);
UpdateData(FALSE);
}

void CFloatPanel::Set(void *pt)
{
floatval=(float *)pt;
}


void CFloatPanel::OnChangeFloat() 
{
UpdateData(TRUE);
NeedUpdate=true;
SetTimer(1,1000,NULL);
}

BOOL CFloatPanel::OnInitDialog() 
{
	CDynaPanel::OnInitDialog();
	UpdateControl();
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFloatPanel::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
if(NeedUpdate)
{
theApp.StopEffects();

float OldValue=*floatval;
*floatval=1/(m_FloatVal);

if(!MyCSet->IsDataValid())
{
*floatval=m_FloatVal=OldValue;
UpdateData(FALSE);
}

NeedUpdate=false;
theApp.StartEffects();
}
	CDynaPanel::OnTimer(nIDEvent);
}
