Beispiel #1
0
/*Create a sprite from an Image file*/
SWError SWCreateSpriteFromFile(
	SpritePtr* newSpriteP,
	void* spriteStorageP,
	const char * file,
	long maxFrames)
{
	SWError err = kNoError;
    FramePtr  tempFrameP = 0;
    SpritePtr tempSpriteP = 0;
    
    /*initialize the sprite*/
    err =  SWCreateSprite(&tempSpriteP, spriteStorageP, maxFrames);
	if (err == kNoError)
	{
		/*Add a single frame to the Sprite (for now) */
		err = SWCreateFrameFromFile(&tempFrameP, file);
	}
	
	if (err == kNoError)
	{
		err = SWAddFrame(tempSpriteP, tempFrameP);
	}

	if(err == kNoError )
	{
		err = SWSetCurrentFrameIndex(tempSpriteP, 0);
	}
    
	if (err == kNoError)
	{
		*newSpriteP = tempSpriteP;
	}
	
	return err;
}
Beispiel #2
0
SWError SWCreateSpriteFromFileSequence(
	SpritePtr* newSpriteP,
	void* spriteStorageP, 
    const char *filename, 
	int start, 
	long maxFrames)
{
	SWError err = kNoError;
    char tmp_file[255];
    int x;
    
    FramePtr tempFrameP;
    SpritePtr tempSpriteP;
    
	SW_UNUSED(spriteStorageP);

    tempSpriteP = *newSpriteP;
    
    /*initialize the sprite*/
	err =  SWCreateSprite(&tempSpriteP, 0, maxFrames);
	
	if (err == kNoError)
	{
		for(x = 0; x < maxFrames; x++)
		{
			sprintf(tmp_file, filename, x+start);
			
			err = SWCreateFrameFromFile(&tempFrameP, tmp_file);
			
			if (err == kNoError)
			{
				err = SWAddFrame(tempSpriteP, tempFrameP);
			}
			
			if (err != kNoError) 
			{
				SWDisposeFrame(&tempFrameP);
				SWDisposeSprite(&tempSpriteP);
				break;
			}
		}
	}
    
	if (err == kNoError)
	{
		SWSetSpriteFrameRange(tempSpriteP, 0, maxFrames - 1);
		err = SWSetCurrentFrameIndex(tempSpriteP, 0);
		*newSpriteP = tempSpriteP;
	}
	
	return err;
}
Beispiel #3
0
SpritePtr CreateStatsSpriteClone(
    SpritePtr masterSpriteP,
    short numDigits,
    JustifyType justification,
    int fillWithZeros)
{
    StatsStructPtr  spriteStructP;
    SpritePtr       newSpriteP;
    SWError         err = kNoError;
    
    SW_ASSERT(masterSpriteP != NULL);
    SW_ASSERT(masterSpriteP->maxFrames >= 10);
    
        // Allocate memory for the StatsStruct
    spriteStructP = (StatsStructPtr)calloc(1,sizeof(StatsStruct));
    if (!spriteStructP)
    {
            err = kMemoryAllocationError;
        }
        
    if (err == kNoError)
    {
        err = SWCloneSprite(masterSpriteP, &newSpriteP, spriteStructP);
    }
    
    if (err == kNoError)
    {
            // Set the Sprite's DrawProc to our special digit-drawing DrawProc.
        newSpriteP->frameDrawProc = StatsItemDrawProc;
        
            // Adjust the Sprite's width to match the width of all the digits put together.
        newSpriteP->drawData->scaledWidth = SW_RECT_WIDTH(newSpriteP->destFrameRect) * numDigits;
        newSpriteP->drawData->scaledHeight = SW_RECT_HEIGHT(newSpriteP->destFrameRect);
        SWSetCurrentFrameIndex(newSpriteP, newSpriteP->curFrameIndex);
        
        spriteStructP->numDigits = numDigits;
        spriteStructP->theNum = -1;
        spriteStructP->justification = justification;
        spriteStructP->fillWithZeros = fillWithZeros;
        spriteStructP->drawProc = SWStdSpriteDrawProc;
    }
    else
    {
        newSpriteP = NULL;
    }
    
    return newSpriteP;
}
Beispiel #4
0
SWError SWCreateSpriteFromSingleFileXY( 
	SpritePtr* newSpriteP,
	void* spriteStorageP,
	const char* fileName,
	int frameWidth,
	int frameHeight,
	int borderWidth,
	int borderHeight,
	int hasOutsideBorder,
	long maxFrames )
{
	SWError			err = kNoError;
	SDL_Surface	*	surface;
	SpritePtr		tempSpriteP;
	int 			widthStart, heightStart;
	SWRect			frameRect;
	int				frame;
	FramePtr 		newFrameP;
		
	surface = BKLoadSurface( fileName );
	if( ! surface ) 
		err = kSDLCreateSurfaceFromFile;
	
	if( err == kNoError )
	{
		if( maxFrames == 0 )
			maxFrames = (surface->w/frameWidth) * (surface->h/frameHeight);
		
		if ( hasOutsideBorder )
		{
			widthStart = borderWidth / 2;
			heightStart = borderHeight / 2;
		}
		else
		{
			widthStart = 0;
			heightStart = 0;
		}

		err = SWCreateSprite( newSpriteP, spriteStorageP, maxFrames);
	}
					
	if( err == kNoError )
	{
		tempSpriteP = *newSpriteP;
		tempSpriteP->sharedSurface = surface;

		frameRect.left = widthStart;
		frameRect.top = heightStart;
		frameRect.right = widthStart + frameWidth;
		frameRect.bottom = heightStart + frameHeight;
		
		for (frame = 0; frame < maxFrames; frame++)
		{
			err = SWCreateFrameFromSurfaceAndRect( &newFrameP, surface, &frameRect );
			
			if (err == kNoError)
			{
				err = SWAddFrame(tempSpriteP, newFrameP);
				if ( frame < maxFrames-1 )
				{
					frameRect.left += frameWidth + borderWidth;
					frameRect.right = frameRect.left + frameWidth;
					if ( frameRect.right > surface->w )
					{
						frameRect.left = widthStart;
						frameRect.right = widthStart + frameWidth;

						frameRect.top += frameHeight + borderHeight;
						frameRect.bottom = frameRect.top + frameHeight;
						if ( frameRect.bottom > surface->h )
						{
							err = kOutOfRangeErr;
						}
					}
				}
			}
			
			if ( err != kNoError )
			{
				SWDisposeFrame(&newFrameP);
				SWDisposeSprite(&tempSpriteP);
				break;
			}
		}
	}
		
	if (err == kNoError )
	{
		SWSetSpriteFrameRange(tempSpriteP, 0, maxFrames - 1);
		err = SWSetCurrentFrameIndex(tempSpriteP, 0);
	}
	
	SWSetStickyIfError( err );
	return err;
}
Beispiel #5
0
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;
}