⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfont.cpp

📁 Symbian OS S60平台2D游戏引擎案例
💻 CPP
字号:
   /*
============================================================================
    * Name : CBmFont.cpp
    * Part of : 2DExample
    * Description : Implementation of CBmFont
    * Copyright (c) 2007 Nokia Corporation
============================================================================
    */

// INCLUDE FILES
#include "CFont.h"
#include "CBitmap.h"



CBmFont* CBmFont::NewL( CBitmap* aBitmap, MSystem* aSystem )
	{
	CBmFont* self = new( ELeave )CBmFont( aBitmap, aSystem );
	CleanupStack::PushL( self );
	self->ConstructL( aBitmap );
	CleanupStack::Pop( self );
	return self;
	}



void CBmFont::ConstructL( CBitmap* aBitmap )
	{
	TUint16* s;
	TInt tr = 0;
	TBool in = EFalse;

	s =aBitmap->Data();
	
	for ( TInt i = 0; i < 255; i++ )
		{
		iRects[i] = TRect( 0, 0, 0, 0 );
		}

	for ( TInt x = 0; x <aBitmap->Size().iWidth; x++ )
		{
		if ( s[x] != 0 )
			{
			in = !in;
			if( in )
				{
				iRects[tr].iTl = TPoint( x,1 );
				}
			else
				{
				iRects[tr].iBr = TPoint( x, aBitmap->Size().iHeight );
				tr++;
				}
			}
		}
	}



CBmFont::CBmFont( CBitmap* aBitmap, MSystem* aSystem ) : iBitmap( aBitmap ), iSystem( aSystem )
	{

	}



CBmFont::~CBmFont()
	{
	}


void CBmFont::DrawText( CBitmap& aTarget,  const TDesC8& aString, const TPoint& aPosition )
	{
	TRect cur ( 0, 0, 0, 0 );
	TPoint pos( aPosition );

	for( TInt i=0;i < aString.Length(); i++ )
		{
		TInt t = aString[i];
		pos.iX += cur.Width();

		if( t == ' ' )
			{
			cur = iRects[ '@' - '0' + 1 ];
			continue;
			}

		t -= '0';
		cur = iRects[t];

		iBitmap->SetDrawRect( iRects[ t ] );
		iBitmap->Draw( aTarget, pos );
		}
	}



void CBmFont::DrawNumber( CBitmap& aTarget, const TInt aNumber, const TPoint& aPosition )
	{
	TBuf8<16> txt;
	txt.AppendNum( aNumber );
	DrawText( aTarget, txt, aPosition );
	}

// End of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -