comparison GUIFont.cpp @ 0:8b8875f5b359

Initial commit
author Nomad
date Fri, 05 Oct 2012 16:07:14 +0200
parents
children 540178ef9b18
comparison
equal deleted inserted replaced
-1:000000000000 0:8b8875f5b359
1 #include <string>
2
3 #include "GUIFont.h"
4 #include "GUIWindow.h"
5 #include "Render.h"
6
7 #include "mm7_data.h"
8
9
10
11
12
13 struct GUIFont *pAutonoteFont;
14 struct GUIFont *pSpellFont;
15 struct GUIFont *pFontArrus;
16 struct GUIFont *pFontLucida;
17 struct GUIFont *pBook2Font;
18 struct GUIFont *pBookFont;
19 struct GUIFont *pFontCreate;
20 struct GUIFont *pFontCChar;
21 struct GUIFont *pFontComic;
22 struct GUIFont *pFontSmallnum;
23
24
25
26
27 //----- (0044D2FD) --------------------------------------------------------
28 void GUIFont::_44D2FD_prolly_draw_credits_entry(GUIFont *pFont, int Str, int a4, unsigned int w, unsigned int h, unsigned __int16 a7, unsigned __int16 a8, const char *pString, unsigned __int16 *pPixels, unsigned int uPixelsWidth)
29 {
30 int v11; // ebx@1
31 int v12; // edi@1
32 char *v13; // eax@1
33 char *v14; // eax@1
34 unsigned __int16 *v15; // esi@1
35 GUIFont *v16; // edi@4
36 signed int v17; // ecx@4
37 signed int v18; // eax@6
38 int v19; // [sp+Ch] [bp-5Ch]@1
39 int v20; // [sp+10h] [bp-58h]@1
40 unsigned int v21; // [sp+14h] [bp-54h]@1
41 unsigned int v22; // [sp+18h] [bp-50h]@1
42 unsigned int v23; // [sp+1Ch] [bp-4Ch]@1
43 unsigned int v24; // [sp+20h] [bp-48h]@1
44 GUIFont *v25; // [sp+60h] [bp-8h]@1
45 GUIFont *v26; // [sp+64h] [bp-4h]@1
46 char *Stra; // [sp+70h] [bp+8h]@1
47 int a4a; // [sp+74h] [bp+Ch]@4
48 int a7a; // [sp+80h] [bp+18h]@2
49
50 v11 = a7;
51 v22 = h;
52 v12 = Str;
53 v26 = this;
54 v24 = a4 + h - 1;
55 v21 = w;
56 v25 = pFont;
57 v23 = Str + w - 1;
58 ui_current_text_color = a7;
59 v19 = Str;
60 v20 = a4;
61 v13 = GUIFont::_44C933(pString, this, pFont, (int)&v19, 0, 1);
62 v14 = strtok(v13, "\n");
63 Stra = v14;
64 v15 = &pPixels[uPixelsWidth * a4];
65 if ( v14 )
66 {
67 a7a = v12 >> 1;
68 while ( 1 )
69 {
70 v16 = v26;
71 ui_current_text_color = v11;
72 v17 = 0;
73 a4a = v11;
74 if ( *v14 == '_' )
75 {
76 v16 = v25;
77 a4a = a8;
78 ui_current_text_color = a8;
79 v17 = 1;
80 }
81 v18 = (signed int)(w - v16->GetLineWidth(&v14[v17])) >> 1;
82 if ( v18 < 0 )
83 v18 = 0;
84 v16->_44D0B5(a4a, a8, (int)&v15[v18 + a7a], Stra, uPixelsWidth);
85 v15 += uPixelsWidth * (LOBYTE(v16->uFontHeight) - 3);
86 Stra = strtok(0, "\n");
87 if ( !Stra )
88 break;
89 v14 = Stra;
90 }
91 }
92 }
93 // 5C6DB4: using guessed type int ui_current_text_color;
94
95
96 //----- (0044D1E7) --------------------------------------------------------
97 void GUIFont::DrawTextLine(unsigned int uDefaultColor, signed int uX, signed int uY, const char *Str, int a6)
98 {
99 size_t v6; // ebx@1
100 GUIFont *v7; // esi@1
101 signed int v8; // edi@3
102 unsigned __int8 v9; // cl@4
103 int v10; // eax@5
104 int v11; // ecx@5
105 int v12; // ecx@6
106 int v13; // ecx@7
107 int v14; // ecx@9
108 unsigned int v15; // edx@9
109 unsigned __int16 v16; // cx@12
110 unsigned __int8 *v17; // eax@12
111 char Dest; // [sp+Ch] [bp-1Ch]@16
112 char v19; // [sp+11h] [bp-17h]@16
113 size_t v20; // [sp+20h] [bp-8h]@2
114 int v21; // [sp+24h] [bp-4h]@1
115 int uXa; // [sp+30h] [bp+8h]@9
116
117 v6 = 0;
118 v21 = uDefaultColor;
119 v7 = this;
120 if ( Str )
121 {
122 v21 = ui_current_text_color;
123 v20 = strlen(Str);
124 if ( (signed int)v20 > 0 )
125 {
126 v8 = uX;
127 do
128 {
129 if ( v7->IsCharValid(v9 = Str[v6]) )
130 {
131 v10 = v9;
132 v11 = v9 - 9;
133 if ( v11 )
134 {
135 v12 = v11 - 1;
136 if ( !v12 )
137 return;
138 v13 = v12 - 2;
139 if ( v13 )
140 {
141 if ( v13 != 1 )
142 {
143 v14 = 3 * v10 + 9;
144 v15 = *((int *)&v7->cFirstChar + v14);
145 uXa = *((int *)&v7->cFirstChar + v14);
146 if ( v15 )
147 {
148 if ( (signed int)v6 > 0 )
149 v8 += v7->pMetrics[v10].uLeftSpacing;
150 v16 = v21;
151 v17 = (unsigned __int8 *)((char *)&v7[1] + v7->field_C20[v10]);
152 if ( !v21 )
153 v16 = -1;
154 pRenderer->DrawText(v8, uY, v17, v15, LOBYTE(v7->uFontHeight), v7->pFontPalettes[0], v16, 0);
155 v8 += uXa;
156 if ( (signed int)v6 < (signed int)v20 )
157 v8 += v7->pMetrics[(unsigned __int8)Str[v6]].uRightSpacing;
158 }
159 }
160 }
161 else
162 {
163 strncpy(&Dest, &Str[v6 + 1], 5u);
164 v19 = 0;
165 v21 = atoi(&Dest);
166 ui_current_text_color = v21;
167 v6 += 5;
168 }
169 }
170 }
171 ++v6;
172 }
173 while ( (signed int)v6 < (signed int)v20 );
174 }
175 }
176 }
177 // 5C6DB4: using guessed type int ui_current_text_color;
178
179
180 //----- (0044D0B5) --------------------------------------------------------
181 void GUIFont::_44D0B5(int a2, int a3, int a4, const char *pString, int a6)
182 {
183 int v6; // ebx@1
184 GUIFont *v7; // esi@1
185 int v8; // edi@3
186 unsigned __int8 v9; // cl@4
187 int v10; // eax@5
188 int v11; // ecx@5
189 int v12; // ecx@6
190 int v13; // ecx@7
191 int v14; // ecx@8
192 int v15; // ebx@10
193 int v16; // edx@13
194 __int16 v17; // ax@13
195 char Dest; // [sp+Ch] [bp-20h]@17
196 char v19; // [sp+11h] [bp-1Bh]@17
197 size_t v20; // [sp+20h] [bp-Ch]@2
198 int v21; // [sp+24h] [bp-8h]@1
199 int v22; // [sp+28h] [bp-4h]@2
200 const char *v23; // [sp+38h] [bp+Ch]@4
201
202 v6 = 0;
203 v21 = a2;
204 v7 = this;
205 if ( pString )
206 {
207 v21 = ui_current_text_color;
208 v20 = strlen(pString);
209 v22 = 0;
210 if ( (signed int)v20 > 0 )
211 {
212 v8 = a4;
213 do
214 {
215 v23 = &pString[v6];
216 if ( v7->IsCharValid(pString[v6]) )
217 {
218 v10 = v9;
219 v11 = v9 - 9;
220 if ( v11 )
221 {
222 v12 = v11 - 1;
223 if ( !v12 )
224 return;
225 v13 = v12 - 2;
226 if ( v13 )
227 {
228 v14 = v13 - 1;
229 if ( v14 )
230 {
231 if ( v14 != 82 )
232 {
233 v15 = *((int *)&v7->cFirstChar + 3 * v10 + 9);
234 if ( v15 )
235 {
236 if ( v22 > 0 )
237 v8 += 2 * v7->pMetrics[v10].uLeftSpacing;
238 v16 = (int)((char *)&v7[1] + v7->field_C20[v10]);
239 v17 = v21;
240 if ( !v21 )
241 v17 = -1;
242 sub_40F845(v8, v16, v15, LOBYTE(v7->uFontHeight), (int)v7->pFontPalettes[0], v17, 2 * a6);
243 v8 += 2 * v15;
244 if ( v22 < (signed int)v20 )
245 v8 += 2 * v7->pMetrics[(unsigned __int8)*v23].uRightSpacing;
246 }
247 }
248 }
249 }
250 else
251 {
252 strncpy(&Dest, &pString[v6 + 1], 5u);
253 v19 = 0;
254 v21 = atoi(&Dest);
255 ui_current_text_color = v21;
256 v22 = v6 + 5;
257 }
258 }
259 }
260 v6 = v22++ + 1;
261 }
262 while ( v22 < (signed int)v20 );
263 }
264 }
265 }
266 // 5C6DB4: using guessed type int ui_current_text_color;
267
268
269 //----- (0044C933) --------------------------------------------------------
270 char *__fastcall GUIFont::_44C933(const char *pString, GUIFont *pFont, GUIFont *a3, int a4, int a5, int a6)
271 {
272 const char *v6; // esi@1
273 size_t v8; // eax@3
274 size_t v9; // edi@3
275 int v10; // eax@3
276 GUIFont *v11; // esi@3
277 int v12; // ebx@3
278 char v13; // cl@5
279 int v14; // edx@11
280 int v15; // ecx@11
281 int v16; // edx@12
282 int v17; // edx@13
283 int v18; // edx@14
284 int v19; // edx@15
285 int v20; // edi@17
286 int v21; // edx@17
287 int v22; // ecx@17
288 int v23; // edi@18
289 char v24; // zf@18
290 int v25; // ecx@19
291 int v26; // eax@19
292 char v27; // dl@24
293 int v28; // eax@46
294 std::string v29; // [sp-18h] [bp-48h]@2
295 const char *v30; // [sp-8h] [bp-38h]@2
296 int v31; // [sp-4h] [bp-34h]@2
297 const char *v32; // [sp+Ch] [bp-24h]@1
298 char Str; // [sp+10h] [bp-20h]@46
299 char v34; // [sp+13h] [bp-1Dh]@46
300 GUIFont *v35; // [sp+14h] [bp-1Ch]@1
301 int v36; // [sp+18h] [bp-18h]@3
302 int v37; // [sp+1Ch] [bp-14h]@3
303 int v38; // [sp+20h] [bp-10h]@4
304 int v39; // [sp+24h] [bp-Ch]@3
305 int v40; // [sp+28h] [bp-8h]@3
306 int i; // [sp+2Ch] [bp-4h]@17
307 std::string *v42; // [sp+38h] [bp+8h]@2
308
309 v6 = pString;
310 v35 = pFont;
311 v32 = pString;
312 if ( !pString )
313 {
314 MessageBoxW(nullptr, L"Invalid string passed !", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:558", 0);
315 return 0;
316 }
317 v8 = strlen(pString);
318 v9 = v8;
319 v39 = v8;
320 strcpy(pTmpBuf3, v6);
321 v10 = a5;
322 v11 = v35;
323 v12 = 0;
324 v40 = 0;
325 v37 = a5;
326 v36 = 0;
327 if ( (signed int)v9 > 0 )
328 {
329 v38 = v9 - 1;
330 do
331 {
332 v13 = pTmpBuf3[v12];
333 if ( (unsigned __int8)v13 >= v11->cFirstChar && (unsigned __int8)v13 <= v11->cLastChar
334 || v13 == '\f'
335 || v13 == '\r'
336 || v13 == '\t'
337 || v13 == '\n' )
338 {
339 v14 = (unsigned __int8)v13 - 9;
340 v15 = (int)&v11->pMetrics[(unsigned __int8)v13];
341 if ( v14 )
342 {
343 v16 = v14 - 1;
344 if ( v16 )
345 {
346 v17 = v16 - 2;
347 if ( v17 )
348 {
349 v18 = v17 - 1;
350 if ( v18 )
351 {
352 v19 = v18 - 19;
353 if ( v19 )
354 {
355 if ( v19 == 63 )
356 {
357 v11 = a3;
358 }
359 else
360 {
361 v20 = *(int *)(v15 + 8);
362 v21 = *(int *)(v15 + 4);
363 v22 = *(int *)v15;
364 i = v20;
365 if ( (unsigned int)(v10 + v20 + v22 + v21) < *(int *)(a4 + 8) )
366 {
367 v12 = v36;
368 if ( v36 > v40 )
369 v10 += v22;
370 v10 += v21;
371 if ( v36 < v39 )
372 v10 += i;
373 }
374 else
375 {
376 v23 = v40;
377 v24 = v11 == a3;
378 pTmpBuf3[v40] = 10;
379 if ( v24 )
380 {
381 v25 = v38;
382 v26 = v23 + 1;
383 while ( v25 >= v26 )
384 {
385 pTmpBuf3[v25] = byte_5C45AF[v25];
386 --v25;
387 }
388 ++v39;
389 ++v38;
390 pTmpBuf3[v23++ + 1] = 95;
391 v40 = v26;
392 }
393 v12 = v36;
394 v10 = v37;
395 for ( i = v23; i <= v36; ++i )
396 {
397 v27 = pTmpBuf3[i];
398 if ( (unsigned __int8)v27 >= v11->cFirstChar && (unsigned __int8)v27 <= v11->cLastChar
399 || v27 == 12
400 || v27 == 13
401 || v27 == 9
402 || v27 == 10 )
403 {
404 if ( i > v23 )
405 v10 += v11->pMetrics[(unsigned __int8)v27].uLeftSpacing;
406 v10 += *((int *)&v11->cFirstChar + 3 * (unsigned __int8)v27 + 9);
407 if ( i < v36 )
408 v10 += v11->pMetrics[(unsigned __int8)v27].uRightSpacing;
409 }
410 }
411 }
412 }
413 }
414 else
415 {
416 v10 += *(int *)(v15 + 4);
417 v40 = v12;
418 }
419 }
420 else
421 {
422 if ( !a6 )
423 return (char *)v32;
424 }
425 }
426 else
427 {
428 v12 += 5;
429 }
430 }
431 else
432 {
433 v10 = v37;
434 v11 = v35;
435 v40 = v12;
436 }
437 }
438 else
439 {
440 strncpy(&Str, &pTmpBuf3[v12 + 1], 3u);
441 v34 = 0;
442 v28 = atoi(&Str);
443 v10 = a5 + v28;
444 v12 += 3;
445 v37 = v10;
446 }
447 }
448 ++v12;
449 v36 = v12;
450 }
451 while ( v12 < v39 );
452 }
453 return pTmpBuf3;
454 }
455
456
457 //----- (0044C6C2) --------------------------------------------------------
458 int GUIFont::_44C6C2(const char *pInString, GUIWindow *pWindow, unsigned int uX, int a5)
459 {
460 const char *v5; // esi@1
461 int v6; // edi@1
462 unsigned __int8 *v8; // ebx@3
463 size_t v9; // eax@3
464 signed int v10; // esi@3
465 int v11; // edx@4
466 unsigned __int8 v12; // cl@4
467 GUIFont *v13; // [sp+Ch] [bp-4h]@1
468 size_t uXa; // [sp+1Ch] [bp+Ch]@3
469
470 auto pFont = this;
471 v5 = pInString;
472 v6 = 0;
473 v13 = pFont;
474 if ( !pInString )
475 return 0;
476 v8 = (unsigned __int8 *)FitTextInAWindow(pInString, pFont, pWindow, uX, 0);
477 v9 = strlen(v5);
478 v10 = 0;
479 uXa = v9;
480 if ( (signed int)v9 > 0 )
481 {
482 while ( !IsCharValid(*v8) )
483 {
484 LABEL_11:
485 ++v10;
486 ++v8;
487 if ( v10 >= (signed int)uXa )
488 return (int)v8;
489 }
490 if ( v12 != 9 )
491 {
492 if ( v12 == 10 )
493 {
494 v6 = v6 + *(char *)(v11 + 5) - 3;
495 if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) )
496 return (int)(v8 + 1);
497 goto LABEL_10;
498 }
499 if ( v12 == 12 )
500 {
501 v8 += 5;
502 v10 += 5;
503 LABEL_10:
504 if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) )
505 return (int)v8;
506 goto LABEL_11;
507 }
508 if ( v12 != 13 )
509 goto LABEL_10;
510 }
511 v8 += 3;
512 v10 += 3;
513 goto LABEL_10;
514 }
515 return (int)v8;
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(*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) --------------------------------------------------------
572 int GUIFont::CalcTextHeight(const char *pString, GUIWindow *pWindow, int a4, int a5)
573 {
574 const char *v5; // ebx@1
575 GUIFont *v6; // edi@1
576 int v8; // esi@3
577 size_t v9; // eax@3
578 signed int v10; // ebx@3
579 unsigned __int8 v11; // cl@4
580 size_t pWindowa; // [sp+10h] [bp+8h]@3
581 unsigned __int8 *uX; // [sp+14h] [bp+Ch]@3
582
583 v5 = pString;
584 v6 = this;
585 if ( !pString )
586 return 0;
587 v8 = LOBYTE(this->uFontHeight) - 3;
588 uX = (unsigned __int8 *)FitTextInAWindow(pString, this, pWindow, a4, 0);
589 v9 = strlen(v5);
590 v10 = 0;
591 pWindowa = v9;
592 while ( v10 < (signed int)pWindowa )
593 {
594 if ( v6->IsCharValid(v11 = *uX) )
595 {
596 if ( v11 == 9 )
597 goto LABEL_9;
598 switch ( v11 )
599 {
600 case 0xAu:
601 v8 = v8 + LOBYTE(v6->uFontHeight) - 3;
602 break;
603 case 0xCu:
604 uX += 5;
605 v10 += 5;
606 break;
607 case 0xDu:
608 LABEL_9:
609 if ( a5 != 1 )
610 {
611 uX += 3;
612 v10 += 3;
613 }
614 break;
615 }
616 }
617 ++v10;
618 ++uX;
619 }
620 return v8;
621 }
622
623
624 //----- (0044C51E) --------------------------------------------------------
625 int GUIFont::GetLineWidth(const char *pString)
626 {
627 GUIFont *v2; // edi@1
628 size_t v4; // ebp@3
629 int v5; // esi@3
630 signed int i; // ebx@3
631 unsigned __int8 v7; // cl@4
632 const char *v8; // [sp+0h] [bp-4h]@1
633
634 v8 = pString;
635 v2 = this;
636 if ( !pString )
637 return 0;
638 v4 = strlen(pString);
639 v5 = 0;
640 for ( i = 0; i < (signed int)v4; ++i )
641 {
642 if ( IsCharValid(v7 = v8[i]) )
643 {
644 if ( v7 < 9u )
645 goto LABEL_9;
646 if ( v7 <= 0xAu )
647 return v5;
648 if ( v7 != '\f' )
649 {
650 if ( v7 == '\r' )
651 return v5;
652 LABEL_9:
653 if ( i > 0 )
654 v5 += v2->pMetrics[v7].uLeftSpacing;
655 v5 += *((int *)&v2->cFirstChar + 3 * v7 + 9);
656 if ( i < (signed int)v4 )
657 v5 += v2->pMetrics[v7].uRightSpacing;
658 continue;
659 }
660 i += 5;
661 }
662 }
663 return v5;
664 }
665
666
667
668
669 //----- (0044C502) --------------------------------------------------------
670 int GUIFont::AlignText_Center(unsigned int uCenterX, const char *pString)
671 {
672 signed int v3; // esi@1
673 signed int result; // eax@2
674
675 v3 = (signed int)(uCenterX - GetLineWidth(pString)) >> 1;
676 if ( v3 >= 0 )
677 result = v3;
678 else
679 result = 0;
680 return result;
681 }
682
683
684 //----- (0044C4DE) --------------------------------------------------------
685 bool GUIFont::IsCharValid(char _c)
686 {
687 unsigned char c = _c;
688 return c >= cFirstChar && c <= cLastChar || c == '\f' || c == '\r' || c == '\t' || c == '\n';
689 }