www.pudn.com > LrcMaker.zip > LyricStatic.cpp
// LyricStatic.cpp : implementation file
//
#include "stdafx.h"
#include "LrcMaker.h"
#include "LyricStatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern BYTE * pAsciiFont;
extern BYTE * pHanziFont;
/////////////////////////////////////////////////////////////////////////////
// CLyricStatic
CLyricStatic::CLyricStatic()
{
m_BackColor = RGB(255,255,255);
m_TextColor = RGB(0, 0, 0);
// m_TextColor = 0xFF;
m_BackBrush.CreateSolidBrush( m_BackColor ) ;
m_strText = NULL;
m_nZoomIn = 1;
}
CLyricStatic::~CLyricStatic()
{
if( m_strText ) free( m_strText );
}
BEGIN_MESSAGE_MAP(CLyricStatic, CStatic)
//{{AFX_MSG_MAP(CLyricStatic)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLyricStatic message handlers
void CLyricStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
RECT rectClient;
GetClientRect(&rectClient);
// 不在范围之内直接以背景色填充
dc.FillRect(&rectClient, &m_BackBrush);
// 文字显示
dc.SetTextColor(m_TextColor);
if( m_strText != NULL )
DrawText(&dc, m_strText);
// Do not call CStatic::OnPaint() for painting messages
}
void CLyricStatic::DrawPoint(CDC *pDc, INT x, INT y, COLORREF color)
{
int i, j;
for(i=0; iSetPixel (x+i, y+j, color);
}
}
}
int CLyricStatic::DrawASCII(CPaintDC *pDC, WCHAR ch, INT x, INT y)
{
BYTE * p;
int i, j, k;
unsigned long offset;
int tempx, tempy=y;
//ASCII 字符
offset = ch * 48;
p = &pAsciiFont[offset];
for( i=0; i<24; i++ )
{
tempx = x;
for( j=0; j<2; j++ )
{
for( k=0; k<8; k++ )
{
if( p[ i*2+j ] & (0x80>>k) )
{
DrawPoint( pDC, tempx, tempy, m_TextColor );
}
//tempx++;
tempx+=m_nZoomIn;
}
}
//tempy++;
tempy+=m_nZoomIn;
}
return (12*m_nZoomIn);
}
int CLyricStatic::DrawHanzi(CPaintDC *pDC, WCHAR ch, INT x, INT y)
{
BYTE * p, c1, c2;
int i, j, k;
unsigned long offset;
int tempx=x, tempy;
c1 = ((ch & 0xff00 )>>8) - 0xa1;
c2 = (ch & 0xff) - 0xa1;
offset = (c1*94 + c2) * 72;
p = &pHanziFont[offset];
for( i=0; i<24; i++ )
{
tempy = y;
for( j=0; j<3; j++ )
{
for( k=0; k<8; k++ )
{
if( p[ i*3+j ] & (0x80>>k) )
{
DrawPoint( pDC, tempx, tempy, m_TextColor );
}
//tempx++;
tempy+=m_nZoomIn;
}
}
//tempy++;
tempx+=m_nZoomIn;
}
return (24*m_nZoomIn);
}
int CLyricStatic::SetText( TCHAR *pText, BOOL bRepaint )
{
int len;
if( pText != NULL )
{
if( m_strText ) free( m_strText );
len = strlen( pText );
m_strText = (TCHAR *)malloc( (len+1) * sizeof(TCHAR) );
memcpy( m_strText, pText, len*sizeof(TCHAR) );
m_strText[len]=0;
}
if ( bRepaint )
{
Invalidate(TRUE);
}
return 0;
}
#define LCD_WIDTH 320
#define LCD_HEIGHT 234
void CLyricStatic::DrawText(CPaintDC *pDC, TCHAR *wsText)
{
BYTE * p = (BYTE *)wsText;
unsigned short ch;
int tx, ty;
tx = 0;
ty = 0;
while( *p )
{
if( *p == 0x0d || *p==0x0a ) break;
if( (*p) < 0x80 )
{
ch = *p;
p++;
if( (tx + (12*m_nZoomIn)) > LCD_WIDTH )
{
tx = 0;
ty += 24*m_nZoomIn;
}
DrawASCII( pDC, ch, tx, ty );
tx += (12*m_nZoomIn);
}
else
{
ch = ((*p)<<8) | *(p+1) ;
p+=2;
if( (tx + (24*m_nZoomIn)) > LCD_WIDTH )
{
tx = 0;
ty += 24*m_nZoomIn;
}
DrawHanzi( pDC, ch, tx, ty );
tx += 24*m_nZoomIn;
}
if( (ty + 24*m_nZoomIn) > LCD_HEIGHT ) break;
}
}