Beispiel #1
0
void
SFont_WriteCenter (SDL_Surface * Surface, SFont_Font * Font,
		   int y, char *text)
{
  SFont_Write (Font, Surface->w / 2 - SFont_TextWidth (Font, text) / 2,
	       y, text);
}
Beispiel #2
0
void gfx_draw_text(SDL_Surface * screen, SFont_Font * font, const int x,
                   const int y, const int useshadow, const int useglow,
                   char *string)
{
    if (y > screen->h || y + gfx_text_height(font) < 0)
        return;

    SFont_Write(screen, font, x, y, useshadow, useglow, string);
}
Beispiel #3
0
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;
}
Beispiel #4
0
void
SFont_WriteAligned (SFont_Font * Font, int x, int y, int w,
		    int gap, int align, char *text)
{
  char buf[512] = "";
  int width = 0;
  int ww = 0;
  int len = strlen (text);
  int i = 0;
  int nextWord = 0;

  if (text == NULL)
    return;

  for (i = 0; i < len; i++)
    {
      ww = wordWidth (Font, text, i, nextWord + 1);
      if ((width + ww) >= w)
	{
	  switch (align)
	    {
	    case ALEFT:
	      SFont_Write (Font, x, y, buf);
	      break;
	    case ARIGHT:
	      SFont_Write (Font, x + w - width, y, buf);
	      break;
	    case ACENTER:
	      SFont_Write (Font, x + (w - width) / 2, y, buf);
	      break;
	    default:
	      break;
	    }
	  width = 0;
	  buf[0] = '\0';
	  y += Font->Surface->h + gap;
	}
      width += ww;
      copyWord (Font, text, buf, i, nextWord);
      i = nextWord;
      nextWord = findWord (Font, text, i + 1);
    }

  switch (align)
    {
    case ALEFT:
      SFont_Write (Font, x, y, buf);
      break;
    case ARIGHT:
      SFont_Write (Font, x + w - width, y, buf);
      break;
    case ACENTER:
      SFont_Write (Font, x + (w - width) / 2, y, buf);
      break;
    default:
      break;
    }
}
Beispiel #5
0
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; 
}
Beispiel #6
0
	void FontTool::drawText(int xpos, int ypos, const char* text, SDL_Surface *display) {
		if(sfont) SFont_Write(display, FontTool::sfont, xpos,ypos,text);
	}
Beispiel #7
0
void
drawRecords (data_t * gfx, records_t * rtab, int hl)
{
  int x, x1, x2, x3, x4, x5, x6, y, w, h, i;
  char buf[128];

  x = gfx->gameX + 2 * BLOCKSIZE;
  w = GRIDWIDTH * BLOCKSIZE - 4 * BLOCKSIZE;
  h = BLOCKSIZE + 12 * gfx->textfont->Surface->h
    + SFont_AlignedHeight (gfx->textfont, w - 2 * BLOCKSIZE, 0,
			   _
			   ("Press any key to continue. Read the README or the 'man' page to learn the meaning of the 'mode' column."));
  y = gfx->gameY + (GRIDHEIGHT * BLOCKSIZE - h) / 2;

  drawAnimatedSquare (gfx, gfx->gcolor, gfx->galpha, x, y, w, h, MSGTIME);
  /*
     x1:#  x2:Name                       x3:Floor x4:Mode x5:Time x6: Date
     ---------------------------------------------------------------------
   */
  y += BLOCKSIZE;

  x1 = x + BLOCKSIZE;

  x2 = x1 + SFont_TextWidth (gfx->textfont, "#   ");
  sprintf (buf, "%s %s %s %s", _("Floor"), _("Mode"), _("Time"),
	   rtab[0].date);

  x3 = x1 + w - 2 * BLOCKSIZE - SFont_TextWidth (gfx->textfont, buf);
  sprintf (buf, "%s %s %s %s", _("Floor"), _("Mode"), _("Time"), _("Date"));
  SFont_Write (gfx->textfont, x3, y, buf);
  sprintf (buf, "%s ", _("Floor"));

  x4 = x3 + SFont_TextWidth (gfx->textfont, buf);
  sprintf (buf, "%s ", _("Mode"));

  x5 = x4 + SFont_TextWidth (gfx->textfont, buf);
  sprintf (buf, "%s ", _("Time"));

  x6 = x5 + SFont_TextWidth (gfx->textfont, buf);
  sprintf (buf, "#  %s ", _("Date"));
  SFont_Write (gfx->textfont, x1, y, buf);

  for (i = 0; i < MAX_RECORDS; i++)
    {
      y += gfx->textfont->Surface->h - 1;

      if (hl == i)
	{
	  sprintf (buf, ">");
	  SFont_Write (gfx->textfont,
		       x1 - SFont_TextWidth (gfx->textfont, buf), y, buf);
	}

      sprintf (buf, "%d", i + 1);
      SFont_Write (gfx->textfont, x1, y, buf);

      SFont_Write (gfx->textfont, x2, y, rtab[i].pname);
      SFont_FillWith (gfx->textfont,
		      x2 + SFont_TextWidth (gfx->textfont, rtab[i].pname) + 3,
		      y,
		      x3 - 6 - (x2 +
				SFont_TextWidth (gfx->textfont,
						 rtab[i].pname)), '.');

      sprintf (buf, "%d", rtab[i].floor);
      SFont_Write (gfx->textfont, x3, y, buf);

      SFont_Write (gfx->textfont, x4, y, rtab[i].mode);

      sprintf (buf, "%d", rtab[i].time);
      SFont_Write (gfx->textfont, x5, y, buf);

      sprintf (buf, "%s", rtab[i].date);
      SFont_Write (gfx->textfont, x6, y, buf);
    }
  y += gfx->textfont->Surface->h * 2;
  SFont_WriteAligned (gfx->textfont, x1, y, w - 2 * BLOCKSIZE,
		      0, ALEFT,
		      _
		      ("Press any key to continue. Read the README or the 'man' page to learn the meaning of the 'mode' column."));

  FlipScreen ();
}
Beispiel #8
0
void SFont_WriteRight(const SFont_Font *Font,
					  int y, const char *text)
{
	SFont_Write(Font, winwidth - SFont_TextWidth(Font, text), y, text);
}
Beispiel #9
0
void SFont_WriteCenter(const SFont_Font *Font,
					   int y, const char *text)
{
	SFont_Write(Font, (winwidth - SFont_TextWidth(Font, text))/2, y, text);
}