コード例 #1
0
ファイル: SWStats.c プロジェクト: gefariasjr/projetofinal1
SWError SetUpStatsSprite(
    SpritePtr statsSpriteP,
    SpriteLayerPtr dstSpriteLayer,
    DrawProcPtr drawProcP,
    short horizLoc,
    short vertLoc,
    long theNum)
{
    SWError err = kNoError;
    
    if (statsSpriteP == NULL)
        err = -1;
    
    if (err == kNoError)
    {
        SWSetSpriteLocation(statsSpriteP, horizLoc, vertLoc);
        SWAddSprite(dstSpriteLayer, statsSpriteP);
        SetStatsSpriteDrawProc(statsSpriteP, drawProcP);
        SetStatsSpriteNumber(statsSpriteP, theNum);
    }
    
    return err;
}
コード例 #2
0
ファイル: StaticText.c プロジェクト: simap/spriteworldx
SWError st_CreateStaticText(
	const char* string,
	const char* fontPath,
	int fontSize,
	SWRect* bounds,
	int wrap,
	StaticTextPtr* newStaticTextPP )
{
	SWError err = kNoError;
	FramePtr frameP = NULL;
	StaticTextPtr tempStaticTextP = NULL;
	
	*newStaticTextPP = 0;
	
	if( ! gSTHasBeenInitialized )
		err = kSTHasNotBeenInitedError;
	
	if( err == kNoError )
		if( strlen( string ) > kMaxStringLength - 1 )
			err = kSTStringTooLongError;

	if( err == kNoError )
		if( strlen( fontPath ) > kMaxPathLength - 1 )
			err = kSTPathTooLongError;
	
	if( err == kNoError )
	{
		tempStaticTextP = malloc( sizeof( StaticTextRec ) );
		if( ! tempStaticTextP ) err = kMemoryAllocationError;
	}
	
	if( err == kNoError )
		err = SWCreateSprite( (SpritePtr*)&tempStaticTextP, tempStaticTextP, 1 );		

	if( err == kNoError )
	{
		SWSetSpriteMoveProc( (SpritePtr)tempStaticTextP, handleStaticText );
		
			// make the frame to which we will be copying each line of text
		err = SWCreateBlankFrame(
			&frameP,
			SW_RECT_WIDTH( *bounds ),
			SW_RECT_HEIGHT( *bounds ),
			SDL_GetVideoInfo()->vfmt->BitsPerPixel,
			true );
	}
				
	if( err == kNoError )
	{
		SWSetSpriteLocation( (SpritePtr)tempStaticTextP, bounds->left, bounds->top );
		err = SWAddFrame( (SpritePtr)tempStaticTextP, frameP );
	}
	
	if( err == kNoError )
	{
		strcpy( tempStaticTextP->string, string );
		strcpy( tempStaticTextP->fontPath, fontPath );
		tempStaticTextP->fontSize = fontSize;
		tempStaticTextP->fontStyle = gDefaultStyle;
		tempStaticTextP->wrap = wrap;
		tempStaticTextP->bounds = *bounds;
		tempStaticTextP->align = gDefaultAlign;
		tempStaticTextP->rendering = gDefaultRendering;
		tempStaticTextP->textColor = gDefaultTextColor;
		tempStaticTextP->backColor = gDefaultBackColor;
		
		err = SWSetCurrentFrameIndex( (SpritePtr)tempStaticTextP, 0 );
	}
		
	if( err == kNoError )
		err = renderStaticText( tempStaticTextP );

	if( err == kNoError )
	{
		SWLockSprite( (SpritePtr)tempStaticTextP );
		*newStaticTextPP = tempStaticTextP;
	}
	
	if( err != kNoError )
	{
			// clean up what we can
		if( tempStaticTextP ) st_DisposeStaticText( &tempStaticTextP );
		if( frameP ) SWDisposeFrame( &frameP );
	}
	
	SWSetStickyIfError( err );
	return err;
}