Mercurial > mm7
annotate GUIFont.cpp @ 1165:29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
removed double LOBYTE, LOWORD etd macro definitions
swprintf called with string size parameter
ErrD3D with too many params fix
1 or 2 other minor fixes
author | Grumpy7 |
---|---|
date | Tue, 04 Jun 2013 03:21:21 +0200 |
parents | 502b8b2e36b4 |
children | 11cda4934da3 |
rev | line source |
---|---|
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1160
diff
changeset
|
1 #ifdef _MSC_VER |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1160
diff
changeset
|
2 #define _CRT_SECURE_NO_WARNINGS |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1160
diff
changeset
|
3 #endif |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1160
diff
changeset
|
4 |
0 | 5 #include <string> |
200 | 6 #include <assert.h> |
7 | |
180 | 8 #include "LOD.h" |
0 | 9 #include "GUIFont.h" |
10 #include "GUIWindow.h" | |
11 #include "Render.h" | |
12 | |
13 #include "mm7_data.h" | |
14 | |
15 | |
180 | 16 extern LODFile_IconsBitmaps *pIcons_LOD; |
0 | 17 |
18 | |
19 struct GUIFont *pAutonoteFont; | |
20 struct GUIFont *pSpellFont; | |
21 struct GUIFont *pFontArrus; | |
22 struct GUIFont *pFontLucida; | |
23 struct GUIFont *pBook2Font; | |
24 struct GUIFont *pBookFont; | |
25 struct GUIFont *pFontCreate; | |
26 struct GUIFont *pFontCChar; | |
27 struct GUIFont *pFontComic; | |
28 struct GUIFont *pFontSmallnum; | |
29 | |
189 | 30 char temp_string[2048]; |
31 | |
200 | 32 char pTmpBuf3[10000]; |
189 | 33 |
1160 | 34 void DrawCharToBuff(unsigned short* uXpos,unsigned char* pCharPixels, int uCharWidth, int uCharHeight, unsigned __int16* pFontPalette, __int16 draw_color, int line_width); |
35 | |
36 | |
180 | 37 //----- (0044C448) -------------------------------------------------------- |
38 GUIFont *LoadFont(const char *pFontFile, const char *pFontPalette, ...) | |
1160 | 39 { |
40 int pallete_index; // eax@3 | |
41 GUIFont *pFont; | |
42 unsigned int palletes_count =0; | |
43 va_list palettes_ptr; | |
180 | 44 |
1160 | 45 pFont = (GUIFont *)pIcons_LOD->LoadRaw(pFontFile, 0); |
46 va_start(palettes_ptr, pFontFile); | |
180 | 47 |
1160 | 48 while (NULL!=(pFontPalette=va_arg(palettes_ptr, const char *))) |
49 { | |
50 pallete_index =pIcons_LOD->LoadTexture(pFontPalette, TEXTURE_16BIT_PALETTE); | |
51 if (pallete_index == -1) | |
52 { | |
53 wsprintfA(pTmpBuf, "Unable to open %s", pFontPalette); | |
54 Abortf(pTmpBuf); | |
55 } | |
56 pFont->pFontPalettes[palletes_count] = pIcons_LOD->pTextures[pallete_index].pPalette16; | |
57 ++palletes_count; | |
58 } | |
59 va_end(palettes_ptr); | |
60 pFont->palletes_count = palletes_count; | |
61 return pFont; | |
62 } | |
0 | 63 |
64 | |
65 | |
66 //----- (0044D2FD) -------------------------------------------------------- | |
1160 | 67 void GUIFont::_44D2FD_prolly_draw_credits_entry(GUIFont *pFont, int Str, int a4, unsigned int w, unsigned int h, |
68 unsigned __int16 a7, unsigned __int16 a8, const char *pString, | |
69 unsigned __int16 *pPixels, unsigned int uPixelsWidth) | |
0 | 70 { |
71 int v11; // ebx@1 | |
72 int v12; // edi@1 | |
73 char *v13; // eax@1 | |
74 char *v14; // eax@1 | |
75 unsigned __int16 *v15; // esi@1 | |
76 GUIFont *v16; // edi@4 | |
77 signed int v17; // ecx@4 | |
78 signed int v18; // eax@6 | |
79 int v19; // [sp+Ch] [bp-5Ch]@1 | |
80 int v20; // [sp+10h] [bp-58h]@1 | |
81 unsigned int v21; // [sp+14h] [bp-54h]@1 | |
82 unsigned int v22; // [sp+18h] [bp-50h]@1 | |
83 unsigned int v23; // [sp+1Ch] [bp-4Ch]@1 | |
84 unsigned int v24; // [sp+20h] [bp-48h]@1 | |
85 GUIFont *v25; // [sp+60h] [bp-8h]@1 | |
86 GUIFont *v26; // [sp+64h] [bp-4h]@1 | |
87 char *Stra; // [sp+70h] [bp+8h]@1 | |
88 int a4a; // [sp+74h] [bp+Ch]@4 | |
89 int a7a; // [sp+80h] [bp+18h]@2 | |
90 | |
91 v11 = a7; | |
92 v22 = h; | |
93 v12 = Str; | |
94 v26 = this; | |
95 v24 = a4 + h - 1; | |
96 v21 = w; | |
97 v25 = pFont; | |
98 v23 = Str + w - 1; | |
99 ui_current_text_color = a7; | |
100 v19 = Str; | |
101 v20 = a4; | |
102 v13 = GUIFont::_44C933(pString, this, pFont, (int)&v19, 0, 1); | |
103 v14 = strtok(v13, "\n"); | |
104 Stra = v14; | |
105 v15 = &pPixels[uPixelsWidth * a4]; | |
106 if ( v14 ) | |
107 { | |
108 a7a = v12 >> 1; | |
109 while ( 1 ) | |
110 { | |
111 v16 = v26; | |
112 ui_current_text_color = v11; | |
113 v17 = 0; | |
114 a4a = v11; | |
115 if ( *v14 == '_' ) | |
116 { | |
117 v16 = v25; | |
118 a4a = a8; | |
119 ui_current_text_color = a8; | |
120 v17 = 1; | |
121 } | |
122 v18 = (signed int)(w - v16->GetLineWidth(&v14[v17])) >> 1; | |
123 if ( v18 < 0 ) | |
124 v18 = 0; | |
1160 | 125 v16->DrawTextLineToBuff(a4a, a8, &v15[v18 + a7a], Stra, uPixelsWidth); |
0 | 126 v15 += uPixelsWidth * (LOBYTE(v16->uFontHeight) - 3); |
127 Stra = strtok(0, "\n"); | |
128 if ( !Stra ) | |
129 break; | |
130 v14 = Stra; | |
131 } | |
132 } | |
133 } | |
134 // 5C6DB4: using guessed type int ui_current_text_color; | |
135 | |
136 | |
137 //----- (0044D1E7) -------------------------------------------------------- | |
1160 | 138 void GUIFont::DrawTextLine( unsigned int uDefaultColor, signed int uX, signed int uY, |
139 const char *text, int max_len_pix ) | |
0 | 140 { |
1160 | 141 signed int uX_pos; // edi@3 |
142 unsigned char c; // cl@4 | |
143 unsigned __int16 draw_color; // cx@12 | |
144 unsigned __int8 *pCharPixels; // eax@12 | |
145 char color_code[20]; // [sp+Ch] [bp-1Ch]@16 | |
146 int text_length; // [sp+20h] [bp-8h]@2 | |
147 int text_color; // [sp+24h] [bp-4h]@1 | |
148 int uCharWidth; // [sp+30h] [bp+8h]@9 | |
0 | 149 |
1160 | 150 if ( !text ) |
151 return; | |
152 text_color = ui_current_text_color; | |
153 text_length = strlen(text); | |
154 uX_pos=uX; | |
155 for (int i=0; i<text_length; ++i ) | |
0 | 156 { |
1160 | 157 c = text[i]; |
158 if ( IsCharValid(c) ) | |
0 | 159 { |
1160 | 160 switch (c) |
0 | 161 { |
1160 | 162 case '\n': //Line Feed 0A 10: |
163 return; | |
164 break; | |
165 case '\f': //Form Feed, page eject 0C 12 | |
166 strncpy(color_code, &text[i + 1], 5); | |
167 color_code[5] = 0; | |
168 text_color = atoi(color_code); | |
169 ui_current_text_color = text_color; | |
170 i += 5; | |
171 break; | |
172 case '\t': // Horizontal tab 09 | |
173 case '\r': //Carriage Return 0D 13 | |
174 break; | |
175 default: | |
176 uCharWidth = pMetrics[c].uWidth; | |
177 if ( uCharWidth ) | |
178 { | |
179 if ( i > 0 ) | |
180 uX_pos += pMetrics[c].uLeftSpacing; | |
181 draw_color = text_color; | |
182 pCharPixels = &pFontData[font_pixels_offset[c]]; | |
183 if ( !text_color ) | |
184 draw_color = -1; | |
185 pRenderer->DrawText(uX_pos, uY, pCharPixels, uCharWidth, uFontHeight, pFontPalettes[0], draw_color, 0); | |
186 uX_pos += uCharWidth; | |
187 if ( i < text_length ) | |
188 uX_pos += pMetrics[c].uRightSpacing; | |
189 } | |
0 | 190 } |
191 } | |
1160 | 192 } |
193 | |
194 } | |
195 | |
196 //----- (0040F845) -------------------------------------------------------- | |
197 void DrawCharToBuff( unsigned short* uXpos,unsigned char* pCharPixels, int uCharWidth, int uCharHeight, | |
198 unsigned __int16* pFontPalette, __int16 draw_color, int line_width ) | |
199 { | |
200 unsigned __int16* draw_buff; // edi@1 | |
201 unsigned char* pPixels; // esi@1 | |
202 unsigned char char_pxl; // eax@3 | |
203 | |
204 draw_buff = uXpos; | |
205 pPixels = pCharPixels; | |
206 for(int i=0; i<uCharHeight; ++i) | |
207 { | |
208 for(int j=0; j<uCharWidth; ++j) | |
0 | 209 { |
1160 | 210 char_pxl = *pPixels++; |
211 if ( char_pxl ) | |
212 { | |
213 if ( char_pxl == 1 ) | |
214 *draw_buff = pFontPalette[1]; | |
215 else | |
216 *draw_buff = draw_color; | |
217 } | |
218 ++draw_buff; | |
0 | 219 } |
1160 | 220 draw_buff+=line_width-uCharWidth; |
0 | 221 } |
1160 | 222 |
0 | 223 } |
224 | |
225 //----- (0044D0B5) -------------------------------------------------------- | |
1160 | 226 void GUIFont::DrawTextLineToBuff( int uColor, int a3, unsigned short* uX_buff_pos, const char *text, int line_width ) |
227 { | |
228 | |
229 unsigned short* uX_pos; // edi@3 | |
230 unsigned char c; // cl@4 | |
231 unsigned __int16 draw_color; // cx@12 | |
232 unsigned __int8 *pCharPixels; // eax@12 | |
233 char color_code[20]; // [sp+Ch] [bp-1Ch]@16 | |
234 int text_length; // [sp+20h] [bp-8h]@2 | |
235 int text_color; // [sp+24h] [bp-4h]@1 | |
236 int uCharWidth; // [sp+30h] [bp+8h]@9 | |
0 | 237 |
1160 | 238 if ( !text ) |
239 return; | |
240 text_color = ui_current_text_color; | |
241 text_length = strlen(text); | |
242 uX_pos=uX_buff_pos; | |
243 for (int i=0; i<text_length; ++i ) | |
0 | 244 { |
1160 | 245 c = text[i]; |
246 if ( IsCharValid(c) ) | |
0 | 247 { |
1160 | 248 switch (c) |
249 { | |
250 case '\n': //Line Feed 0A 10: | |
0 | 251 return; |
1160 | 252 break; |
253 case '\f': //Form Feed, page eject 0C 12 | |
254 strncpy(color_code, &text[i + 1], 5); | |
255 color_code[5] = 0; | |
256 text_color = atoi(color_code); | |
257 ui_current_text_color = text_color; | |
258 i += 5; | |
259 break; | |
260 case '\t': // Horizontal tab 09 | |
261 case '\r': //Carriage Return 0D 13 | |
262 break; | |
263 default: | |
264 uCharWidth = pMetrics[c].uWidth; | |
265 if ( uCharWidth ) | |
0 | 266 { |
1160 | 267 if ( i > 0 ) |
268 uX_pos += pMetrics[c].uLeftSpacing; | |
269 draw_color = text_color; | |
270 pCharPixels = &pFontData[font_pixels_offset[c]]; | |
271 if ( !text_color ) | |
272 draw_color = -1; | |
273 DrawCharToBuff(uX_pos, pCharPixels, uCharWidth, uFontHeight, pFontPalettes[0], draw_color, line_width); | |
274 uX_pos += uCharWidth; | |
275 if ( i < text_length ) | |
276 uX_pos += pMetrics[c].uRightSpacing; | |
0 | 277 } |
278 } | |
279 } | |
280 } | |
281 } | |
1160 | 282 |
0 | 283 |
284 | |
285 //----- (0044C933) -------------------------------------------------------- | |
180 | 286 char * GUIFont::_44C933(const char *pString, GUIFont *pFont, GUIFont *a3, int a4, int a5, int a6) |
0 | 287 { |
288 const char *v6; // esi@1 | |
289 size_t v8; // eax@3 | |
290 size_t v9; // edi@3 | |
291 int v10; // eax@3 | |
292 GUIFont *v11; // esi@3 | |
293 int v12; // ebx@3 | |
294 char v13; // cl@5 | |
295 int v14; // edx@11 | |
296 int v15; // ecx@11 | |
297 int v16; // edx@12 | |
298 int v17; // edx@13 | |
299 int v18; // edx@14 | |
300 int v19; // edx@15 | |
301 int v20; // edi@17 | |
302 int v21; // edx@17 | |
303 int v22; // ecx@17 | |
304 int v23; // edi@18 | |
305 char v24; // zf@18 | |
306 int v25; // ecx@19 | |
307 int v26; // eax@19 | |
308 char v27; // dl@24 | |
309 int v28; // eax@46 | |
310 std::string v29; // [sp-18h] [bp-48h]@2 | |
311 const char *v30; // [sp-8h] [bp-38h]@2 | |
312 int v31; // [sp-4h] [bp-34h]@2 | |
313 const char *v32; // [sp+Ch] [bp-24h]@1 | |
314 char Str; // [sp+10h] [bp-20h]@46 | |
315 char v34; // [sp+13h] [bp-1Dh]@46 | |
316 GUIFont *v35; // [sp+14h] [bp-1Ch]@1 | |
317 int v36; // [sp+18h] [bp-18h]@3 | |
318 int v37; // [sp+1Ch] [bp-14h]@3 | |
319 int v38; // [sp+20h] [bp-10h]@4 | |
320 int v39; // [sp+24h] [bp-Ch]@3 | |
321 int v40; // [sp+28h] [bp-8h]@3 | |
322 int i; // [sp+2Ch] [bp-4h]@17 | |
323 std::string *v42; // [sp+38h] [bp+8h]@2 | |
324 | |
325 v6 = pString; | |
326 v35 = pFont; | |
327 v32 = pString; | |
328 if ( !pString ) | |
329 { | |
330 MessageBoxW(nullptr, L"Invalid string passed !", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:558", 0); | |
331 return 0; | |
332 } | |
333 v8 = strlen(pString); | |
334 v9 = v8; | |
335 v39 = v8; | |
200 | 336 |
337 assert(strlen(v6) < sizeof(pTmpBuf3)); | |
0 | 338 strcpy(pTmpBuf3, v6); |
339 v10 = a5; | |
340 v11 = v35; | |
341 v12 = 0; | |
342 v40 = 0; | |
343 v37 = a5; | |
344 v36 = 0; | |
345 if ( (signed int)v9 > 0 ) | |
346 { | |
347 v38 = v9 - 1; | |
348 do | |
349 { | |
350 v13 = pTmpBuf3[v12]; | |
351 if ( (unsigned __int8)v13 >= v11->cFirstChar && (unsigned __int8)v13 <= v11->cLastChar | |
352 || v13 == '\f' | |
353 || v13 == '\r' | |
354 || v13 == '\t' | |
355 || v13 == '\n' ) | |
356 { | |
357 v14 = (unsigned __int8)v13 - 9; | |
358 v15 = (int)&v11->pMetrics[(unsigned __int8)v13]; | |
359 if ( v14 ) | |
360 { | |
361 v16 = v14 - 1; | |
362 if ( v16 ) | |
363 { | |
364 v17 = v16 - 2; | |
365 if ( v17 ) | |
366 { | |
367 v18 = v17 - 1; | |
368 if ( v18 ) | |
369 { | |
370 v19 = v18 - 19; | |
371 if ( v19 ) | |
372 { | |
373 if ( v19 == 63 ) | |
374 { | |
375 v11 = a3; | |
376 } | |
377 else | |
378 { | |
379 v20 = *(int *)(v15 + 8); | |
380 v21 = *(int *)(v15 + 4); | |
381 v22 = *(int *)v15; | |
382 i = v20; | |
383 if ( (unsigned int)(v10 + v20 + v22 + v21) < *(int *)(a4 + 8) ) | |
384 { | |
385 v12 = v36; | |
386 if ( v36 > v40 ) | |
387 v10 += v22; | |
388 v10 += v21; | |
389 if ( v36 < v39 ) | |
390 v10 += i; | |
391 } | |
392 else | |
393 { | |
394 v23 = v40; | |
395 v24 = v11 == a3; | |
396 pTmpBuf3[v40] = 10; | |
397 if ( v24 ) | |
398 { | |
399 v25 = v38; | |
400 v26 = v23 + 1; | |
401 while ( v25 >= v26 ) | |
402 { | |
403 pTmpBuf3[v25] = byte_5C45AF[v25]; | |
404 --v25; | |
405 } | |
406 ++v39; | |
407 ++v38; | |
408 pTmpBuf3[v23++ + 1] = 95; | |
409 v40 = v26; | |
410 } | |
411 v12 = v36; | |
412 v10 = v37; | |
413 for ( i = v23; i <= v36; ++i ) | |
414 { | |
415 v27 = pTmpBuf3[i]; | |
416 if ( (unsigned __int8)v27 >= v11->cFirstChar && (unsigned __int8)v27 <= v11->cLastChar | |
417 || v27 == 12 | |
418 || v27 == 13 | |
419 || v27 == 9 | |
420 || v27 == 10 ) | |
421 { | |
422 if ( i > v23 ) | |
423 v10 += v11->pMetrics[(unsigned __int8)v27].uLeftSpacing; | |
424 v10 += *((int *)&v11->cFirstChar + 3 * (unsigned __int8)v27 + 9); | |
425 if ( i < v36 ) | |
426 v10 += v11->pMetrics[(unsigned __int8)v27].uRightSpacing; | |
427 } | |
428 } | |
429 } | |
430 } | |
431 } | |
432 else | |
433 { | |
434 v10 += *(int *)(v15 + 4); | |
435 v40 = v12; | |
436 } | |
437 } | |
438 else | |
439 { | |
440 if ( !a6 ) | |
441 return (char *)v32; | |
442 } | |
443 } | |
444 else | |
445 { | |
446 v12 += 5; | |
447 } | |
448 } | |
449 else | |
450 { | |
451 v10 = v37; | |
452 v11 = v35; | |
453 v40 = v12; | |
454 } | |
455 } | |
456 else | |
457 { | |
458 strncpy(&Str, &pTmpBuf3[v12 + 1], 3u); | |
459 v34 = 0; | |
460 v28 = atoi(&Str); | |
461 v10 = a5 + v28; | |
462 v12 += 3; | |
463 v37 = v10; | |
464 } | |
465 } | |
466 ++v12; | |
467 v36 = v12; | |
468 } | |
469 while ( v12 < v39 ); | |
470 } | |
471 return pTmpBuf3; | |
472 } | |
473 | |
474 | |
475 //----- (0044C6C2) -------------------------------------------------------- | |
1160 | 476 char* GUIFont::_44C6C2( const char *pInString, GUIWindow *pWindow, unsigned int uX, int a5 ) |
477 { | |
478 int text_height; // edi@1 | |
479 char *text_str; // ebx@3 | |
480 int i; | |
481 unsigned char c; // cl@4 | |
482 int text_length; | |
0 | 483 |
1160 | 484 text_height = 0; |
485 | |
0 | 486 if ( !pInString ) |
487 return 0; | |
1160 | 488 text_str = FitTextInAWindow(pInString, this, pWindow, uX, 0); |
489 text_length = strlen(text_str); | |
490 //uX_pos=uX_buff_pos; | |
491 for (i=0; i<text_length; ++i ) | |
492 { | |
493 c = text_str[i]; | |
494 if ( IsCharValid(c) ) | |
495 { | |
496 switch (c) | |
497 { | |
498 case '\n': //Line Feed 0A 10: | |
499 text_height = text_height + uFontHeight - 3; | |
500 if ( text_height >= (signed int)(a5 * pWindow->uFrameHeight) ) | |
501 return &text_str[i+1]; | |
502 break; | |
503 case '\f': //Form Feed, page eject 0C 12 | |
504 i += 5; | |
505 break; | |
506 case '\t': // Horizontal tab 09 | |
507 case '\r': //Carriage Return 0D 13 | |
508 i += 3; | |
509 break; | |
510 } | |
511 if ( text_height >= (signed int)(a5 * pWindow->uFrameHeight) ) | |
512 return &text_str[i]; | |
513 } | |
514 } | |
515 return &text_str[i]; | |
0 | 516 } |
517 | |
518 | |
519 | |
520 //----- (0044C62E) -------------------------------------------------------- | |
521 int GUIFont::GetStringHeight2(GUIFont *a2, const char *Str, int a4, int a5, int a6) | |
522 { | |
523 GUIFont *v6; // edi@1 | |
524 int v8; // esi@3 | |
525 unsigned __int8 *v9; // ebx@3 | |
526 size_t v10; // eax@3 | |
527 unsigned __int8 v11; // cl@4 | |
528 signed int Stra; // [sp+Ch] [bp+8h]@3 | |
529 size_t v13; // [sp+14h] [bp+10h]@3 | |
530 | |
531 auto a1 = this; | |
532 v6 = a1; | |
533 if ( !Str ) | |
534 return 0; | |
535 v8 = LOBYTE(a1->uFontHeight) - 3; | |
536 v9 = (unsigned __int8 *)GUIFont::_44C933(Str, a1, a2, a4, a5, 0); | |
537 v10 = strlen(Str); | |
538 Stra = 0; | |
539 v13 = v10; | |
540 while ( Stra < (signed int)v13 ) | |
541 { | |
542 if ( GUIFont::IsCharValid(v11 = *v9) ) | |
543 { | |
544 if ( v11 == 9 ) | |
545 goto LABEL_9; | |
546 switch ( v11 ) | |
547 { | |
548 case 0xAu: | |
549 v8 = v8 + LOBYTE(v6->uFontHeight) - 3; | |
550 break; | |
551 case 0xCu: | |
552 v9 += 5; | |
553 Stra += 5; | |
554 break; | |
555 case 0xDu: | |
556 LABEL_9: | |
557 if ( a6 != 1 ) | |
558 { | |
559 v9 += 3; | |
560 Stra += 3; | |
561 } | |
562 break; | |
563 } | |
564 } | |
565 ++Stra; | |
566 ++v9; | |
567 } | |
568 return v8; | |
569 } | |
570 | |
571 //----- (0044C59D) -------------------------------------------------------- | |
1160 | 572 int GUIFont::CalcTextHeight( const char *pString, struct GUIWindow *pWindow, int uXOffset, int a5 ) |
573 { | |
189 | 574 int uAllHeght; |
1160 | 575 int uStringLen; |
576 unsigned char c; | |
189 | 577 char *test_string; |
0 | 578 |
180 | 579 if (!pString) |
580 return 0; | |
581 uAllHeght = this->uFontHeight - 3; | |
582 test_string = FitTextInAWindow(pString, this, pWindow, uXOffset, 0); | |
583 uStringLen = strlen(pString); | |
584 for (int i = 0; i < uStringLen; ++i) | |
585 { | |
586 c = test_string[i]; | |
587 if (IsCharValid(c)) | |
588 { | |
589 switch (c) | |
590 { | |
591 case '\n': //Line Feed 0A 10: | |
592 uAllHeght+= this->uFontHeight - 3; | |
593 break; | |
594 case '\f': //Form Feed, page eject 0C 12 | |
595 i += 5; | |
596 break; | |
597 case '\t': // Horizontal tab 09 | |
598 case '\r': //Carriage Return 0D 13 | |
599 if (a5 != 1) | |
600 i += 3; | |
601 break; | |
602 } | |
603 } | |
604 } | |
605 return uAllHeght; | |
606 } | |
0 | 607 |
608 | |
609 //----- (0044C51E) -------------------------------------------------------- | |
610 int GUIFont::GetLineWidth(const char *pString) | |
180 | 611 { |
1160 | 612 int str_len; // ebp@3 |
180 | 613 int string_line_width; // esi@3 |
614 unsigned char c; | |
0 | 615 |
180 | 616 if (!pString) |
617 return 0; | |
618 str_len = strlen(pString); | |
619 string_line_width = 0; | |
620 for ( int i = 0; i < str_len; ++i ) | |
621 { | |
622 c = pString[i]; | |
623 if (IsCharValid(c)) | |
624 { | |
625 switch (c) | |
626 { | |
627 case '\t': | |
628 case '\n': | |
629 case '\r': | |
630 return string_line_width; | |
631 case '\f': | |
632 i += 5; | |
633 break; | |
634 default: | |
635 if (i > 0) | |
636 string_line_width += this->pMetrics[c].uLeftSpacing; | |
637 string_line_width += this->pMetrics[c].uWidth; | |
638 if (i < str_len) | |
639 string_line_width +=this->pMetrics[c].uRightSpacing; | |
640 } | |
641 } | |
642 } | |
643 return string_line_width; | |
644 } | |
0 | 645 |
646 | |
647 //----- (0044C502) -------------------------------------------------------- | |
648 int GUIFont::AlignText_Center(unsigned int uCenterX, const char *pString) | |
649 { | |
180 | 650 signed int position; // esi@1 |
651 | |
652 position = (signed int)(uCenterX - GetLineWidth(pString)) >> 1; | |
653 if ( position >= 0 ) | |
654 return position; | |
655 else | |
656 return 0; | |
178 | 657 |
0 | 658 } |
659 | |
180 | 660 //----- (0044C768) -------------------------------------------------------- |
688 | 661 char * FitTextInAWindow( const char *pInString, GUIFont *pFont, GUIWindow *pWindow, signed int uX, int a5 ) |
662 { | |
189 | 663 unsigned char c; |
1160 | 664 int uInStrLen; |
189 | 665 char digits[4]; |
666 int possible_transition_point; | |
667 int string_pixel_Width; | |
668 int start_pixel_offset; | |
0 | 669 |
189 | 670 if (!pInString) |
180 | 671 { |
672 MessageBoxW(nullptr, L"Invalid string passed !", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:445", 0); | |
673 return 0; | |
674 } | |
189 | 675 uInStrLen = strlen(pInString); |
676 strcpy(&temp_string[0], pInString); | |
677 if (uInStrLen==0) | |
678 return &temp_string[0]; | |
679 | |
680 start_pixel_offset=string_pixel_Width=uX; | |
681 possible_transition_point=0; | |
682 for(int i=0; i<uInStrLen; ++i) | |
180 | 683 { |
189 | 684 c=temp_string[i]; |
685 if (pFont->IsCharValid(c)) | |
180 | 686 { |
189 | 687 switch (c) |
688 { | |
689 case '\t': // Horizontal tab 09 | |
690 { | |
691 strncpy(digits, &temp_string[i+1],3); | |
692 digits[3]=0; | |
693 string_pixel_Width= atoi(digits)+uX; | |
694 i+=3; | |
695 break; | |
696 } | |
697 case '\n': //Line Feed 0A 10 | |
698 { | |
699 string_pixel_Width=start_pixel_offset; | |
700 possible_transition_point=i; | |
701 break; | |
702 } | |
703 case '\f': //Form Feed, page eject 0C 12 | |
180 | 704 { |
189 | 705 i+=5; |
706 break; | |
180 | 707 } |
189 | 708 case '\r': //Carriage Return 0D 13 |
709 { | |
710 if (!a5) | |
711 return (char*)pInString; | |
180 | 712 break; |
189 | 713 } |
714 case ' ' : | |
180 | 715 { |
189 | 716 string_pixel_Width+=pFont->pMetrics[c].uWidth; |
717 possible_transition_point=i; | |
718 break; | |
180 | 719 } |
189 | 720 default: |
721 | |
722 if ((string_pixel_Width+pFont->pMetrics[c].uWidth+ pFont->pMetrics[c].uLeftSpacing+ | |
723 pFont->pMetrics[c].uRightSpacing)<pWindow->uFrameWidth) | |
180 | 724 { |
189 | 725 if(i>possible_transition_point) |
726 string_pixel_Width+=pFont->pMetrics[c].uLeftSpacing; | |
727 string_pixel_Width+=pFont->pMetrics[c].uWidth; | |
728 if (i<uInStrLen) | |
729 string_pixel_Width+=pFont->pMetrics[c].uRightSpacing; | |
730 } | |
731 else | |
732 { | |
733 temp_string[possible_transition_point]='\n'; | |
734 string_pixel_Width=start_pixel_offset; | |
735 if (i>possible_transition_point) | |
180 | 736 { |
189 | 737 for(int j=possible_transition_point;j<i; ++j ) |
180 | 738 { |
189 | 739 c=temp_string[j]; |
740 if (pFont->IsCharValid(c)) | |
180 | 741 { |
189 | 742 if(j>possible_transition_point) |
743 string_pixel_Width+=pFont->pMetrics[c].uLeftSpacing; | |
744 string_pixel_Width+=pFont->pMetrics[c].uWidth; | |
745 if (j<i) | |
746 string_pixel_Width+=pFont->pMetrics[c].uRightSpacing; | |
747 | |
180 | 748 } |
189 | 749 } |
180 | 750 } |
751 } | |
752 } | |
753 } | |
754 } | |
189 | 755 return &temp_string[0]; |
180 | 756 } |