version 1.1 | | version 1.2 |
---|
| | |
* Fonts for the game. | | * Fonts for the game. |
* | | * |
* $Log$ | | * $Log$ |
* Revision 1.1 1999/06/14 22:06:59 donut | | * Revision 1.2 1999/10/08 00:57:03 donut |
* Initial revision | | * variable GAME_FONT |
| | * |
| | * Revision 1.1.1.1 1999/06/14 22:06:59 donut |
| | * Import of d1x 1.37 source. |
* | | * |
* Revision 2.0 1995/02/27 11:30:14 john | | * Revision 2.0 1995/02/27 11:30:14 john |
* New version 2.0, which has no anonymous unions, builds with | | * New version 2.0, which has no anonymous unions, builds with |
| | |
#endif | | #endif |
| | |
#include <stdlib.h> | | #include <stdlib.h> |
| | #include <stdio.h> |
| | |
#include "gr.h" | | #include "gr.h" |
| | #include "error.h" |
| | #include "strutil.h" |
| | #include "mono.h" |
| | #include "args.h" |
#include "gamefont.h" | | #include "gamefont.h" |
| | |
char * Gamefont_filenames[] = { "font1-1.fnt", // Font 0 | | char * Gamefont_filenames[] = { "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 |
}; | | }; |
| | |
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 |
| | // take scry into account? how/when? |
| | typedef struct _gamefont_conf{ |
| | int x; |
| | int builtin; |
| | union{ |
| | char name[64];//hrm. |
| | grs_font *ptr; |
| | } f; |
| | }gamefont_conf; |
| | |
| | gamefont_conf font_conf[10]; |
| | int num_font_conf=0,cur_font_conf=-1; |
| | grs_font *game_font=NULL; |
| | |
| | void gamefont_unloadfont(void){ |
| | if (game_font){ |
| | if (!font_conf[cur_font_conf].builtin) |
| | gr_close_font(game_font); |
| | game_font=NULL; |
| | } |
| | } |
| | void gamefont_loadfont(int fi){ |
| | gamefont_unloadfont(); |
| | if (font_conf[fi].builtin) |
| | game_font=font_conf[fi].f.ptr; |
| | else |
| | game_font=gr_init_font(font_conf[fi].f.name); |
| | cur_font_conf=fi; |
| | } |
| | void gamefont_choose_game_font(int scrx,int scry){ |
| | int i,close=-1,m=-1; |
| | if (!Gamefont_installed) return; |
| | |
| | for (i=0;i<num_font_conf;i++) |
| | if (scrx>=font_conf[i].x && close<font_conf[i].x){ |
| | close=font_conf[i].x; |
| | m=i; |
| | } |
| | if (m<0) |
| | Error("no gamefont found for %ix%i\n",scrx,scry); |
| | |
| | gamefont_loadfont(m); |
| | } |
| | |
| | void addfontconf(int x,char * fn){ |
| | int i,b=0; |
| | grs_font *ptr=NULL; |
| | for (i=0; i<MAX_FONTS; i++ ) |
| | if (stricmp(fn,Gamefont_filenames[i])==0){ |
| | b=1; |
| | ptr=Gamefonts[i]; |
| | } |
| | mprintf((0,"adding font %s at %i, %i: ",fn,x,b)); |
| | for (i=0;i<num_font_conf;i++){ |
| | if (font_conf[i].x==x){ |
| | mprintf((0,"replaced %i\n",i)); |
| | if (i==cur_font_conf) |
| | gamefont_unloadfont(); |
| | font_conf[i].builtin=b; |
| | if (b) |
| | font_conf[i].f.ptr=ptr; |
| | else |
| | strcpy(font_conf[i].f.name,fn); |
| | if (i==cur_font_conf) |
| | gamefont_loadfont(i); |
| | return; |
| | } |
| | } |
| | mprintf((0,"added %i\n",num_font_conf)); |
| | font_conf[num_font_conf].x=x; |
| | font_conf[num_font_conf].builtin=b; |
| | if (b) |
| | 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() |
{ | | { |
int i; | | int i; |
| | |
| | |
for (i=0; i<MAX_FONTS; i++ ) | | for (i=0; i<MAX_FONTS; i++ ) |
Gamefonts[i] = gr_init_font(Gamefont_filenames[i]); | | Gamefonts[i] = gr_init_font(Gamefont_filenames[i]); |
| | |
| | addfontconf(0,"font3-1.fnt");//default font. |
| | // addfontconf(800,"pc6x8.fnt"); |
| | // addfontconf(1024,"pc8x16.fnt"); |
| | if ((i=FindArg("-font320"))) |
| | addfontconf(320,Args[i+1]); |
| | if ((i=FindArg("-font640"))) |
| | addfontconf(640,Args[i+1]); |
| | if ((i=FindArg("-font800"))) |
| | addfontconf(800,Args[i+1]); |
| | if ((i=FindArg("-font1024"))) |
| | addfontconf(1024,Args[i+1]); |
| | gamefont_choose_game_font(320,200); |
| | |
| | for (i=0; i<MAX_FONTS; i++ ) |
| | printf ("font %i: %ix%i\n",i,Gamefonts[i]->ft_w,Gamefonts[i]->ft_h); |
| | |
atexit( gamefont_close ); | | atexit( gamefont_close ); |
} | | } |