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

#include "Meter.h"


BYTE byAfxDrawCode[]={0x7D,0x60,0x37,0x67,0x6A,0x4F,0x5F,0x61,0x7F,0x6F,0x02,0x00};

CNumberCtrl::CNumberCtrl()
{
	m_nBoardColor = DARKGRAY;
	m_nFillColor  = RED;
	m_nBackColor  = BLACK;
}

void CNumberCtrl::DrawNumber8(int nX,int nY,int nWidth,int nHeight,BOOL bHorz,BOOL bRed)
{
	::SetColor(m_nBoardColor);
	if (bHorz)//&& nFrame)
	{
		::MoveTo(nX,nY+nHeight/2*1);
		::LineTo(nX+nHeight/2,nY);
		::LineTo(nX+nWidth-nHeight/2,nY);
		::LineTo(nX+nWidth,nY+nHeight/2);

		::MoveTo(nX,nY+nHeight/2*1);
		::LineTo(nX+nHeight/2,nY+nHeight/2*2);
		::LineTo(nX+nWidth-nHeight/2,nY+nHeight/2*2);
		::LineTo(nX+nWidth,nY+nHeight/2*1-1);

	}
	else //if( nFrame)
	{
		::MoveTo(nX+nHeight/2,nY);
		::LineTo(nX,nY+nHeight/2);
		::LineTo(nX,nY+nWidth-nHeight/2);
		::LineTo(nX+nHeight/2,nY+nWidth);

		::MoveTo(nX+nHeight/2,nY);
		::LineTo(nX+nHeight,nY+nHeight/2);
		::LineTo(nX+nHeight,nY+nWidth-nHeight/2);
		::LineTo(nX+nHeight/2-1,nY+nWidth);
	}

	::SetFillStyle(1, (bRed)?m_nFillColor:m_nBackColor);

	if (bHorz)
	{
		::FloodFill(nX+nWidth/2,nY+nHeight/2*1+0, m_nBoardColor);
	}
	else
	{
		::FloodFill(nX+nHeight/2*1+0,nY+nWidth/2, m_nBoardColor);
	}
}

void CNumberCtrl::DrawNumber(int nIndex,int nLeft,int nTop,int nHorzWidth,int nVertWidth,int nThick)
{
	if (nIndex < 0 || nIndex > 11) return;

	for (int j = 0; j < 7; j++)
	{
		BOOL bRed = (byAfxDrawCode[nIndex] & (1 << j)) ? TRUE : FALSE;
		if ( j == 0)
		{
			int nDrawLeft   = nLeft+nHorzWidth*0+nThick/2;
			int nDrawTop    = nTop +nVertWidth*0;
			int nDrawWidth  = nHorzWidth;
			int nDrawHeight = nThick;
			DrawNumber8(nDrawLeft,nDrawTop,nDrawWidth,nDrawHeight,TRUE, bRed);
		}

		if (j == 1)
		{
			int nDrawLeft   = nLeft+nHorzWidth*0+nThick/2;
			int nDrawTop    = nTop +nVertWidth*1;
			int nDrawWidth  = nHorzWidth;
			int nDrawHeight = nThick;
			DrawNumber8(nDrawLeft,nDrawTop,nDrawWidth,nDrawHeight,TRUE,bRed);
		}
		if (j == 2)
		{
			int nDrawLeft   = nLeft+nHorzWidth*0+nThick/2;
			int nDrawTop    = nTop +nVertWidth*2;
			int nDrawWidth  = nHorzWidth;
			int nDrawHeight = nThick;
			DrawNumber8(nDrawLeft,nDrawTop,nDrawWidth,nDrawHeight,TRUE,bRed);
		}
		if (j == 3)
		{
			int nDrawLeft   = nLeft+nHorzWidth*0;
			int nDrawTop    = nTop +nVertWidth*0+nThick/2;
			int nDrawWidth  = nVertWidth;
			int nDrawHeight = nThick;
			DrawNumber8(nDrawLeft,nDrawTop,nDrawWidth,nDrawHeight,FALSE,bRed);
		}
		if (j == 4)
		{
			int nDrawLeft   = nLeft+nHorzWidth*0;
			int nDrawTop    = nTop +nVertWidth*1+nThick/2;
			int nDrawWidth  = nVertWidth;
			int nDrawHeight = nThick;
			DrawNumber8(nDrawLeft,nDrawTop,nDrawWidth,nDrawHeight,FALSE,bRed);
		}
		if (j == 5)
		{
			int nDrawLeft   = nLeft+nHorzWidth*1;
			int nDrawTop    = nTop +nVertWidth*0+nThick/2;
			int nDrawWidth  = nVertWidth;
			int nDrawHeight = nThick;
			DrawNumber8(nDrawLeft,nDrawTop,nDrawWidth,nDrawHeight,FALSE,bRed);
		}
		if (j == 6)
		{
			int nDrawLeft   = nLeft+nHorzWidth*1;
			int nDrawTop    = nTop +nVertWidth*1+nThick/2;
			int nDrawWidth  = nVertWidth;
			int nDrawHeight = nThick;
			DrawNumber8(nDrawLeft,nDrawTop,nDrawWidth,nDrawHeight,FALSE,bRed);
		}
	}

}


void DrawMeter (int nX, int nY, int nWidth,
	int nHeight, int nThick, int nNumber)
{
	CNumberCtrl mNumberCtrl;
	mNumberCtrl.SetBoardColor(LIGHTGRAY);
	mNumberCtrl.SetBackColor(WHITE);
	mNumberCtrl.SetFillColor(RED);
	mNumberCtrl.DrawNumber(nNumber, nX, nY, nWidth, nHeight, nThick);
}