#include "pch.h"
#include "GenericBkMFC.h"
#include "DlgDigitST.h"

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

CDlgDigitST::CDlgDigitST(CWnd* pParent, CResourceServerST*	m_pIcons)
	: CDialog(CDlgDigitST::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgDigitST)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	m_pIconsDLL = m_pIcons;
	m_bRunning = FALSE;
}

void CDlgDigitST::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgDigitST)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP

	DDX_Control(pDX, IDC_BTNGO, m_btnGo);
	DDX_Control(pDX, IDC_RESETPARTIAL, m_btnReset);
	DDX_Control(pDX, IDC_DIGIT_SPEED, m_dgtSpeed);
	DDX_Control(pDX, IDC_DIGIT_TOTALKM, m_dgtTotal);
	DDX_Control(pDX, IDC_DIGIT_PARTIALKM, m_dgtPartial);
}

BEGIN_MESSAGE_MAP(CDlgDigitST, CDialog)
	//{{AFX_MSG_MAP(CDlgDigitST)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_RESETPARTIAL, OnResetPartial)
	ON_BN_CLICKED(IDC_BTNGO, OnGo)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

	m_dwTotal = 1055;
	m_dwPartial = 0;

	//m_btnGo.m_ptImageOrg.x += 4;
	//m_btnGo.SetIcon(m_pIconsDLL->LoadIcon(DLL_IDI_SET04_OK, 24, 24));
	m_btnGo.SetShade(CKeyboardButtonST::SHS_KEYBOARD2, FALSE);
	m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_LOW, RGB(0, 128, 0), FALSE);
	m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_MID, RGB(165, 255, 165), FALSE);
	m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_HI, RGB(128, 255, 128), FALSE);
	m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_MIX, RGB(165, 255, 165), FALSE);
	//
	m_btnReset.m_ptImageOrg.x += 4;
	m_btnReset.SetIcon(m_pIconsDLL->LoadIcon(DLL_IDI_SET04_INFO, 24, 24));
	m_btnReset.SetShade(CKeyboardButtonST::SHS_KEYBOARD2, FALSE);

	// Create IDC_DIGIT_SPEED control
	m_dgtSpeed.SetStyle(IDB_BIG1, 5);
	m_dgtSpeed.SetText(0);

	// Create IDC_DIGIT_TOTALKM control
	m_dgtTotal.SetStyle(IDB_SMALL2, 6);
	m_dgtTotal.SetZeroPadding(TRUE);
	m_dgtTotal.SetText((long)m_dwTotal);

	// Create IDC_DIGIT_PARTIALKM control
	m_dgtPartial.SetStyle(IDB_SMALL1, 6);
	m_dgtPartial.SetZeroPadding(TRUE);
	m_dgtPartial.SetText((long)m_dwPartial);

	return TRUE;
} // End of OnInitDialog

void CDlgDigitST::OnDestroy()
{
	KillTimer(1);

	CDialog::OnDestroy();
} // End of OnDestroy

void CDlgDigitST::OnOK()
{
} // End of OnOK

void CDlgDigitST::OnCancel()
{
} // End of OnCancel

void CDlgDigitST::OnTimer(UINT_PTR nIDEvent)
{
	if (nIDEvent == 1)
	{
		m_dwTotal++;
		m_dwPartial++;
		//
		m_dgtTotal.SetText((long)m_dwTotal);
		m_dgtPartial.SetText((long)m_dwPartial);
	} // if
	else
		CDialog::OnTimer(nIDEvent);
} // End of OnTimer

void CDlgDigitST::OnResetPartial()
{
	m_dwPartial = 0;
	m_dgtPartial.SetText((long)m_dwPartial);
} // End of OnResetPartial

void CDlgDigitST::OnGo()
{
	m_bRunning = !m_bRunning;

	if (m_bRunning == TRUE)
	{
		SetTimer(1, 250, NULL);
		m_dgtSpeed.SetText(90);
		m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_LOW, RGB(255, 0, 0), FALSE);
		m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_MID, RGB(255, 165, 165), FALSE);
		m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_HI, RGB(255, 122, 122), FALSE);
		m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_MIX, RGB(255, 165, 165), FALSE);
		m_btnGo.SetWindowText(_T("Stop moving!"));
	} // if
	else
	{
		KillTimer(1);
		m_dgtSpeed.SetText(0);
		m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_LOW, RGB(0, 128, 0), FALSE);
		m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_MID, RGB(165, 255, 165), FALSE);
		m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_HI, RGB(128, 255, 128), FALSE);
		m_btnGo.SetColor(CKeyboardButtonST::KEYST_COLOR_MIX, RGB(165, 255, 165), FALSE);
		m_btnGo.SetWindowText(_T("Go somewhere"));
	} // else
} // End of OnGo
