Beispiel #1
0
void TFont::surf_string_tr(SDL_Surface *surf,int x, int y, const char *s, int color,int w) {
  if (loaded_font)
    gfxPrimitivesSetFont(loaded_font,charWidth,charHeight);
  if (charWidth*strlen(s) > (unsigned)w) {
      int len = w/charWidth;
      char *dup = strdup(s);
      dup[len+1] = 0;
      stringColor(surf,x,y,dup,color);
      free(dup);
  } else
      stringColor(surf,x,y,s,color);
}
Beispiel #2
0
void TFont::load_font(char *myfont) {
  FILE *f;
  unsigned int len,width,height;
  get_font_dimensions(myfont,&width,&height);
  if (!width || !height) { // load default font
    charWidth = charHeight = 0;
    if (loaded_font) {
      free(loaded_font);
      loaded_font = NULL;
    }
    return;
  }
  if (strchr(myfont,'/') == 0) {
    char tpath[1024];
    sprintf(tpath,"fonts/%s",myfont);
    f = fopen(get_shared(tpath),"rb");
  } else
    f = fopen(get_shared(myfont),"rb");

  if (f) {
    fseek(f,0L,SEEK_END);
    len = ftell(f);
    fseek(f,0L,SEEK_SET);
    if (loaded_font)
      free(loaded_font);

    loaded_font = (char*)malloc(len);
    if (loaded_font) {
      fread(loaded_font,len,1,f);
      charWidth = width;
      charHeight = height;
      gfxPrimitivesSetFont(loaded_font,charWidth,charHeight);
    } else {
      charWidth = charHeight = 0;
      // in this case CharWidth = CharHeight = 8, see get_font_height...
    }
    fclose(f);
  }
}
Beispiel #3
0
void Draw(SDL_Surface *screen)
{
 FILE *file;
 char *myfont;
 char mytext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
 /* Black screen */
 ClearScreen(screen);

 /* Load a font and draw with it */
 myfont=(char *)malloc(1792);
 file = fopen(RELPATH "Fonts/5x7.fnt","r");
 fread(myfont,1792,1,file);
 fclose(file);
 gfxPrimitivesSetFont(myfont,5,7);
 stringRGBA(screen,10,10,mytext,255,255,255,255);
 free(myfont);

 /* Load a font and draw with it */
 myfont=(char *)malloc(3328);
 //
 file = fopen(RELPATH "Fonts/7x13.fnt","r");
 fread(myfont,3328,1,file);
 fclose(file);
 gfxPrimitivesSetFont(myfont,7,13);
 stringRGBA(screen,10,30,mytext,255,255,255,255);
 //
 file = fopen(RELPATH "Fonts/7x13B.fnt","r");
 fread(myfont,3328,1,file);
 fclose(file);
 gfxPrimitivesSetFont(myfont,7,13);
 stringRGBA(screen,10,50,mytext,255,255,255,255);
 //
 file = fopen(RELPATH "Fonts/7x13O.fnt","r");
 fread(myfont,3328,1,file);
 fclose(file);
 gfxPrimitivesSetFont(myfont,7,13);
 stringRGBA(screen,10,70,mytext,255,255,255,255);
 //
 free(myfont);

 /* Load a font and draw with it */
 myfont=(char *)malloc(9216);
 //
 file = fopen(RELPATH "Fonts/9x18.fnt","r");
 fread(myfont,9216,1,file);
 fclose(file);
 gfxPrimitivesSetFont(myfont,9,18);
 stringRGBA(screen,10,90,mytext,255,255,255,255);
 //
 file = fopen(RELPATH "Fonts/9x18B.fnt","r");
 fread(myfont,9216,1,file);
 fclose(file);
 gfxPrimitivesSetFont(myfont,9,18);
 stringRGBA(screen,10,110,mytext,255,255,255,255);
 //
 free(myfont);
 
 /* Display by flipping screens */
 SDL_UpdateRect(screen,0,0,0,0);
 
 while (1) {
  
  /* Events */
  HandleEvent();
  

  /* Delay to limit rate */                   
  SDL_Delay(1000);  
 }
}
Beispiel #4
0
void Draw(SDL_Surface *screen)
{
	int i, rotation;
	char *myfont;
	char mytext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int x,y,yold;

	/* Black screen */
	ClearScreen(screen);
	y=0; 

	/* Try all horizontal rotations */
	rotation = 0;
	gfxPrimitivesSetFontRotation(rotation);

	/* Render all fonts */ 
	for (i=0; i<NUM_SDLGFX_FONTS; i++) {
		fprintf(stderr,"Drawing Font: size %ix%i, file '%s', %i bytes, rotation %i\n",fontw[i], fonth[i], fontfile[i],fontsize[i], rotation);
		/* Reset line pos */
		x=4;
		myfont = NULL;
		if (i>0) {
			myfont=LoadFontFile(i);
		}
		/* Set font data and use it */
		gfxPrimitivesSetFont(myfont,fontw[i],fonth[i]);
		y += fonth[i];
		stringRGBA(screen,x,y,fontfile[i],255,255,255,255);
		x += 100;
		stringRGBA(screen,x,y,mytext,255,255,255,255);
		y += 10;
		if (i>0)
		{
			/* Clean up font-data */
			free(myfont);
		}
	}

	y += 20;

	yold = y;

	rotation = 2;
	gfxPrimitivesSetFontRotation(rotation);

	/* Render all fonts */ 
	for (i=0; i<NUM_SDLGFX_FONTS; i++) {
		fprintf(stderr,"Drawing Font: size %ix%i, file '%s', %i bytes, rotation %i\n",fontw[i], fonth[i], fontfile[i],fontsize[i], rotation);
		/* Reset line pos */
		x=WIDTH - 14;
		myfont = NULL;
		if (i>0) {
			myfont=LoadFontFile(i);
		}
		/* Set font data and use it */
		gfxPrimitivesSetFont(myfont,fontw[i],fonth[i]);
		y += fonth[i];
		stringRGBA(screen,x,y,fontfile[i],255,255,255,255);
		x -= 100;
		stringRGBA(screen,x,y,mytext,255,255,255,255);
		y += 10;
		if (i>0)
		{
			/* Clean up font-data */
			free(myfont);
		}
	}

	y += 20;

	/* Try all vertical rotations */
	rotation = 1;
	gfxPrimitivesSetFontRotation(rotation);

	x = 14;

	/* Render all fonts */ 
	for (i=0; i<NUM_SDLGFX_FONTS; i++) {
		fprintf(stderr,"Drawing Font: size %ix%i, file '%s', %i bytes, rotation %i\n",fontw[i], fonth[i], fontfile[i],fontsize[i], rotation);
		/* Reset line pos */
		y=yold;
		myfont = NULL;
		if (i>0) {
			myfont=LoadFontFile(i);
		}
		/* Set font data and use it */
		gfxPrimitivesSetFont(myfont,fontw[i],fonth[i]);
		x += fonth[i];
		stringRGBA(screen,x,y,fontfile[i],255,255,255,255);
		y += 100;
		stringRGBA(screen,x,y,mytext,255,255,255,255);
		x += 10;
		if (i>0)
		{
			/* Clean up font-data */
			free(myfont);
		}
	}

	x += 20;

	rotation = 3;
	gfxPrimitivesSetFontRotation(rotation);

	/* Render all fonts */ 
	for (i=0; i<NUM_SDLGFX_FONTS; i++) {
		fprintf(stderr,"Drawing Font: size %ix%i, file '%s', %i bytes, rotation %i\n",fontw[i], fonth[i], fontfile[i],fontsize[i], rotation);
		/* Reset line pos */
		y=HEIGHT - 14;
		myfont = NULL;
		if (i>0) {
			if (i>0) {
				myfont=LoadFontFile(i);
			}
			/* Set font data and use it */
			gfxPrimitivesSetFont(myfont,fontw[i],fonth[i]);
			x += fonth[i];
			stringRGBA(screen,x,y,fontfile[i],255,255,255,255);
			y -= 100;
			stringRGBA(screen,x,y,mytext,255,255,255,255);
			x += 10;
			if (i>0)
			{
				/* Clean up font-data */
				free(myfont);
			}
		}

		/* Display by flipping screens */
		SDL_Flip(screen); 
	}
}
Beispiel #5
0
CAMLprim value ml_gfxPrimitivesSetFont(value fd,value cw,value ch)
{
  gfxPrimitivesSetFont(String_val(fd),Int_val(cw),Int_val(ch));
  return Val_unit;
}