//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "GlobalUnit.h"
#include "stdio.h"
#include "PlayTimePanel.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)

#define SHOW_LEFT 		8
#define SHOW_TOP 		5
#define SHOW_BOTTOM		24
#define SHOW_WIDTH_1    6
#define SHOW_WIDTH_2    15
#define SHOW_WIDTH_3    22

const COLORREF CLR_BACK = RGB( 74, 80, 88 ),
				CLR_TEXT = RGB( 201, 214, 229 );

__fastcall TPlayTimePanel::TPlayTimePanel(TComponent *Owner) : TPanel(Owner)
{
	memset( m_iTime, 0, sizeof(m_iTime) );

	m_iLeft[0] = SHOW_LEFT;
	m_iRight[0] = m_iLeft[0] + SHOW_WIDTH_3;
	m_iLeft[1] = m_iRight[0] + SHOW_WIDTH_1;
	m_iRight[1] = m_iLeft[1] + SHOW_WIDTH_2;
	m_iLeft[2] = m_iRight[1] + SHOW_WIDTH_1;
	m_iRight[2] = m_iLeft[2] + SHOW_WIDTH_3;
}
//---------------------------------------------------------------------------

__fastcall TPlayTimePanel::~TPlayTimePanel()
{

}
//---------------------------------------------------------------------------

void __fastcall TPlayTimePanel::CreateWnd()
{
	TPanel::CreateWnd();

	Canvas->Font->Name = "Tahoma";
	Canvas->Font->Color = CLR_TEXT;
	Canvas->Font->Size = g_szFont9;
	Canvas->Font->Pitch = TFontPitch::fpFixed;
	Canvas->Font->Quality = TFontQuality::fqClearTypeNatural;
	Canvas->Brush->Style = bsClear;

	Hint = "当前位置(节拍)";
	ShowHint = true;
}
//---------------------------------------------------------------------------

void __fastcall TPlayTimePanel::Paint()
{
	char strTime[4];

	sprintf( strTime, "%03d", m_iTime[0] );
	Canvas->TextOut( m_iLeft[0], SHOW_TOP, strTime );

	sprintf( strTime, "%02d", m_iTime[1] );
	Canvas->TextOut( m_iLeft[1], SHOW_TOP, strTime );

	sprintf( strTime, "%03d", m_iTime[2] );
	Canvas->TextOut( m_iLeft[2], SHOW_TOP, strTime );
}
//---------------------------------------------------------------------------

void __fastcall TPlayTimePanel::WMEraseBkgnd(TWMEraseBkgnd &Message)
{
	TCanvas* pCanvas = new TCanvas();
	pCanvas->Handle  = Message.DC;

	TRect rect = GetClientRect();

	pCanvas->Brush->Color = CLR_BACK;	// 绘制底色
	pCanvas->FillRect(rect);

	pCanvas->Font->Name = "Tahoma";
	pCanvas->Font->Color = CLR_TEXT;
	pCanvas->Font->Size = g_szFont9;
	pCanvas->Font->Pitch = TFontPitch::fpFixed;
	pCanvas->Font->Quality = TFontQuality::fqClearTypeNatural;
	pCanvas->Brush->Style = bsClear;

	int iTop = SHOW_TOP - 1;
	pCanvas->TextOut( m_iLeft[1] - SHOW_WIDTH_1, iTop, ":" );
	pCanvas->TextOut( m_iLeft[2] - SHOW_WIDTH_1, iTop, ":" );

	delete pCanvas;
}
//---------------------------------------------------------------------------

void __fastcall TPlayTimePanel::SetTime( int iTime[3] )
{
	TRect rect(0,SHOW_TOP,0,SHOW_BOTTOM);

	if( iTime[0]!=m_iTime[0] ){
		m_iTime[0] = iTime[0];
		rect.left = m_iLeft[0];
		rect.right = m_iRight[0];
		InvalidateRect( Handle, &rect, FALSE );
	}

	if( iTime[1]!=m_iTime[1] ){
		m_iTime[1] = iTime[1];
		rect.left = m_iLeft[1];
		rect.right = m_iRight[1];
		InvalidateRect( Handle, &rect, FALSE );
	}

	if( iTime[2]!=m_iTime[2] ){
		m_iTime[2] = iTime[2];
		rect.left = m_iLeft[2];
		rect.right = m_iRight[2];
		InvalidateRect( Handle, &rect, FALSE );
	}
}
//---------------------------------------------------------------------------

