#include <Symbol.h>
#include <MyFrame.h>

#include "Meter.h"

void DrawMeter (int nX, int nY, int nWidth,
	int nHeight, int nThick, int nNumber);

void  OnTime_LedDemoDialog(CObject* pCurObj)
{

	CDialog* pDialog = (CDialog *)pCurObj;



	static int nCounts = 0;
	if (((++nCounts) % 10) != 0)
	{
		return;
	}
	nCounts = 0;

	viewporttype mViewPort;
	pDialog->SaveAndSetUserView(&mViewPort);

	//Rpm
	int nRand = ::rand();
	int nRand2 = nRand % 10000;
	int nNumber = nRand2 / 1000;
	::DrawMeter (10 + 50 * 0, 30, 35, 35, 12, nNumber);

	nRand2 = nRand2 - nNumber * 1000;
	nNumber = nRand2 / 100;
	::DrawMeter (10 + 50 * 1, 30, 35, 35, 12, nNumber);

	nRand2 = nRand2 - nNumber * 100;
	nNumber = nRand2 / 10;
	::DrawMeter (10 + 50 * 2, 30, 35, 35, 12, nNumber);
	::DrawMeter (10 + 50 * 3, 30, 35, 35, 12, nRand2 - 10 * nNumber);


	pDialog->RestoreUserView(&mViewPort);

}

void  OnDraw_LedDemoDialog(CObject* pCurObj)
{
	::DrawMeter (10 + 50 * 0, 30, 35 ,35, 12, 1);
	::DrawMeter (10 + 50 * 1, 30, 35 ,35, 12, 2);
	::DrawMeter (10 + 50 * 2, 30, 35 ,35, 12, 3);
	::DrawMeter (10 + 50 * 3, 30, 35 ,35, 12, 4);

}


void far LedDemoDialog()
{
	CDialog* pDialog = new CDialog;
	pDialog->CreateWindow(0, 0, 230, 160, "LED");
	pDialog->Center();

	new CCloseButton(pDialog);


	pDialog->SetBackColor(LIGHTGREEN);
	pDialog->SetDrawFc(OnDraw_LedDemoDialog);
	pDialog->SetTimeFc(OnTime_LedDemoDialog);




	pDialog->ShowWindow();
	pDialog->DoModal();
	delete pDialog;
	return;
}