#include "MotorIndicator.h"

CMotorIndicator::CMotorIndicator(UINT id, Motor *motor, CDialog *parent,
							   UINT ledOffBitmap, UINT ledOnBitmap) {
	_id = id;
	_motor = motor;
	_ledOff.LoadBitmap(ledOffBitmap);
	_ledOn.LoadBitmap(ledOnBitmap);
	_jogState = 9999;
	_parent = parent;
}


CMotorIndicator::~CMotorIndicator()
{
}


void CMotorIndicator::update() {
	Boolean jogState = _motor->jogging();

	if (jogState == _jogState)
		return;


	_jogState = jogState;

	repaint();

}

void CMotorIndicator::repaint() 
{
	CBitmap *bitmap;

	if (_jogState)
		bitmap = &_ledOn;
	else
		bitmap = &_ledOff;


	CWnd *canvas = _parent->GetDlgItem(_id);
	if(canvas != NULL)
	{
		CDC *pDC = canvas->GetDC();
		CDC dC;
		dC.CreateCompatibleDC(pDC);
		dC.SelectObject(bitmap);
		BITMAP bmp;	
		bitmap->GetBitmap(&bmp);
		pDC->BitBlt(0, 0, bmp.bmWidth, bmp.bmHeight, &dC, 0, 0, SRCCOPY);
		_parent->ReleaseDC(pDC);		
	}
}
