-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtext.cpp
More file actions
378 lines (309 loc) · 6.86 KB
/
Copy pathtext.cpp
File metadata and controls
378 lines (309 loc) · 6.86 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
// Text.cpp
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <ddraw.h>
#include "def.h"
#include "pixmap.h"
#include "text.h"
#include "texttables.h"
#pragma warning (disable: 4996)
/////////////////////////////////////////////////////////////////////////////
// Retourne l'offset pour un caract�re donn�.
int GetOffset(char c)
{
int i;
static unsigned char table_accents[15] =
{
0xFC, 0xE0, 0xE2, 0xE9, 0xE8, 0xEB, 0xEA, 0xEF,
0xEE, 0xF4, 0xF9, 0xFB, 0xE4, 0xF6, 0xE7
};
for ( i=0 ; i<15 ; i++ )
{
if ( (unsigned char)c == table_accents[i] )
{
return 15+i;
}
}
if ( c<0 || c>128 ) return 1; // carr�
return c;
}
// Retourne la longueur d'un caract�re.
int GetCharWidth(char c, int font)
{
static unsigned char table_width[128] =
{
9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,8,
9,9,8,8,8,8,5,5,8,8,8,9,8,8,10,10,
5,6,9,13,11,12,12,6,6,6,12,12,5,9,6,9,
8,8,9,9,8,9,8,8,9,9,6,6,8,9,10,11,
12,8,9,9,9,8,8,8,9,4,8,9,8,10,9,9,
8,9,8,9,10,8,9,11,9,8,10,7,10,7,13,13,
9,9,8,8,8,8,6,8,8,4,6,8,4,12,8,8,
8,8,7,6,7,8,8,10,8,8,7,6,6,6,10,0,
};
static unsigned char table_width_little[128] =
{
6,6,6,6,6,6,6,6,6,6,6,6,5,6,6,7,
6,6,6,6,6,6,3,3,6,6,6,6,6,6,5,5,
3,3,5,8,5,11,9,3,4,4,6,6,3,4,3,6,
5,5,5,5,5,5,5,5,5,5,3,3,7,6,7,6,
9,8,6,7,7,5,5,8,7,2,4,7,5,10,7,8,
6,8,7,6,6,6,8,12,7,6,6,3,5,3,6,8,
4,6,6,6,6,6,4,6,6,2,3,5,2,10,6,6,
6,6,3,5,3,6,6,8,6,6,5,4,6,4,7,0,
};
if ( font == FONTLITTLE )
{
return table_width_little[GetOffset(c)];
}
else
{
return table_width[GetOffset(c)]-1;
}
}
// Affiche un texte.
void DrawTextB(CPixmap *pPixmap, POINT pos, char *pText, int font)
{
int rank;
if ( font == FONTLITTLE )
{
while ( *pText != 0 )
{
rank = GetOffset(*pText);
pPixmap->DrawIcon(-1, CHLITTLE, rank, pos);
pos.x += GetCharWidth(*pText++, font);
}
}
else
{
while ( *pText != 0 )
{
rank = GetOffset(*pText);
rank += 128*font;
pPixmap->DrawIcon(-1, CHTEXT, rank, pos);
pos.x += GetCharWidth(*pText++, font);
}
}
}
void DrawTextLeft(CPixmap* pPixmap, POINT pos, char *text, int font)
{
DrawTextB(pPixmap, pos, text, font);
return;
}
//Implement later
void DrawChar(CPixmap* pPixmap, POINT* pos, char c, int font)
{
POINT pos1;
int width;
UINT index;
index = (UINT)(BYTE)c;
}
void DrawCharSingle(CPixmap pPixmap, POINT pos, char* pText, int font)
{
if (font == FONTLITTLE)
{
pPixmap.DrawIcon(-1, CHLITTLE, (int)pText, pos, 0, FALSE);
return;
}
pPixmap.DrawIcon(-1, CHTEXT, (int)(pText + font * 128), pos, 0, FALSE);
return;
}
// Affiche un texte pench�.
void DrawTextPente(CPixmap *pPixmap, POINT pos, char *pText,
int pente, int font)
{
int rank, lg, rel, start;
start = pos.y;
rel = 0;
while ( *pText != 0 )
{
rank = GetOffset(*pText);
rank += 128*font;
pPixmap->DrawIcon(-1, CHTEXT, rank, pos);
lg = GetCharWidth(*pText++, font);
rel += lg;
pos.x += lg;
pos.y = start + rel/pente;
}
}
// Affiche un pav� de texte.
// Une ligne vide est affich�e avec un demi interligne !
// Si part != -1, n'affiche que les lignes qui commencent
// par "n|", avec n=part.
void DrawTextRect(CPixmap *pPixmap, POINT pos, char *pText,
int pente, int font, int part)
{
char text[100];
char* pDest;
int itl;
if ( font == FONTLITTLE ) itl = DIMLITTLEY;
else itl = DIMTEXTY;
while ( *pText != 0 )
{
pDest = text;
while ( *pText != 0 && *pText != '\r' && *pText != '\n' )
{
*pDest++ = *pText++;
}
*pDest = 0;
if ( *pText == '\r' ) pText ++; // saute '\r'
if ( *pText == '\n' ) pText ++; // saute '\n'
pDest = text;
if ( text[0] != 0 && text[1] == '|' ) // commence par "n|" ?
{
if ( part != -1 && part != text[0]-'0' ) continue;
pDest += 2; // saute "n|"
}
else
{
if ( part != -1 ) continue;
}
if ( pente == 0 )
{
DrawTextB(pPixmap, pos, pDest, font);
}
else
{
DrawTextPente(pPixmap, pos, pDest, pente, font);
}
if ( pDest[0] == 0 ) // ligne vide ?
{
pos.y += itl/2; // descend de 1/2 ligne
}
else
{
pos.y += itl; // passe � la ligne suivante
}
}
}
// Affiche un texte centr� pouvant �ventuellement
// contenir plusieurs lignes s�par�es par des '\n'.
void DrawTextCenter(CPixmap *pPixmap, POINT pos, char *pText, int font)
{
char text[100];
char* pDest;
int itl;
POINT start;
if ( font == FONTLITTLE ) itl = DIMLITTLEY;
else itl = DIMTEXTY;
while ( *pText != 0 )
{
pDest = text;
while ( *pText != 0 && *pText != '\r' && *pText != '\n' )
{
*pDest++ = *pText++;
}
*pDest = 0;
if ( *pText == '\r' ) pText ++; // saute '\r'
if ( *pText == '\n' ) pText ++; // saute '\n'
pDest = text;
start.x = pos.x - GetTextWidth(pDest)/2;
start.y = pos.y;
DrawTextB(pPixmap, start, pDest, font);
if ( pDest[0] == 0 ) // ligne vide ?
{
pos.y += itl/2; // descend de 1/2 ligne
}
else
{
pos.y += itl; // passe � la ligne suivante
}
}
}
// Retourne la hauteur d'un texte.
int GetTextHeight(char *pText, int font, int part)
{
char text[100];
char* pDest;
int itl;
int h=0;
if ( font == FONTLITTLE ) itl = DIMLITTLEY;
else itl = DIMTEXTY;
while ( *pText != 0 )
{
pDest = text;
while ( *pText != 0 && *pText != '\r' && *pText != '\n' )
{
*pDest++ = *pText++;
}
*pDest = 0;
if ( *pText == '\r' ) pText ++; // saute '\r'
if ( *pText == '\n' ) pText ++; // saute '\n'
pDest = text;
if ( text[0] != 0 && text[1] == '|' ) // commence par "n|" ?
{
if ( part != -1 && part != text[0]-'0' ) continue;
pDest += 2; // saute "n|"
}
else
{
if ( part != -1 ) continue;
}
if ( pDest[0] == 0 ) // ligne vide ?
{
h += itl/2; // descend de 1/2 ligne
}
else
{
h += itl; // passe � la ligne suivante
}
}
return h;
}
// Retourne la longueur d'un texte.
int GetTextWidth(char *pText, int font)
{
int width = 0;
while ( *pText != 0 )
{
width += GetCharWidth(*pText++, font);
}
return width;
}
// Retourne la longueur d'un grand chiffre.
void GetBignumInfo(int num, int &start, int &lg)
{
static int table[11] =
{
0,53,87,133,164,217,253,297,340,382,426
};
start = table[num];
lg = table[num+1]-table[num];
}
// Affiche un grand nombre.
void DrawBignum(CPixmap *pPixmap, POINT pos, int num)
{
char string[10];
int i = 0;
int start, lg;
RECT rect;
sprintf(string, "%d", num);
rect.top = 0;
rect.bottom = 52;
while ( string[i] != 0 )
{
GetBignumInfo(string[i]-'0', start, lg);
rect.left = start;
rect.right = start+lg;
pPixmap->DrawPart(-1, CHBIGNUM, pos, rect);
pos.x += lg+4;
i ++;
}
}
// Retourne la longueur d'un grand nombre.
int GetBignumWidth(int num)
{
char string[10];
int i = 0;
int start, lg;
int width = -4;
sprintf(string, "%d", num);
while ( string[i] != 0 )
{
GetBignumInfo(string[i]-'0', start, lg);
width += lg+4;
i ++;
}
return width;
}