Example #1
0
geBoolean XFont_Create(XFont* fnt, char *name, int size, geBoolean anti, geEngine* theEngine){
	geFont *font;
	geRect cellRect;
	geBitmap *fontbmp;
	geFontCharacterRecord charRec;
	int i;

	assert( name );
	assert( size > 0 );

	strcpy( fnt->m_name, name );
	fnt->m_size = size;
	fnt->m_anti = anti;

	fnt->m_engine = theEngine;

	font = geFont_Create(theEngine, name, size, 0, anti );
	if ( font == NULL ) return GE_FALSE;

	geFont_AddCharacters( font, kFontLowRange, kFontHighRange ); // bang, font bitmap is built

	// create world to store the font bitmaps
	fnt->m_world = geWorld_Create( NULL ); // create an empty world
	if ( !fnt->m_world ) return GE_FALSE;

	// add the world to the engine
	if ( GE_FALSE == geEngine_AddWorld(theEngine, fnt->m_world ) )
		return GE_FALSE;

	// now build a set of individual character bitmaps and add each to the world
	
	fontbmp = font->bitmapList->map; // the big font bitmap containing all glyphs
	assert( fontbmp );

	for ( i = kFontLowRange; i <= kFontHighRange; i++ )
	{
		charRec = font->characterArray[i];
		cellRect = charRec.bitmapRect;

		fnt->m_chars[i].width = cellRect.Right - cellRect.Left;
		fnt->m_chars[i].height = cellRect.Bottom - cellRect.Top;
		fnt->m_chars[i].offsetY = fnt->m_size - fnt->m_chars[i].height;
		//assert( fnt->m_chars[i].offsetY >= 0 );

		fnt->m_chars[i].bitmap = geBitmap_Create( fnt->m_chars[i].width, fnt->m_chars[i].height,
			0/*<-- mip count*/, GE_PIXELFORMAT_8BIT );
		assert( fnt->m_chars[i].bitmap );

		if ( GE_FALSE == geBitmap_Blit( fontbmp,
			//charRec.offsetX, charRec.offsetY,
			cellRect.Left, cellRect.Top,
			fnt->m_chars[i].bitmap, 0, 0, fnt->m_chars[i].width, fnt->m_chars[i].height ) )
		{
			return GE_FALSE;
		}

		if ( GE_FALSE == geWorld_AddBitmap( fnt->m_world, fnt->m_chars[i].bitmap ) )
			return GE_FALSE;
	}

	geFont_Destroy( &font ); // we're done with the font now

	fnt->m_spaceWidth = fnt->m_size / 3;

	return GE_TRUE;
}
/* ------------------------------------------------------------------------------------ */
CAnimGif::CAnimGif(const char *szFile, int fileformat)
{
	long Size;

	GifSize = GlobalColorSize = 0;
	Active = false;
	Texture = false;
	GlobalColorTable = NULL;

	if(!CCD->OpenRFFile(&MainFS, fileformat, szFile, GE_VFILE_OPEN_READONLY))
		return;

	geVFile_Size(MainFS, &Size);

	Palette = geBitmap_Palette_Create(GE_PIXELFORMAT_32BIT_XRGB, 256);
	theBmp = NULL;
	pcGif = NULL;

	if(geVFile_Read(MainFS, buffer, 13) == GE_TRUE)
	{
		if(!strncmp((char *)buffer, "GIF89a", 6) || !strncmp((char *)buffer, "GIF87a", 6))
		{
			nWidth = *(WORD*)(buffer+6);
			nWidth = ((nWidth-1)|0x3)+1;
			nHeight = *(WORD*)(buffer+8);
			BackgroundColor = *(buffer+11);

			if(buffer[10]&0x80)
			{
				GlobalColorSize = 0x01<<((buffer[10]&0x07)+1);
				GlobalColorTable = new BYTE[3*GlobalColorSize];
				if(geVFile_Read(MainFS, GlobalColorTable, 3*GlobalColorSize) != GE_TRUE)
				{
					delete[] GlobalColorTable;
					geVFile_Close(MainFS);
					geBitmap_Palette_Destroy(&Palette);
					return;
				}
			}

			GifSize = Size-3*GlobalColorSize-12;
			pcGifTrack=pcGif = new BYTE[GifSize];

			if(geVFile_Read(MainFS, pcGif, GifSize) == GE_TRUE)
			{
				TotalReadByte = 0;
				FirstFrame = true;

				theBmp = geBitmap_Create(nWidth, nHeight, 1, GE_PIXELFORMAT_8BIT);
				geBitmap_SetPreferredFormat(theBmp, GE_PIXELFORMAT_8BIT);
				geEngine_AddBitmap(CCD->Engine()->Engine(), theBmp);
				geBitmap_GetInfo(theBmp,&Info,NULL);
				geBitmap_ClearMips(theBmp);

				if(GetImage(false))
				{
					Active = true;
				}
			}
		}
	}

	geVFile_Close(MainFS);
	return;
}