Ejemplo n.º 1
0
bool CCTextureFontPageFile::load()
{
    CCText textureFile( name );
    textureFile += ".png";

    CCResourceType resourceType = CCFileManager::FindFile( textureFile.buffer );
    if( resourceType != Resource_Unknown )
    {
        texturePageIndex = gEngine->textureManager->assignTextureIndex( textureFile.buffer, resourceType, true, true, true );

        CCText csvFile = name;
        csvFile += ".csv";

        // Load the descriptor file
        CCText textData;
        CCFileManager::GetFile( csvFile.buffer, textData, resourceType );

        CCList<char> lettersSplit;
        textData.split( lettersSplit, "\n" );

        CCText rawLetterData;
        CCList<char> letterDataSplit;
        for( int i=0; i<lettersSplit.length; ++i )
        {
            const char *raw = lettersSplit.list[i];
            rawLetterData.set( raw );

            letterDataSplit.clear();
            rawLetterData.split( letterDataSplit, "," );
            ASSERT( letterDataSplit.length == 4 );

            Letter &letter = letters[i];
            const char *x1 = letterDataSplit.list[0];
            const char *y1 = letterDataSplit.list[1];
            const char *x2 = letterDataSplit.list[2];
            const char *y2 = letterDataSplit.list[3];

            letter.start.x = (float)atof( x1 );
            letter.start.y = (float)atof( y1 );
            letter.end.x = (float)atof( x2 );
            letter.end.y = (float)atof( y2 );

            // 16.0f because there's 16 tiles per font page
            letter.size.width = ( letter.end.x - letter.start.x ) * 16.0f;
            letter.size.height = ( letter.end.y - letter.start.y ) * 16.0f;
        }

        return true;
    }
    return false;
}
Ejemplo n.º 2
0
const bool CCTextureFontPageFile::load(const char *name, const CCResourceType resourceType, const bool generateMipMap)
{
    CCText textureFilename( name );
    textureFilename += ".png";
    texturePageIndex = gEngine->textureManager->assignTextureIndex( textureFilename.buffer, resourceType, true, generateMipMap );
    
    CCText filename( name );
    filename += ".data";
    
	// Load the descriptor file
    char *fileData = NULL;
    CCFileManager::getPackagedFile( filename.buffer, &fileData );
    CCText textData( fileData );
    FREE_POINTER( fileData );
    
    CCList<char> *lettersSplit = textData.split( "\n" );
    CCText rawLetterData;
    for( int i=0; i<lettersSplit->length; ++i )
    {
        const char *raw = lettersSplit->list[i];
        rawLetterData.set( raw );
        
        CCList<char> *letterDataSplit = rawLetterData.split( "," );
        ASSERT( letterDataSplit->length == 4 );
        
        Letters &letter = letters[i];
        letter.start.x = (float)atof( letterDataSplit->list[0] );
        letter.start.y = (float)atof( letterDataSplit->list[1] );
        letter.end.x = (float)atof( letterDataSplit->list[2] );
        letter.end.y = (float)atof( letterDataSplit->list[3] );

        // 16.0f because there's 16 tiles per font page
        letter.size.width = ( letter.end.x - letter.start.x ) * 16.0f;
        letter.size.height = ( letter.end.y - letter.start.y ) * 16.0f;
        
        DELETE_POINTER( letterDataSplit );
    }
    DELETE_POINTER( lettersSplit );
	
	return true;
}