version 1.4 | | version 1.5 |
---|
| | |
* Fonts for the game. | | * Fonts for the game. |
* | | * |
* $Log$ | | * $Log$ |
| | * Revision 1.5 1999/11/20 10:05:17 donut |
| | * variable size menu patch from Jan Bobrowski. Variable menu font size support and a bunch of fixes for menus that didn't work quite right, by me (MPM). |
| | * |
* Revision 1.4 1999/10/08 09:00:47 donut | | * Revision 1.4 1999/10/08 09:00:47 donut |
* fixed undefined error on mingw | | * fixed undefined error on mingw |
* | | * |
| | |
#include "hudmsg.h" | | #include "hudmsg.h" |
#include "gamefont.h" | | #include "gamefont.h" |
| | |
char * Gamefont_filenames[] = { "font1-1.fnt", // Font 0 | | char * Gamefont_filenames_l[] = { "font1-1.fnt", // Font 0 |
"font2-1.fnt", // Font 1 | | "font2-1.fnt", // Font 1 |
"font2-2.fnt", // Font 2 | | "font2-2.fnt", // Font 2 |
"font2-3.fnt", // Font 3 | | "font2-3.fnt", // Font 3 |
"font3-1.fnt" // Font 4 | | "font3-1.fnt" // Font 4 |
}; | | }; |
| | |
| | //large fonts from d2: |
| | char * Gamefont_filenames_h[] = { "font1-1h.fnt", // Font 0 |
| | "font2-1h.fnt", // Font 1 |
| | "font2-2h.fnt", // Font 2 |
| | "font2-3h.fnt", // Font 3 |
| | "font3-1h.fnt" // Font 4 |
| | }; |
| | |
grs_font *Gamefonts[MAX_FONTS]; | | grs_font *Gamefonts[MAX_FONTS]; |
| | |
int Gamefont_installed=0; | | int Gamefont_installed=0; |
| | |
//code to allow variable GAME_FONT, added 10/7/99 Matt Mueller | | //code to allow variable GAME_FONT, added 10/7/99 Matt Mueller - updated 11/18/99 to handle all fonts, not just GFONT_SMALL |
// take scry into account? how/when? | | // take scry into account? how/when? |
typedef struct _gamefont_conf{ | | typedef struct _a_gamefont_conf{ |
int x; | | int x; |
int builtin; | | |
union{ | | union{ |
char name[64];//hrm. | | char name[64];//hrm. |
grs_font *ptr; | | grs_font *ptr; |
} f; | | } f; |
| | }a_gamefont_conf; |
| | typedef struct _gamefont_conf{ |
| | a_gamefont_conf font[10]; |
| | int num,cur; |
}gamefont_conf; | | }gamefont_conf; |
| | |
gamefont_conf font_conf[10]; | | gamefont_conf font_conf[MAX_FONTS]; |
int num_font_conf=0,cur_font_conf=-1; | | |
grs_font *game_font=NULL; | | char *gamefont_curfontname(int gf){ |
| | if (font_conf[gf].cur<0) |
void gamefont_unloadfont(void){ | | return Gamefont_filenames_l[gf]; |
if (game_font){ | | else |
if (cur_font_conf>=0){ | | return font_conf[gf].font[font_conf[gf].cur].f.name; |
if (!font_conf[cur_font_conf].builtin) | | } |
gr_close_font(game_font); | | |
} | | void gamefont_unloadfont(int gf){ |
game_font=NULL; | | if (Gamefonts[gf]){ |
} | | font_conf[gf].cur=-1; |
} | | gr_close_font(Gamefonts[gf]); |
void gamefont_loadfont(int fi){ | | Gamefonts[gf]=NULL; |
if (font_conf[fi].builtin){ | | } |
gamefont_unloadfont(); | | } |
game_font=font_conf[fi].f.ptr; | | void gamefont_loadfont(int gf,int fi){ |
}else{ | | if (cfexist(font_conf[gf].font[fi].f.name)){ |
if (cfexist(font_conf[fi].f.name)){ | | gamefont_unloadfont(gf); |
gamefont_unloadfont(); | | Gamefonts[gf]=gr_init_font(font_conf[gf].font[fi].f.name); |
game_font=gr_init_font(font_conf[fi].f.name); | | |
}else { | | }else { |
hud_message(MSGC_GAME_FEEDBACK,"Couldn't find font file %s!",font_conf[fi].f.name); | | hud_message(MSGC_GAME_FEEDBACK,"Couldn't find font file %s!",font_conf[gf].font[fi].f.name); |
if (game_font==NULL){ | | if (Gamefonts[gf]==NULL){ |
game_font=Gamefonts[GFONT_SMALL]; | | Gamefonts[gf]=gr_init_font(Gamefont_filenames_l[gf]); |
cur_font_conf=-1; | | font_conf[gf].cur=-1; |
} | | } |
return; | | return; |
} | | } |
} | | font_conf[gf].cur=fi; |
cur_font_conf=fi; | | |
} | | } |
void gamefont_choose_game_font(int scrx,int scry){ | | void gamefont_choose_game_font(int scrx,int scry){ |
int i,close=-1,m=-1; | | int gf,i,close=-1,m=-1; |
| | mprintf ((0,"gamefont_choose_game_font(%i,%i) %i\n",scrx,scry,Gamefont_installed)); |
if (!Gamefont_installed) return; | | if (!Gamefont_installed) return; |
| | |
for (i=0;i<num_font_conf;i++) | | for (gf=0;gf<MAX_FONTS;gf++){ |
if (scrx>=font_conf[i].x && close<font_conf[i].x){ | | for (i=0;i<font_conf[gf].num;i++) |
close=font_conf[i].x; | | if (scrx>=font_conf[gf].font[i].x && close<font_conf[gf].font[i].x){ |
| | close=font_conf[gf].font[i].x; |
m=i; | | m=i; |
} | | } |
if (m<0) | | if (m<0) |
Error("no gamefont found for %ix%i\n",scrx,scry); | | Error("no gamefont found for %ix%i\n",scrx,scry); |
| | |
gamefont_loadfont(m); | | gamefont_loadfont(gf,m); |
} | | } |
| | |
void addfontconf(int x,char * fn){ | | |
int i,b=0; | | |
grs_font *ptr=NULL; | | |
for (i=0; i<MAX_FONTS; i++ ) | | for (i=0; i<MAX_FONTS; i++ ) |
if (stricmp(fn,Gamefont_filenames[i])==0){ | | mprintf ((0,"font %i: %ix%i\n",i,Gamefonts[i]->ft_w,Gamefonts[i]->ft_h)); |
b=1; | | } |
ptr=Gamefonts[i]; | | |
} | | void addfontconf(int gf, int x,char * fn){ |
mprintf((0,"adding font %s at %i, %i: ",fn,x,b)); | | int i; |
for (i=0;i<num_font_conf;i++){ | | mprintf((0,"adding font %s at %i %i: ",fn,gf,x)); |
if (font_conf[i].x==x){ | | for (i=0;i<font_conf[gf].num;i++){ |
| | if (font_conf[gf].font[i].x==x){ |
mprintf((0,"replaced %i\n",i)); | | mprintf((0,"replaced %i\n",i)); |
if (i==cur_font_conf) | | if (i==font_conf[gf].cur) |
gamefont_unloadfont(); | | gamefont_unloadfont(gf); |
font_conf[i].builtin=b; | | strcpy(font_conf[gf].font[i].f.name,fn); |
if (b) | | if (i==font_conf[gf].cur) |
font_conf[i].f.ptr=ptr; | | gamefont_loadfont(gf,i); |
else | | |
strcpy(font_conf[i].f.name,fn); | | |
if (i==cur_font_conf) | | |
gamefont_loadfont(i); | | |
return; | | return; |
} | | } |
} | | } |
mprintf((0,"added %i\n",num_font_conf)); | | mprintf((0,"added %i\n",font_conf[gf].num)); |
font_conf[num_font_conf].x=x; | | font_conf[gf].font[font_conf[gf].num].x=x; |
font_conf[num_font_conf].builtin=b; | | strcpy(font_conf[gf].font[font_conf[gf].num].f.name,fn); |
if (b) | | font_conf[gf].num++; |
font_conf[num_font_conf].f.ptr=ptr; | | |
else | | |
strcpy(font_conf[num_font_conf].f.name,fn); | | |
num_font_conf++; | | |
} | | } |
| | |
void gamefont_init() | | void gamefont_init() |
| | |
if (Gamefont_installed) return; | | if (Gamefont_installed) return; |
Gamefont_installed = 1; | | Gamefont_installed = 1; |
| | |
for (i=0; i<MAX_FONTS; i++ ) | | for (i=0;i<MAX_FONTS;i++){ |
Gamefonts[i] = gr_init_font(Gamefont_filenames[i]); | | Gamefonts[i]=NULL; |
| | addfontconf(i,0,Gamefont_filenames_l[i]); |
| | addfontconf(i,640,Gamefont_filenames_h[i]); |
| | } |
| | |
addfontconf(0,"font3-1.fnt");//default font. | | // addfontconf(640,"pc6x8.fnt"); |
addfontconf(640,"pc6x8.fnt"); | | // addfontconf(1024,"pc8x16.fnt"); |
addfontconf(1024,"pc8x16.fnt"); | | |
if ((i=FindArg("-font320"))) | | if ((i=FindArg("-font320"))) |
addfontconf(320,Args[i+1]); | | addfontconf(4,320,Args[i+1]); |
if ((i=FindArg("-font640"))) | | if ((i=FindArg("-font640"))) |
addfontconf(640,Args[i+1]); | | addfontconf(4,640,Args[i+1]); |
if ((i=FindArg("-font800"))) | | if ((i=FindArg("-font800"))) |
addfontconf(800,Args[i+1]); | | addfontconf(4,800,Args[i+1]); |
if ((i=FindArg("-font1024"))) | | if ((i=FindArg("-font1024"))) |
addfontconf(1024,Args[i+1]); | | addfontconf(4,1024,Args[i+1]); |
gamefont_choose_game_font(320,200); | | |
| | |
for (i=0; i<MAX_FONTS; i++ ) | | gamefont_choose_game_font(grd_curscreen->sc_canvas.cv_bitmap.bm_w,grd_curscreen->sc_canvas.cv_bitmap.bm_h); |
printf ("font %i: %ix%i\n",i,Gamefonts[i]->ft_w,Gamefonts[i]->ft_h); | | |
| | |
atexit( gamefont_close ); | | atexit( gamefont_close ); |
} | | } |
| | |
Gamefont_installed = 0; | | Gamefont_installed = 0; |
| | |
for (i=0; i<MAX_FONTS; i++ ) { | | for (i=0; i<MAX_FONTS; i++ ) { |
gr_close_font( Gamefonts[i] ); | | gamefont_unloadfont(i); |
Gamefonts[i] = NULL; | | // gr_close_font( Gamefonts[i] ); |
| | // Gamefonts[i] = NULL; |
} | | } |
| | |
} | | } |