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

📄 cfont.cpp

📁 Symbian手机游戏,可运行于S60 1.x和2.x下, Carbide.C++ & Vs.Net2003下编译 游戏为吞食鱼的手机版,通过服用比自己体积小的鱼而使自己长大
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CFont from CFont.h
*  Part of  : 2DExample
*  Created  : 01/01/2005 by Forum Nokia
*  Version  : 1.0
*  Copyright: 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 + -