Exemplo n.º 1
0
void
SFont_WriteMaxWidth (SFont_Font * Font, int x, int y, int w, int align,
		     char *tag, char *text)
{
  int tagw = SFont_TextWidth (Font, tag);
  int width = SFont_TextWidth (Font, text);
  int i = 0;
  char *buf = NULL;

  if (width >= w - tagw)
    {
      buf = malloc (sizeof (char) * (strlen (text) + 1));
      width = 0;
      while (width <= w - tagw)
	{
	  buf[i] = text[i];
	  buf[i + 1] = '\0';
	  width += charWidth (Font, text[i]);
	  i++;
	}
      width -= charWidth (Font, text[i]);
      buf[--i] = '\0';
      strcat (buf, tag);
      width += tagw;
    }
  else
    {
      buf = text;
    }

  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;
    }

  if (buf != text)
    free (buf);

}
Exemplo n.º 2
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);
}
Exemplo n.º 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;
}
Exemplo n.º 4
0
	int FontTool::getTextWidth(const char *text) {
		return SFont_TextWidth(FontTool::sfont,text);
	}
Exemplo n.º 5
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 ();
}
Exemplo n.º 6
0
void SFont_WriteRight(const SFont_Font *Font,
					  int y, const char *text)
{
	SFont_Write(Font, winwidth - SFont_TextWidth(Font, text), y, text);
}
Exemplo n.º 7
0
void SFont_WriteCenter(const SFont_Font *Font,
					   int y, const char *text)
{
	SFont_Write(Font, (winwidth - SFont_TextWidth(Font, text))/2, y, text);
}
Exemplo n.º 8
0
int gfx_text_width(SFont_Font * font, const char *s)
{
    return SFont_TextWidth(font, s);
}