]> 4ch.mooo.com Git - 16.git/blob - 16/v2/source/ENGINE/FONT.C
wwww
[16.git] / 16 / v2 / source / ENGINE / FONT.C
1 /*\r
2 Copyright (C) 1998 BJ Eirich (aka vecna)\r
3 This program is free software; you can redistribute it and/or\r
4 modify it under the terms of the GNU General Public License\r
5 as published by the Free Software Foundation; either version 2\r
6 of the License, or (at your option) any later version.\r
7 This program is distributed in the hope that it will be useful,\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
10 See the GNU General Public Lic\r
11 See the GNU General Public License for more details.\r
12 You should have received a copy of the GNU General Public License\r
13 along with this program; if not, write to the Free Software\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
15 */\r
16 \r
17 #define FONT_H\r
18 #include "verge.h"\r
19 \r
20 // ================================= Data ====================================\r
21 \r
22 struct fontstruct\r
23 {\r
24   byte width, height;                  // Font character dimensions\r
25   byte *data;                          // Font bitmap data\r
26 };\r
27 \r
28 struct fontstruct font[10];            // Font stuff;\r
29 int numfonts=0;                        // number of loaded fonts.\r
30 int curx, cury;                        // x/y font location\r
31 char tc=0;                             // text color\r
32 \r
33 // ================================= Code ====================================\r
34 \r
35 int LoadFont(char *fname)\r
36 { VFILE *f=0;\r
37   struct fontstruct *cfont=0;\r
38   int z=0;\r
39 \r
40   if (!(f=vopen(fname)))\r
41      err("Could not open font %s. \n",fname);\r
42 \r
43   // alias current font struct\r
44   cfont=font+numfonts;\r
45 \r
46   if (vgetc(f) != 1)\r
47     err("Font file incorrect version number. \n");\r
48 \r
49   // font dims\r
50   cfont->width=vgetw(f);\r
51   cfont->height=vgetw(f);\r
52 \r
53   // get num of sub-set; calc total bytes as well\r
54   z=vgetw(f) * 96 * cfont->width*cfont->height;\r
55 \r
56   // nab room for font and read it in\r
57   cfont->data=(byte *)valloc(z, "LoadFont:cfont->data", OID_IMAGE);\r
58   vread(cfont->data, z, f);\r
59 \r
60   vclose(f);\r
61 \r
62   return numfonts++;\r
63 }\r
64 \r
65 void TextColor(int c)\r
66 {\r
67   tc=c;\r
68 }\r
69 \r
70 void GotoXY(int x, int y)\r
71 {\r
72   curx=x;\r
73   cury=y;\r
74 }\r
75 \r
76 static void pchar(int fnt, int x, int y, unsigned char c)\r
77 {\r
78   int w;\r
79   if (c>31 && c<127)\r
80   {\r
81     w=font[fnt].width,h=font[fnt].height;\r
82     TCopySpriteClip(x,y, w,h, font[fnt].data+((c-32)*w*h)+((tc&3)*96*w*h));\r
83   }\r
84 }\r
85 \r
86 void printstring(int fnt, char *str)\r
87 {\r
88   if (fnt<0 || fnt >= numfonts)\r
89     return;\r
90   for (; *str; str++)\r
91   {\r
92     unsigned char c=*str;\r
93     switch (c)\r
94     {\r
95       case 126: tc=0; str++; continue;\r
96       case 128: tc=1; str++; continue;\r
97       case 129: tc=2; str++; continue;\r
98       case 130: tc=3; str++; continue;\r
99     }\r
100     pchar(fnt,curx,cury,c);\r
101     curx+=font[fnt].width;\r
102   }\r
103 }