コード例 #1
0
ファイル: font.cpp プロジェクト: CliffsDover/NXEngine-iOS
bool font_init(void)
{
bool error = false;

	// we'll be bypassing the NXSurface automatic scaling features
	// and drawing at the real resolution so we can get better-looking fonts.
//	sdl_screen = screen->GetSDLSurface();
	
	// at 320x240 switch to bitmap fonts for better appearance
	#ifdef CONFIG_ENABLE_TTF
	if (SCALE == 1)
	#endif
	{
		stat("fonts: using bitmapped from %s", bmpfontfile);
		
		SDL_RWops* rwops = fileopen_SDL_RWops_RO(bmpfontfile);
		if (!rwops) { staterr("Couldn't open bitmap font file %s: SDL_RWFromFP: %s", bmpfontfile, SDL_GetError()); return 1; }
		SDL_Surface *sheet = SDL_LoadBMP_RW(rwops, 1);
		if (!sheet) { staterr("Couldn't open bitmap font file: SDL_LoadBMP_RW: %s", SDL_GetError()); return 1; }
		
		uint32_t fgindex = SDL_MapRGB(sheet->format, 255, 255, 255);
		
		error = error || whitefont.InitBitmapChars(sheet, fgindex, 0xffffff);
		error = error || greenfont.InitBitmapChars(sheet, fgindex, 0x00ff80);
		error = error || bluefont.InitBitmapChars(sheet, fgindex, 0xa0b5de);
		error = error || shadowfont.InitBitmapCharsShadowed(sheet, fgindex, 0xffffff, 0x000000);
	}
	#ifdef CONFIG_ENABLE_TTF
	else
	{
		// It will get size 8, 17, 26, 35, ...
		// Hope ot will look nice on higher resolutions
		int pointsize = 8 + 9 * (SCALE - 1);
        
		stat("fonts: using truetype at %dpt", pointsize);

		// initilize normal TTF fonts
		if (TTF_Init() < 0)
		{
			staterr("Couldn't initialize SDL_ttf: %s", TTF_GetError());
			return 1;
		}
		
		TTF_Font *font = TTF_OpenFontRW(SDL_RWFromFP(fileopenRO(ttffontfile), SDL_TRUE), 1, pointsize);
		if (!font)
		{
			staterr("Couldn't open font: '%s'", ttffontfile);
			return 1;
		}
		
		error = error || whitefont.InitChars(font, 0xffffff);
		error = error || greenfont.InitChars(font, 0x00ff80);
		error = error || bluefont.InitChars(font, 0xa0b5de);
		error = error || shadowfont.InitCharsShadowed(font, 0xffffff, 0x000000);
		
		TTF_CloseFont(font);
	}
	#endif

	error = error || whitefont.InitTextures();
	error = error || greenfont.InitTextures();
	error = error || bluefont.InitTextures();
	error = error || shadowfont.InitTextures();
	
	error = error || create_shade_sfc();
	if (error) return 1;
	
	fontheight = (whitefont.letters['M']->h / SCALE);
	initilized = true;
	return 0;
}
コード例 #2
0
ファイル: font.cpp プロジェクト: EXLMOTODEV/NXEngine
bool font_init(void)
{
bool error = false;

	// we'll be bypassing the NXSurface automatic scaling features
	// and drawing at the real resolution so we can get better-looking fonts.
	sdl_screen = screen->GetSDLSurface();
	
	// at 320x240 switch to bitmap fonts for better appearance
#if (defined(_320X240) || defined(_480X272)) && defined(_L10N_CP1251)
    if (false)
#elif defined(CONFIG_ENABLE_TTF)
    if (SCALE == 1)
#endif
	{
		stat("fonts: using bitmapped from %s", bmpfontfile);
		
		SDL_Surface *sheet = SDL_LoadBMP(bmpfontfile);
		if (!sheet)
		{
			staterr("Couldn't open bitmap font file: '%s'", bmpfontfile);
			return 1;
		}
		
		uint32_t fgindex = SDL_MapRGB(sheet->format, 255, 255, 255);
		
		error |= whitefont.InitBitmapChars(sheet, fgindex, 0xffffff);
		error |= greenfont.InitBitmapChars(sheet, fgindex, 0x00ff80);
		error |= bluefont.InitBitmapChars(sheet, fgindex, 0xa0b5de);
		error |= shadowfont.InitBitmapCharsShadowed(sheet, fgindex, 0xffffff, 0x000000);
	}
    #ifdef CONFIG_ENABLE_TTF
	else
	{
		stat("fonts: using truetype at %dpt", pointsize[SCALE]);
		
		// initilize normal TTF fonts
		if (TTF_Init() < 0)
		{
			staterr("Couldn't initialize SDL_ttf: %s", TTF_GetError());
			return 1;
		}

        TTF_Font *font = TTF_OpenFont(ttffontfile, pointsize[SCALE]);
		if (!font)
		{
			staterr("Couldn't open font: '%s'", ttffontfile);
			return 1;
		}
		
		error |= whitefont.InitChars(font, 0xffffff);
		error |= greenfont.InitChars(font, 0x00ff80);
		error |= bluefont.InitChars(font, 0xa0b5de);
		error |= shadowfont.InitCharsShadowed(font, 0xffffff, 0x000000);
		
		TTF_CloseFont(font);
	}
    #endif
	
	error |= create_shade_sfc();
	if (error) return 1;
	
	fontheight = (whitefont.letters['M']->h / SCALE);
	initilized = true;
	return 0;
}