示例#1
0
文件: text.c 项目: svn2github/GrafX2
byte *Render_text_SFont(const char *str, int font_number, int *width, int *height)
{
  SFont_Font *font;
  SDL_Surface * TexteColore;
  SDL_Surface * Texte8Bit;
  SDL_Surface *Surface_fonte;
  byte * new_brush;

  // Chargement de la fonte
  Surface_fonte=IMG_Load(Font_name(font_number));
  if (!Surface_fonte)
  {
    DEBUG("Font loading failed",0);
    return NULL;
  }
  font=SFont_InitFont(Surface_fonte);
  if (!font)
  {
    DEBUG("Font init failed",1);
    return NULL;
  }
  
  // Calcul des dimensions
  *height=SFont_TextHeight(font);
  *width=SFont_TextWidth(font, str);
  // Allocation d'une surface SDL
  TexteColore=SDL_CreateRGBSurface(SDL_SWSURFACE, *width, *height, 24, 0, 0, 0, 0);
  // Rendu du texte
  SFont_Write(TexteColore, font, 0, 0, str);
  if (!TexteColore)
  {
    DEBUG("Rendering failed",2);
    SFont_FreeFont(font);
    return NULL;
  }
  
  Texte8Bit=SDL_DisplayFormat(TexteColore);
  SDL_FreeSurface(TexteColore);
    
  new_brush=Surface_to_bytefield(Texte8Bit, NULL);
  if (!new_brush)
  {
    DEBUG("Converting failed",3);
    SDL_FreeSurface(TexteColore);
    SDL_FreeSurface(Texte8Bit);
    SFont_FreeFont(font);
    return NULL;
  }
  SDL_FreeSurface(Texte8Bit);
  SFont_FreeFont(font);

  return new_brush;
}
示例#2
0
Font* Font_Factory::create_font(Font_Type type)
{
	std::string m_res_factory(Resource_Factory::instance()->get_resource_path());
	
	Font* font = new Font();
	switch(type)
	{
		case GAME_FONT:
			m_res_factory += "/gfx/game_font.bmp";
			break;
		case TIME_FONT:
			m_res_factory += "/gfx/time_font.bmp";
			break;
		case CREDITS_FONT:
			m_res_factory += "/gfx/credits_font.bmp";
			break;
		case MENU_FONT:
			m_res_factory += "/gfx/menu_font.bmp";
			break;
		default:
			assert(!"Error: Selected non-existing font type.");
	}
	DEBOUT("Loading font: "<<m_res_factory<<"...\n");
	SDL_Surface* temp = SDL_LoadBMP(m_res_factory.c_str());
	SDL_Surface* temp2 = SDL_DisplayFormat(temp);
	
	if(temp2!=NULL)
	{
		font->init(SFont_InitFont (temp2));
	}
	else
	{
		DEBOUT("Error: "<<m_res_factory<<" is not a valid font: "<<SDL_GetError()<<"\n");
	}
	
	SDL_FreeSurface(temp);
	
	return font;
}
示例#3
0
文件: main.c 项目: clach04/dingoo-sdk
int main(int argc, char *argv[]) 
{
    SDL_Surface* screen =NULL;
    bool done = false; 
    SDL_Event evt; 
    int FPS = 0; 
    int pastFPS = 0; 
    int past = 0; 
    int currentTime = 0;
    static char buffer[20] = {0};
    
    SDL_Surface *font_bitmap_surface=NULL;
    SFont_Font* Font;
    
    
    
    /* Initialize SDL */
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        exit (1);
    }
    
    SDL_ShowCursor(SDL_DISABLE); /* There is no mouse */

    /* Initialize the screen / window */
    /*screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE|SDL_FULLSCREEN);  SDL_FULLSCREEN not needed on Dingoo, useful on desktop */
    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
    if (screen == NULL)
    {
        SDL_Quit();
        exit (2);
    }
    
    SDL_WM_SetCaption ("SDL MultiMedia Application", NULL); /* Not needed on Dingoo */

    font_bitmap_surface = get_default_data_font();
    Font = SFont_InitFont(font_bitmap_surface);
    if(!Font) {
        fprintf(stderr, "An error occured while setting up font.");
        exit(1);
    }
    
    while(!done) 
    {
        if( SDL_PollEvent(&evt) ) 
        { 
            switch (evt.type)
            {
                        case SDL_KEYDOWN:
                             /* quit on any key press */
                             done = true; 
                             break;
                        case SDL_QUIT:
                             done = true; 
                             break;
            }
        }

        currentTime = SDL_GetTicks();
#define LOCK_FPS_TO_60FPS
#undef LOCK_FPS_TO_60FPS
#ifdef LOCK_FPS_TO_60FPS
        /*
        ** Alternative is to sleep....
        ** however sleep may not have the expected granularity (e.g. under native)
        ** Check if 1/60th of a second has elapsed
        ** 1 (sec) / 60 == 1000 (millisec) / 60 == 16.66666666666666.... ~16
        */
        if ( currentTime - past >= 16 ) 
#endif /* LOCK_FPS_TO_60FPS */
        { 
            past = SDL_GetTicks(); /* this should be done before redrawing screen */

            #define ALWAYS_FLIP
            #ifdef ALWAYS_FLIP
            SFont_Write(screen, Font, 0, 20, "Hello World");
            SDL_UpdateRect(screen, 0, 0, 0, 0);
            #endif /* ALWAYS_FLIP */
            FPS++; 
        }

        /*
        ** Every 1 second re-calculate FPS display string
        */
        if ( currentTime - pastFPS >= 1000 )
        { 
            sprintf( buffer, "%d FPS", FPS );
            SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 ); /* rather brute force wipe out area first... */
            SFont_Write (screen, Font, 0,0, buffer);
            SDL_UpdateRect(screen, 0, 0, 0, 0); /* SDL_UpdateRect() is a way to only mark part of the screen as updated for performance */
            #ifndef ALWAYS_FLIP
            SDL_Flip( screen );
            #endif /* ALWAYS_FLIP */
        
            FPS = 0;
            pastFPS = currentTime;
        }
    }

    SFont_FreeFont(Font);
    SDL_Quit();

    return 0; 
}
示例#4
0
void init_text(int splash)
{
	SDL_Event ev;
	int toexit=0;
	SDL_Surface *sur;
	SDL_Rect r;
	int i,j;


	if (!text_screen)
	{

//		text_screen=SDL_ConvertSurface(screen,screen->format,0);
		text_screen=SDL_CreateRGBSurface(screen->flags,screen->w,screen->h,screen->format->BitsPerPixel,screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,screen->format->Amask);
//		text_screen=SDL_DisplayFormat(screen);
		if (!text_screen)
		{
#ifdef STDOUTPUT
			puts("Unable to make a SDL_Surface (text_screen)");
#endif
			exit(-1);

		}
	}

#ifdef DREAMCAST
        __sdl_dc_emulate_keyboard=1;
#endif
	if (!splash)
	{
		menu_raise();
		return;
	}

	text_image2=load_img_0(MENU_FILE_TEXT2);
	font_inv.Surface=text_image2;
	SFont_InitFontInfo(&font_inv);

	text_image=load_img_0(MENU_FILE_TEXT);
	SFont_InitFont(text_image);

	text_win_uleft=load_img_255(MENU_FILE_WIN_ULEFT);
	text_win_uright=load_img_255(MENU_FILE_WIN_URIGHT);
	text_win_upper=load_img_255(MENU_FILE_WIN_UPPER);
	text_win_left=load_img_255(MENU_FILE_WIN_LEFT);
	text_win_right=load_img_255(MENU_FILE_WIN_RIGHT);
	text_win_bright=load_img_255(MENU_FILE_WIN_BRIGHT);
	text_win_bleft=load_img_255(MENU_FILE_WIN_BLEFT);
	text_win_bottom=load_img_255(MENU_FILE_WIN_BOTTOM);
	text_cdrom=menu_IMG_Load(MENU_FILE_LOADING);

	init_background();

	obten_colores();
	sound_play_menu_music();
#ifndef AUTO_EVENTS
	sur=menu_IMG_Load(MENU_FILE_SPLASH);
	r.x=(text_screen->w - sur->w)/2;
	r.y=(text_screen->h - sur->h)/2;
	r.h=sur->w;
	r.w=sur->h;
	SDL_FillRect(text_screen,NULL,0); //0xFFFFFFFF);
	while(SDL_PollEvent(&ev)) SDL_Delay(50);
	for (i=128;(i>-8)&&(!toexit);i-=8)
	{
#ifdef DREAMCAST
		vid_waitvbl();
#else
		SDL_Delay(50);
#endif
		SDL_FillRect(text_screen,NULL,0); //0xFFFFFFFF);
		SDL_BlitSurface(sur,NULL,text_screen,&r);
		fade16(text_screen,i);
		text_flip();
		while(SDL_PollEvent(&ev)) toexit=1;
	}
	for(i=0;(i<23)&&(!toexit);i++)
	{
		while(SDL_PollEvent(&ev)) toexit=1;
		SDL_Delay(100);
	}
	for(i=0;(i<128)&&(!toexit);i+=16)
	{
#ifdef DREAMCAST
		vid_waitvbl();
#else
		SDL_Delay(50);
#endif
		SDL_FillRect(text_screen,NULL,0); //0xFFFFFFFF);
		SDL_BlitSurface(sur,NULL,text_screen,&r);
		fade16(text_screen,i);
		text_flip();
		while(SDL_PollEvent(&ev)) toexit=1;
	}
	for(i=128;(i>-8)&&(!toexit);i-=8)
	{
#ifdef DREAMCAST
		vid_waitvbl();
#else
		SDL_Delay(50);
#endif
		text_draw_background();
		fade16(text_screen,i);
		text_flip();
		while(SDL_PollEvent(&ev)) toexit=1;
	}
	SDL_FreeSurface(sur);
#else
#ifndef DREAMCAST
	chdir(ROM_PREFIX);
#else
//	fs_chdir(ROM_PREFIX);
	fs_chdir("/");//ROM_PREFIX);
#endif
#endif
//	menu_msg_time=SDL_GetTicks();
}