-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathletterrender.c
187 lines (180 loc) · 4.91 KB
/
letterrender.c
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
/*
* $Id: letterrender.c,v 1.1.1.1 2003/03/16 07:03:49 kenta Exp $
*
* Copyright 2002 Kenta Cho. All rights reserved.
*/
/**
* Letter render.
*
* @version $Revision: 1.1.1.1 $
*/
//senquack - for fixed point stuff
#include "degutil.h"
#include "screen.h"
#include "letterrender.h"
#include "letterdata.h"
//senquack TODO: optimizing all of these by passing all parameters as fixed or float, not int:
//senquack - converted to fixed/float point
//void drawLetter(int idx, int lx, int ly, int ltSize, int d,
// int r, int g, int b) {
// int i;
// float x, y, length, size, t;
// int deg;
// for ( i=0 ; ; i++ ) {
// deg = (int)spData[idx][i][4];
// if ( deg > 99990 ) break;
// x = -spData[idx][i][0]; y = -spData[idx][i][1];
// size = spData[idx][i][2]; length = spData[idx][i][3];
// size *= 0.66f; length *= 0.6f;
// switch ( d ) {
// case 0:
// x = -x; y = y;
// break;
// case 1:
// t = x; x = -y; y = -t;
// deg += 90;
// break;
// case 2:
// x = x; y = -y;
// deg += 180;
// break;
// case 3:
// t = x; x = y; y = t;
// deg += 270;
// break;
// }
// deg %= 180;
// if ( deg <= 45 || deg > 135 ) {
// drawBox((int)(x*ltSize)+lx, (int)(y*ltSize)+ly,
// (int)(size*ltSize), (int)(length*ltSize), r, g, b);
// } else {
// drawBox((int)(x*ltSize)+lx, (int)(y*ltSize)+ly,
// (int)(length*ltSize), (int)(size*ltSize), r, g, b);
// }
// }
//}
void drawLetter (int idx, int lx, int ly, int ltSize, int d, int r, int g, int b)
{
#ifdef FIXEDMATH
printf ("Call to fixed-point stub for Draw letter\n");
#else
int i;
float x, y, length, size, t;
int deg;
for ( i=0 ; ; i++ ) {
deg = (int)spData[idx][i][4];
if ( deg > 99990 ) break;
x = -spData[idx][i][0]; y = -spData[idx][i][1];
size = spData[idx][i][2]; length = spData[idx][i][3];
size *= 0.66f; length *= 0.6f;
switch ( d ) {
case 0:
x = -x; y = y;
break;
case 1:
t = x; x = -y; y = -t;
deg += 90;
break;
case 2:
x = x; y = -y;
deg += 180;
break;
case 3:
t = x; x = y; y = t;
deg += 270;
break;
}
deg %= 180;
if ( deg <= 45 || deg > 135 ) {
//senquack - on smaller dimensioned screens, don't draw outlines on very small text
#if SCREEN_WIDTH < 640
if (ltSize > 6) {
drawBox((x*ltSize)+lx, (y*ltSize)+ly,
(size*ltSize), (length*ltSize), r, g, b);
} else {
drawBoxNoOutline((x*ltSize)+lx, (y*ltSize)+ly,
(size*ltSize), (length*ltSize), r, g, b);
}
#else
drawBox((x*ltSize)+lx, (y*ltSize)+ly,
(size*ltSize), (length*ltSize), r, g, b);
#endif
} else {
#if SCREEN_WIDTH < 640
if (ltSize > 6) {
drawBox((x*ltSize)+lx, (y*ltSize)+ly,
(length*ltSize), (size*ltSize), r, g, b);
} else {
drawBoxNoOutline((x*ltSize)+lx, (y*ltSize)+ly,
(length*ltSize), (size*ltSize), r, g, b);
}
#else
drawBox((x*ltSize)+lx, (y*ltSize)+ly,
(length*ltSize), (size*ltSize), r, g, b);
#endif
}
}
#endif //FIXEDMATH
}
//senquack - converted to fixed/float point:
void drawString (char *str, int lx, int ly, int ltSize, int d, int r, int g, int b)
{
int x = lx, y = ly;
int i, c, idx;
for (i = 0;; i++) {
if (str[i] == '\0')
break;
c = str[i];
if (c != ' ') {
if (c >= '0' && c <= '9') {
idx = c - '0';
} else if (c >= 'A' && c <= 'Z') {
idx = c - 'A' + 10;
} else if (c >= 'a' && c <= 'z') {
idx = c - 'a' + 10;
} else if (c == '.') {
idx = 36;
} else if (c == '-') {
idx = 38;
} else if (c == '+') {
idx = 39;
} else {
idx = 37;
}
drawLetter (idx, x, y, ltSize, d, r, g, b);
}
switch (d) {
#ifdef FIXEDMATH
case 0:
// x += ltSize*1.7f;
x += FNUM2INT (FMUL (INT2FNUM (ltSize), 111411));
break;
case 1:
// y += ltSize*1.7f;
y += FNUM2INT (FMUL (INT2FNUM (ltSize), 111411));
break;
case 2:
// x -= ltSize*1.7f;
x -= FNUM2INT (FMUL (INT2FNUM (ltSize), 111411));
break;
case 3:
// y -= ltSize*1.7f;
y -= FNUM2INT (FMUL (INT2FNUM (ltSize), 111411));
break;
#else
case 0:
x += ltSize*1.7f;
break;
case 1:
y += ltSize*1.7f;
break;
case 2:
x -= ltSize*1.7f;
break;
case 3:
y -= ltSize*1.7f;
break;
#endif //FIXEDMATH
}
}
}