示例#1
0
KrFontResource::KrFontResource( const std::string& name,
								KrPaintInfo* info,
								int startingGlyph,
								int addSpaceGlyph,
								int type,
								int length )
	: KrSpriteResource( name )
{
	startIndex = startingGlyph;
	fontType   = type;
	space      = addSpaceGlyph;

	KrAction* action = new KrAction( "NONE" );

	if ( fontType == FIXED )
	{
		int width  = info->width / length;
		int height = info->height;

		for( int i = 0; i < length; i++ )
		{
			action->AddFrame();
			KrRle* rle = action->GetFrame( i );

			rle->Create(	info,
							i * width, 0, width, height,
							i * width, 0,	// the hotspots are absolute coordinates!
							width, height );
		}
	}
	else
	{
		KrPainter painter( info );
		int height = info->height - 1;
		int x = 0;
		int transparent = 0;

		while ( x < info->width )
		{
			x += painter.CalcNotTransparentRun( x, info->width - 1, 0 );
			if ( x < info->width )
				transparent = painter.CalcTransparentRun( x, info->width - 1, 0 );
			else
				transparent = 0;

			if ( x < info->width && transparent > 0 )
			{
				action->AddFrame();
				KrRle* rle = action->GetFrame( action->NumFrames() - 1 );

 				rle->Create(	info,
								x, 1, transparent, height,
								x, 1,	// the hotspots are absolute coordinates!
								transparent, height );
			}
			x += transparent;
		}
	}

	AddAction( action );

	CalcSpaceWidth();
}
示例#2
0
bool KrEncoder::EncodeSprite( SDL_Surface* surface, const AllInfo& allInfo, KrConsole* console )
{
//	gedString spriteName, actionName;
//	TiXmlElement* action;
//	TiXmlElement* frame;
//
//	spriteName = "no_sprite_name";
//	if ( sprite->Attribute( "name" ) )
//	{
//		spriteName = *(sprite->Attribute( "name" ));
//	}

	// Create or locate the sprite.
	if ( !vault.GetSpriteResource( allInfo.name ) )
	{
		vault.AddResource( new KrSpriteResource( allInfo.name ) );
	}
	KrSpriteResource* spriteResource = vault.GetSpriteResource( allInfo.name );
	GLASSERT( spriteResource );

	GlDynArray< int > rotation;
	if ( allInfo.rotation.Count() )
		rotation = allInfo.rotation;
	else
		rotation.PushBack( 0 );

	for( int i=0; i<(int) rotation.Count(); ++i )
	{
		// Get or create the action.
		// If using rotation, append to the name.
		gedString action = allInfo.action;
		if ( rotation.Count() > 1 )
		{
			char buf[16];
			sprintf( buf, ".ROT%03d", rotation[i] );
			action += buf;
		}

		if ( !spriteResource->GetAction( action ) )
		{
			spriteResource->AddAction( new KrAction( action ) );
		}
		KrAction* actionRes = spriteResource->GetAction( action );
		GLASSERT( actionRes );

		int index = actionRes->NumFrames();
		actionRes->AddFrame();

		KrPaintInfo info( surface );
		KrRle* rle = actionRes->GetFrame( index );

		if ( allInfo.isoTargetWidth > 0 )
		{
			CreateIsoTile(  &info, console, 
							allInfo.x, allInfo.y, allInfo.width, allInfo.height,
							rle, allInfo.isoTargetWidth,
							rotation[i] );
		}
		else
		{
			rle->Create( &info, allInfo.x, allInfo.y, allInfo.width, allInfo.height, allInfo.hotx, allInfo.hoty, allInfo.deltax, allInfo.deltay );
		}
		PrintSprite( console, allInfo.name, action, index, actionRes->GetFrame( index ) );
	}

	return true;
}