font.c
4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
Example of FONTS
*/
#include <PR/mbi.h>
#include <PR/sp.h>
#include "font.h"
#include "font_ext.h"
#include "letters.h" /* sct 11/20/95 */
#include "pinfont.h" /* sct 11/20/95 */
#include "digit6font.h" /* sct 11/27/95 */
static Font * font_font = &pinfont_font;
static unsigned char font_red = 255;
static unsigned char font_grn = 255;
static unsigned char font_blu = 255;
static unsigned char font_alf = 255;
static int font_xpos = 0;
static int font_ypos = 0;
static int font_win_width = 40;
static int font_win_height = 1;
static double font_xscale = 1.0;
static double font_yscale = 1.0;
static void text_sprite( Sprite *, char *, Font *, int , int );
char *my_strchr( char *, char );
static void
text_sprite( Sprite *txt, char *str, Font *fnt, int xlen, int ylen )
{
int i, ci;
int x;
int y;
char *indx;
Bitmap *bm;
/* sct 11/27/95 - These seem like they are font dependent! Watch out! */
txt->width = xlen * 8;
txt->height = ylen * 16;
bm = txt->bitmap;
i = 0;
ci = 0;
for(y=0; y<ylen; y++)
{
for(x=0; x<xlen; x++, i++, ci++)
{
if( str[ci] == '\0' )
{
bm[i] = fnt->bitmaps[0];
bm[i].width = -1;
txt->nbitmaps = i;
return;
}
if( str[ci] == '\n' ) /* fill remainder of line with spaces */
{
bm[i] = fnt->bitmaps[0];
bm[i].buf = NULL; /* insert a space */
ci--;
continue;
}
if( (indx = my_strchr(fnt->index_string, str[ci])) != NULL )
bm[i] = fnt->bitmaps[indx-fnt->index_string];
else
{
bm[i] = fnt->bitmaps[0];
bm[i].buf = NULL; /* insert a space */
}
}
if( str[ci] == '\n' )
ci++;
}
txt->nbitmaps = i;
return;
}
char *
my_strchr( char *str, char target )
{
while( *str && (*str != target) )
str++;
if( *str )
return( str );
return( NULL );
}
/* Initialize Font local variables and prepare for drawing sprites */
void
font_init( Gfx **glistp )
{
Gfx *gl;
gl = *glistp;
spInit( &gl );
*glistp = gl;
/* template_sprite.rsp_dl_next = template_sprite.rsp_dl; */
font_red = 255;
font_grn = 255;
font_blu = 255;
font_alf = 255;
font_xpos = 0;
font_ypos = 0;
font_win_width = 40;
font_win_height = 1;
font_xscale = 1.0;
font_yscale = 1.0;
}
/* Call spFinish() to clean up when done using Sprites */
void
font_finish( Gfx **glistp )
{
Gfx *gxp;
gxp = *glistp;
spFinish( &gxp );
*glistp = (gxp-1); /* Don't use final EndDisplayList() */
}
/*
Allows the user to specify which font to use.
sct 11/27/95 - created.
*/
void
font_set_font( int fontType )
{
switch (fontType)
{
case kLettersFont:
font_font = &letters_font;
break;
case kPinFont:
font_font = &pinfont_font;
break;
case kDigit6Font:
font_font = &digit6_font;
break;
}
}
/* Set text window area (units are characters) */
void
font_set_win( int width, int height )
{
font_win_width = width;
font_win_height = height;
}
/* Set text window position (upper left corner) */
void
font_set_pos( int xpos, int ypos )
{
font_xpos = xpos;
font_ypos = ypos;
}
/* Set text size */
void
font_set_scale( double xscale, double yscale )
{
font_xscale = xscale;
font_yscale = yscale;
}
/* Set text color */
void
font_set_color( unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha )
{
font_red = red;
font_grn = green;
font_blu = blue;
font_alf = alpha;
}
void
font_set_transparent( int flag, Sprite *sp )
{
if( flag )
spSetAttribute( sp, SP_TRANSPARENT | SP_CUTOUT );
else
spClearAttribute( sp, SP_TRANSPARENT | SP_CUTOUT );
}
/* Convert the string to a sprite with the propler bitmaps
assembled from the basic font texture. */
void
font_show_string( Gfx **glistp, char *val_str, Sprite *sp )
{
Gfx *gxp, *dl;
gxp = *glistp;
sp->width = font_win_width*8 + 8;
sp->height = font_win_height*16 + 8;
/* sct 11/27/95 - Made font user settable. */
text_sprite( sp, val_str, font_font, font_win_width, font_win_height );
spMove( sp, font_xpos, font_ypos );
spColor( sp, font_red, font_grn, font_blu, font_alf );
spScale( sp, font_xscale, font_yscale );
dl = spDraw( sp );
gSPDisplayList( gxp++, dl );
*glistp = gxp;
}