Mercurial > mm7
comparison GUIFont.cpp @ 170:91fa025e6ca6
font cleaning code
author | C:\Documents and Settings\Administrator.SDF-1\Application Data\The Bat! |
---|---|
date | Fri, 15 Feb 2013 01:21:53 +0400 |
parents | b9ac55f2c8e6 |
children | 05682713195c |
comparison
equal
deleted
inserted
replaced
169:d1dde383af89 | 170:91fa025e6ca6 |
---|---|
1 #include <string> | 1 #include <string> |
2 | 2 #include "LOD.h" |
3 #include "GUIFont.h" | 3 #include "GUIFont.h" |
4 #include "GUIWindow.h" | 4 #include "GUIWindow.h" |
5 #include "Render.h" | 5 #include "Render.h" |
6 | 6 |
7 #include "mm7_data.h" | 7 #include "mm7_data.h" |
8 | 8 |
9 | 9 |
10 | 10 extern LODFile_IconsBitmaps *pIcons_LOD; |
11 | 11 |
12 | 12 |
13 struct GUIFont *pAutonoteFont; | 13 struct GUIFont *pAutonoteFont; |
14 struct GUIFont *pSpellFont; | 14 struct GUIFont *pSpellFont; |
15 struct GUIFont *pFontArrus; | 15 struct GUIFont *pFontArrus; |
19 struct GUIFont *pFontCreate; | 19 struct GUIFont *pFontCreate; |
20 struct GUIFont *pFontCChar; | 20 struct GUIFont *pFontCChar; |
21 struct GUIFont *pFontComic; | 21 struct GUIFont *pFontComic; |
22 struct GUIFont *pFontSmallnum; | 22 struct GUIFont *pFontSmallnum; |
23 | 23 |
24 //----- (0044C448) -------------------------------------------------------- | |
25 GUIFont *LoadFont(const char *pFontFile, const char *pFontPalette, ...) | |
26 { | |
27 | |
28 int pallete_index; // eax@3 | |
29 GUIFont *pFont; | |
30 unsigned int palletes_count =0; | |
31 va_list palettes_ptr; | |
32 | |
33 pFont = (GUIFont *)pIcons_LOD->LoadRaw(pFontFile, 0); | |
34 va_start(palettes_ptr, pFontFile); | |
35 | |
36 while (NULL!=(pFontPalette=va_arg(palettes_ptr, const char *))) | |
37 { | |
38 pallete_index =pIcons_LOD->LoadTexture(pFontPalette, TEXTURE_16BIT_PALETTE); | |
39 if (pallete_index == -1) | |
40 { | |
41 wsprintfA(pTmpBuf, "Unable to open %s", pFontPalette); | |
42 Abortf(pTmpBuf); | |
43 } | |
44 pFont->pFontPalettes[palletes_count] = pIcons_LOD->pTextures[pallete_index].pPalette16; | |
45 ++palletes_count; | |
46 } | |
47 va_end(palettes_ptr); | |
48 pFont->palletes_count = palletes_count; | |
49 return pFont; | |
50 } | |
24 | 51 |
25 | 52 |
26 | 53 |
27 //----- (0044D2FD) -------------------------------------------------------- | 54 //----- (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) | 55 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) |
265 } | 292 } |
266 // 5C6DB4: using guessed type int ui_current_text_color; | 293 // 5C6DB4: using guessed type int ui_current_text_color; |
267 | 294 |
268 | 295 |
269 //----- (0044C933) -------------------------------------------------------- | 296 //----- (0044C933) -------------------------------------------------------- |
270 char *__fastcall GUIFont::_44C933(const char *pString, GUIFont *pFont, GUIFont *a3, int a4, int a5, int a6) | 297 char * GUIFont::_44C933(const char *pString, GUIFont *pFont, GUIFont *a3, int a4, int a5, int a6) |
271 { | 298 { |
272 const char *v6; // esi@1 | 299 const char *v6; // esi@1 |
273 size_t v8; // eax@3 | 300 size_t v8; // eax@3 |
274 size_t v9; // edi@3 | 301 size_t v9; // edi@3 |
275 int v10; // eax@3 | 302 int v10; // eax@3 |
574 } | 601 } |
575 return v8; | 602 return v8; |
576 } | 603 } |
577 | 604 |
578 //----- (0044C59D) -------------------------------------------------------- | 605 //----- (0044C59D) -------------------------------------------------------- |
579 int GUIFont::CalcTextHeight(const char *pString, GUIWindow *pWindow, int a4, int a5) | 606 int GUIFont::CalcTextHeight(const char *pString, GUIWindow *pWindow, int uXOffset, int a5) |
580 { | 607 { |
581 const char *v5; // ebx@1 | 608 int uAllHeght; // esi@3 |
582 GUIFont *v6; // edi@1 | 609 unsigned int uStringLen; // eax@3 |
583 int v8; // esi@3 | 610 char c; // cl@4 |
584 size_t v9; // eax@3 | 611 char *test_string; // [sp+14h] [bp+Ch]@3 |
585 signed int v10; // ebx@3 | 612 |
586 unsigned __int8 v11; // cl@4 | 613 if (!pString) |
587 size_t pWindowa; // [sp+10h] [bp+8h]@3 | 614 return 0; |
588 unsigned __int8 *uX; // [sp+14h] [bp+Ch]@3 | 615 uAllHeght = this->uFontHeight - 3; |
589 | 616 test_string = FitTextInAWindow(pString, this, pWindow, uXOffset, 0); |
590 v5 = pString; | 617 uStringLen = strlen(pString); |
591 v6 = this; | 618 for (int i = 0; i < uStringLen; ++i) |
592 if ( !pString ) | 619 { |
593 return 0; | 620 c = test_string[i]; |
594 v8 = LOBYTE(this->uFontHeight) - 3; | 621 if (IsCharValid(c)) |
595 uX = (unsigned __int8 *)FitTextInAWindow(pString, this, pWindow, a4, 0); | 622 { |
596 v9 = strlen(v5); | 623 switch (c) |
597 v10 = 0; | 624 { |
598 pWindowa = v9; | 625 case '\n': //Line Feed 0A 10: |
599 while ( v10 < (signed int)pWindowa ) | 626 uAllHeght+= this->uFontHeight - 3; |
600 { | 627 break; |
601 if ( v6->IsCharValid(v11 = *uX) ) | 628 case '\f': //Form Feed, page eject 0C 12 |
602 { | 629 i += 5; |
603 if ( v11 == 9 ) | 630 break; |
604 goto LABEL_9; | 631 case '\t': // Horizontal tab 09 |
605 switch ( v11 ) | 632 case '\r': //Carriage Return 0D 13 |
606 { | 633 if (a5 != 1) |
607 case 0xAu: | 634 i += 3; |
608 v8 = v8 + LOBYTE(v6->uFontHeight) - 3; | 635 break; |
609 break; | 636 } |
610 case 0xCu: | 637 } |
611 uX += 5; | 638 } |
612 v10 += 5; | 639 return uAllHeght; |
613 break; | 640 } |
614 case 0xDu: | |
615 LABEL_9: | |
616 if ( a5 != 1 ) | |
617 { | |
618 uX += 3; | |
619 v10 += 3; | |
620 } | |
621 break; | |
622 } | |
623 } | |
624 ++v10; | |
625 ++uX; | |
626 } | |
627 return v8; | |
628 } | |
629 | 641 |
630 | 642 |
631 //----- (0044C51E) -------------------------------------------------------- | 643 //----- (0044C51E) -------------------------------------------------------- |
632 int GUIFont::GetLineWidth(const char *pString) | 644 int GUIFont::GetLineWidth(const char *pString) |
633 { | 645 { |
634 GUIFont *pFont; // edi@1 | 646 unsigned int str_len; // ebp@3 |
635 size_t pNumLen; // ebp@3 | 647 int string_line_width; // esi@3 |
636 int v5; // esi@3 | 648 unsigned char c; |
637 signed int i; // ebx@3 | 649 |
638 unsigned __int8 v7; // cl@4 | 650 if (!pString) |
639 const char *pStr; // [sp+0h] [bp-4h]@1 | 651 return 0; |
640 | 652 str_len = strlen(pString); |
641 pStr = pString; | 653 string_line_width = 0; |
642 pFont = this; | 654 for ( int i = 0; i < str_len; ++i ) |
643 if ( !pString ) // == 0 | 655 { |
644 return 0; | 656 c = pString[i]; |
645 pNumLen = strlen(pString); | 657 if (IsCharValid(c)) |
646 v5 = 0; | 658 { |
647 for ( i = 0; i < (signed int)pNumLen; ++i ) | 659 switch (c) |
648 { | 660 { |
649 if ( IsCharValid(v7 = pStr[i]) ) | 661 case '\t': |
650 { | 662 case '\n': |
651 if ( v7 < 9u ) | 663 case '\r': |
652 { | 664 return string_line_width; |
653 if ( i > 0 ) | 665 case '\f': |
654 v5 += pFont->pMetrics[v7].uLeftSpacing; | 666 i += 5; |
655 v5 += *((int *)&pFont->cFirstChar + 3 * v7 + 9); | 667 break; |
656 if ( i < (signed int)pNumLen ) | 668 default: |
657 v5 += pFont->pMetrics[v7].uRightSpacing; | 669 if (i > 0) |
658 continue; | 670 string_line_width += this->pMetrics[c].uLeftSpacing; |
659 } | 671 string_line_width += this->pMetrics[c].uWidth; |
660 if ( v7 <= 0xAu ) | 672 if (i < str_len) |
661 return v5; | 673 string_line_width +=this->pMetrics[c].uRightSpacing; |
662 if ( v7 != '\f' ) | 674 } |
663 { | 675 } |
664 if ( v7 == '\r' ) | 676 } |
665 return v5; | 677 return string_line_width; |
666 if ( i > 0 ) | 678 } |
667 v5 += pFont->pMetrics[v7].uLeftSpacing; | |
668 v5 += *((int *)&pFont->cFirstChar + 3 * v7 + 9); | |
669 if ( i < (signed int)pNumLen ) | |
670 v5 += pFont->pMetrics[v7].uRightSpacing; | |
671 continue; | |
672 } | |
673 i += 5; | |
674 } | |
675 } | |
676 return v5; | |
677 } | |
678 | |
679 | |
680 | 679 |
681 | 680 |
682 //----- (0044C502) -------------------------------------------------------- | 681 //----- (0044C502) -------------------------------------------------------- |
683 int GUIFont::AlignText_Center(unsigned int uCenterX, const char *pString) | 682 int GUIFont::AlignText_Center(unsigned int uCenterX, const char *pString) |
684 { | 683 { |
685 signed int v3; // esi@1 | 684 signed int position; // esi@1 |
686 signed int result; // eax@2 | 685 |
687 | 686 position = (signed int)(uCenterX - GetLineWidth(pString)) >> 1; |
688 v3 = (signed int)(uCenterX - GetLineWidth(pString)) >> 1; | 687 if ( position >= 0 ) |
689 if ( v3 >= 0 ) | 688 return position; |
690 result = v3; | |
691 else | 689 else |
692 result = 0; | 690 return 0; |
693 return result; | 691 |
694 } | 692 } |
695 | 693 |
696 | 694 //----- (0044C768) -------------------------------------------------------- |
697 //----- (0044C4DE) -------------------------------------------------------- | 695 char * FitTextInAWindow(const char *pInString, GUIFont *pFont, GUIWindow *pWindow, unsigned int uX, int a5) |
698 bool GUIFont::IsCharValid(char _c) | 696 { |
699 { | 697 const char *v5; // edi@1 |
700 unsigned char c = _c; | 698 GUIFont *v6; // esi@1 |
701 return c >= cFirstChar && c <= cLastChar || c == '\f' || c == '\r' || c == '\t' || c == '\n'; | 699 unsigned int v8; // eax@3 |
702 } | 700 int v9; // edi@3 |
701 unsigned __int8 v10; // cl@4 | |
702 int v11; // edx@10 | |
703 GUICharMetric *v12; // ecx@10 | |
704 int v13; // edx@11 | |
705 int v14; // edx@12 | |
706 int v15; // edx@13 | |
707 unsigned int v16; // esi@15 | |
708 unsigned int v17; // edx@15 | |
709 unsigned int v18; // ecx@15 | |
710 int v19; // ebx@16 | |
711 unsigned __int8 v20; // zf@16 | |
712 char v21; // sf@16 | |
713 unsigned __int8 v22; // of@16 | |
714 int v23; // edi@16 | |
715 unsigned __int8 v24; // dl@17 | |
716 int v25; // edi@39 | |
717 int v26; // eax@42 | |
718 std::string v27; // [sp-18h] [bp-40h]@2 | |
719 const char *v28; // [sp-8h] [bp-30h]@2 | |
720 int v29; // [sp-4h] [bp-2Ch]@2 | |
721 const char *v30; // [sp+Ch] [bp-1Ch]@1 | |
722 char Str[3]; // [sp+10h] [bp-18h]@42 | |
723 char v32; // [sp+13h] [bp-15h]@42 | |
724 size_t v33; // [sp+14h] [bp-14h]@3 | |
725 unsigned int v34; // [sp+18h] [bp-10h]@3 | |
726 GUIFont *v35; // [sp+1Ch] [bp-Ch]@1 | |
727 int v36; // [sp+20h] [bp-8h]@3 | |
728 int v37; // [sp+24h] [bp-4h]@3 | |
729 | |
730 v5 = pInString; | |
731 v6 = pFont; | |
732 v30 = pInString; | |
733 v35 = pFont; | |
734 if ( !pInString ) | |
735 { | |
736 MessageBoxW(nullptr, L"Invalid string passed !", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:445", 0); | |
737 return 0; | |
738 } | |
739 v33 = strlen(pInString); | |
740 strcpy(pTmpBuf3, v5); | |
741 v8 = uX; | |
742 v9 = 0; | |
743 v36 = 0; | |
744 v34 = uX; | |
745 v37 = 0; | |
746 if ( (signed int)v33 > 0 ) | |
747 { | |
748 while ( 1 ) | |
749 { | |
750 v10 = pTmpBuf3[v9]; | |
751 if ((v10 < v6->cFirstChar || v10 > v6->cLastChar) | |
752 && v10 != '\f' && v10 != '\r' && v10 != '\t' && v10 != '\n' ) | |
753 goto LABEL_34; | |
754 v11 = v10 - 9; | |
755 v12 = &v6->pMetrics[v10]; | |
756 if ( !v11 ) | |
757 { | |
758 strncpy(Str, &pTmpBuf3[v9 + 1], 3u); | |
759 v32 = 0; | |
760 v26 = atoi(Str); | |
761 v8 = uX + v26; | |
762 v25 = v9 + 3; | |
763 v34 = v8; | |
764 goto LABEL_43; | |
765 } | |
766 v13 = v11 - 1; | |
767 if ( !v13 ) | |
768 break; | |
769 v14 = v13 - 2; | |
770 if ( !v14 ) | |
771 { | |
772 v25 = v9 + 5; | |
773 LABEL_43: | |
774 v37 = v25; | |
775 goto LABEL_34; | |
776 } | |
777 v15 = v14 - 1; | |
778 if ( v15 ) | |
779 { | |
780 if ( v15 != 19 ) | |
781 { | |
782 v16 = v12->uRightSpacing; | |
783 v17 = v12->uWidth; | |
784 v18 = v12->uLeftSpacing; | |
785 if ( v8 + v16 + v18 + v17 < pWindow->uFrameWidth ) | |
786 { | |
787 if ( v37 > v36 ) | |
788 v8 += v18; | |
789 v8 += v17; | |
790 if ( v37 < (signed int)v33 ) | |
791 v8 += v16; | |
792 v6 = v35; | |
793 } | |
794 else | |
795 { | |
796 v19 = v36; | |
797 v8 = v34; | |
798 v22 = v36 > v37; | |
799 v20 = v36 == v37; | |
800 v21 = v36 - v37 < 0; | |
801 v6 = v35; | |
802 pTmpBuf3[v36] = 10; | |
803 v23 = v19; | |
804 if ( (unsigned __int8)(v21 ^ v22) | v20 ) | |
805 { | |
806 do | |
807 { | |
808 v24 = pTmpBuf3[v23]; | |
809 if ( v24 >= v6->cFirstChar && v24 <= v6->cLastChar || v24 == 12 || v24 == 13 || v24 == 9 || v24 == 10 ) | |
810 { | |
811 if ( v23 > v19 ) | |
812 v8 += v6->pMetrics[v24].uLeftSpacing; | |
813 v8 += *((int *)&v6->cFirstChar + 3 * v24 + 9); | |
814 if ( v23 < v37 ) | |
815 v8 += v6->pMetrics[v24].uRightSpacing; | |
816 } | |
817 ++v23; | |
818 } | |
819 while ( v23 <= v37 ); | |
820 } | |
821 } | |
822 goto LABEL_34; | |
823 } | |
824 v8 += v12->uWidth; | |
825 goto LABEL_41; | |
826 } | |
827 if ( !a5 ) | |
828 return (char *)v30; | |
829 LABEL_34: | |
830 v9 = v37++ + 1; | |
831 if ( v37 >= (signed int)v33 ) | |
832 return pTmpBuf3; | |
833 } | |
834 v8 = v34; | |
835 LABEL_41: | |
836 v36 = v9; | |
837 goto LABEL_34; | |
838 } | |
839 return pTmpBuf3; | |
840 } |