-
Notifications
You must be signed in to change notification settings - Fork 0
/
charDrawer.cpp
189 lines (180 loc) · 3.95 KB
/
charDrawer.cpp
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
//
// charDrawer.cpp
// mySketch
//
// Created by Juhani Halkomäki on 05/03/2018.
//
#include "charDrawer.h"
void drawChar(char chr, int x, int y, VideoBuffer *vb){
int *bits = get_bits(getChar(chr), 15);
for(int dx=0; dx<LETTER_WIDTH; dx++){
for(int dy=0; dy<LETTER_HEIGHT; dy++){
if(bits[dx+dy*LETTER_WIDTH] == 1)
vb->setPixel((x+dx),(y+dy), true);
}
}
free(bits);
}
void drawString(const char *str, int x, int y, VideoBuffer *vb){
for(int i=0; i<strlen(str); i++){
drawChar(str[i], x+i*(LETTER_WIDTH+1), y, vb);
}
}
unsigned int stringLengthInPixels(const char *str){
return strlen(str) * (LETTER_WIDTH+1);
}
unsigned int getChar(char chr){
switch(chr) {
case '0':
return LETTER_0;
break;
case '1':
return LETTER_1;
break;
case '2':
return LETTER_2;
break;
case '3':
return LETTER_3;
break;
case '4':
return LETTER_4;
break;
case '5':
return LETTER_5;
break;
case '6':
return LETTER_6;
break;
case '7':
return LETTER_7;
break;
case '8':
return LETTER_8;
break;
case '9':
return LETTER_9;
break;
default:
return LETTER_0;
break;
case 'a':
case 'A':
return LETTER_A;
break;
case 'b':
case 'B':
return LETTER_B;
break;
case 'c':
case 'C':
return LETTER_C;
break;
case 'd':
case 'D':
return LETTER_D;
break;
case 'e':
case 'E':
return LETTER_E;
break;
case 'f':
case 'F':
return LETTER_F;
break;
case 'g':
case 'G':
return LETTER_G;
break;
case 'h':
case 'H':
return LETTER_H;
break;
case 'i':
case 'I':
return LETTER_I;
break;
case 'j':
case 'J':
return LETTER_J;
break;
case 'k':
case 'K':
return LETTER_K;
break;
case 'l':
case 'L':
return LETTER_L;
break;
case 'm':
case 'M':
return LETTER_M;
break;
case 'n':
case 'N':
return LETTER_N;
break;
case 'o':
case 'O':
return LETTER_O;
break;
case 'p':
case 'P':
return LETTER_P;
break;
case 'q':
case 'Q':
return LETTER_Q;
break;
case 'r':
case 'R':
return LETTER_R;
break;
case 's':
case 'S':
return LETTER_S;
break;
case 't':
case 'T':
return LETTER_T;
break;
case 'u':
case 'U':
return LETTER_U;
break;
case 'v':
case 'V':
return LETTER_V;
break;
case 'w':
case 'W':
return LETTER_W;
break;
case 'x':
case 'X':
return LETTER_X;
break;
case 'y':
case 'Y':
return LETTER_Y;
break;
case 'z':
case 'Z':
return LETTER_Z;
break;
case ' ':
return LETTER_SPACE;
break;
}
}
int *get_bits(int n, int bitswanted){
int *bits = (int *)malloc(sizeof(int) * bitswanted);
int k;
for(k=0; k<bitswanted; k++){
int mask = 1 << k;
int masked_n = n & mask;
int thebit = masked_n >> k;
bits[k] = thebit;
}
return bits;
}