Exemple #1
0
KrAction* SharedStateData::CreateAnimationAction()
{
	KrAction* action = 0;

	// If there is a current action, write the frame actions
	// and encode them.
	if ( currentAction )
	{
		int nFrames = currentAction->children.Count();
		int i = 0;
		if ( nFrames > 0 )
		{
			action = new KrAction( "no_action_name" );

			GlSListIterator< EdWidget* > it( currentAction->children );
			for( i = 0, it.Begin(); 
				 !it.Done(); 
				 ++i, it.Next() )
			{
				EdWidgetFrame* frame = it.Current()->ToFrame();
				GLASSERT( frame );
				KrDom::Frame frameData = frame->GetFrameData();

				KrPaintInfo info(	canvasResource->Pixels(), 
									canvasResource->Width(), 
									canvasResource->Height() );

				action->AddFrame();
				GLASSERT( action->NumFrames() == i+1 );
				action->GetFrame( i )->Create(	&info, 
												frameData.x,
												frameData.y,
												frameData.width,
												frameData.height,
												frameData.hotspotX,
												frameData.hotspotY,
												frameData.deltaX,
												frameData.deltaY );
			}			
		}
	}
	return action;
}
Exemple #2
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();
}
Exemple #3
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;
}