Mercurial > mm7
comparison GUIFont.cpp @ 178:1dfa65be220e
Обращённый набор изменений: 91fa025e6ca6
author | Ritor1 |
---|---|
date | Fri, 15 Feb 2013 10:41:54 +0600 |
parents | c10509e439f1 |
children | c5bd7a825ef2 |
comparison
equal
deleted
inserted
replaced
177:c10509e439f1 | 178:1dfa65be220e |
---|---|
1 #include <string> | 1 #include <string> |
2 #include "LOD.h" | 2 |
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 extern LODFile_IconsBitmaps *pIcons_LOD; | 10 |
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 } | |
51 | 24 |
52 | 25 |
53 | 26 |
54 //----- (0044D2FD) -------------------------------------------------------- | 27 //----- (0044D2FD) -------------------------------------------------------- |
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) | 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) |
292 } | 265 } |
293 // 5C6DB4: using guessed type int ui_current_text_color; | 266 // 5C6DB4: using guessed type int ui_current_text_color; |
294 | 267 |
295 | 268 |
296 //----- (0044C933) -------------------------------------------------------- | 269 //----- (0044C933) -------------------------------------------------------- |
297 char * GUIFont::_44C933(const char *pString, GUIFont *pFont, GUIFont *a3, int a4, int a5, int a6) | 270 char *__fastcall GUIFont::_44C933(const char *pString, GUIFont *pFont, GUIFont *a3, int a4, int a5, int a6) |
298 { | 271 { |
299 const char *v6; // esi@1 | 272 const char *v6; // esi@1 |
300 size_t v8; // eax@3 | 273 size_t v8; // eax@3 |
301 size_t v9; // edi@3 | 274 size_t v9; // edi@3 |
302 int v10; // eax@3 | 275 int v10; // eax@3 |
601 } | 574 } |
602 return v8; | 575 return v8; |
603 } | 576 } |
604 | 577 |
605 //----- (0044C59D) -------------------------------------------------------- | 578 //----- (0044C59D) -------------------------------------------------------- |
606 int GUIFont::CalcTextHeight(const char *pString, GUIWindow *pWindow, int uXOffset, int a5) | 579 int GUIFont::CalcTextHeight(const char *pString, GUIWindow *pWindow, int a4, int a5) |
607 { | 580 { |
608 int uAllHeght; // esi@3 | 581 const char *v5; // ebx@1 |
609 unsigned int uStringLen; // eax@3 | 582 GUIFont *v6; // edi@1 |
610 char c; // cl@4 | 583 int v8; // esi@3 |
611 char *test_string; // [sp+14h] [bp+Ch]@3 | 584 size_t v9; // eax@3 |
612 | 585 signed int v10; // ebx@3 |
613 if (!pString) | 586 unsigned __int8 v11; // cl@4 |
614 return 0; | 587 size_t pWindowa; // [sp+10h] [bp+8h]@3 |
615 uAllHeght = this->uFontHeight - 3; | 588 unsigned __int8 *uX; // [sp+14h] [bp+Ch]@3 |
616 test_string = FitTextInAWindow(pString, this, pWindow, uXOffset, 0); | 589 |
617 uStringLen = strlen(pString); | 590 v5 = pString; |
618 for (int i = 0; i < uStringLen; ++i) | 591 v6 = this; |
619 { | 592 if ( !pString ) |
620 c = test_string[i]; | 593 return 0; |
621 if (IsCharValid(c)) | 594 v8 = LOBYTE(this->uFontHeight) - 3; |
622 { | 595 uX = (unsigned __int8 *)FitTextInAWindow(pString, this, pWindow, a4, 0); |
623 switch (c) | 596 v9 = strlen(v5); |
624 { | 597 v10 = 0; |
625 case '\n': //Line Feed 0A 10: | 598 pWindowa = v9; |
626 uAllHeght+= this->uFontHeight - 3; | 599 while ( v10 < (signed int)pWindowa ) |
627 break; | 600 { |
628 case '\f': //Form Feed, page eject 0C 12 | 601 if ( v6->IsCharValid(v11 = *uX) ) |
629 i += 5; | 602 { |
630 break; | 603 if ( v11 == 9 ) |
631 case '\t': // Horizontal tab 09 | 604 goto LABEL_9; |
632 case '\r': //Carriage Return 0D 13 | 605 switch ( v11 ) |
633 if (a5 != 1) | 606 { |
634 i += 3; | 607 case 0xAu: |
635 break; | 608 v8 = v8 + LOBYTE(v6->uFontHeight) - 3; |
636 } | 609 break; |
637 } | 610 case 0xCu: |
638 } | 611 uX += 5; |
639 return uAllHeght; | 612 v10 += 5; |
640 } | 613 break; |
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 } | |
641 | 629 |
642 | 630 |
643 //----- (0044C51E) -------------------------------------------------------- | 631 //----- (0044C51E) -------------------------------------------------------- |
644 int GUIFont::GetLineWidth(const char *pString) | 632 int GUIFont::GetLineWidth(const char *pString) |
645 { | 633 { |
646 unsigned int str_len; // ebp@3 | 634 GUIFont *pFont; // edi@1 |
647 int string_line_width; // esi@3 | 635 size_t pNumLen; // ebp@3 |
648 unsigned char c; | 636 int v5; // esi@3 |
649 | 637 signed int i; // ebx@3 |
650 if (!pString) | 638 unsigned __int8 v7; // cl@4 |
651 return 0; | 639 const char *pStr; // [sp+0h] [bp-4h]@1 |
652 str_len = strlen(pString); | 640 |
653 string_line_width = 0; | 641 pStr = pString; |
654 for ( int i = 0; i < str_len; ++i ) | 642 pFont = this; |
655 { | 643 if ( !pString ) // == 0 |
656 c = pString[i]; | 644 return 0; |
657 if (IsCharValid(c)) | 645 pNumLen = strlen(pString); |
658 { | 646 v5 = 0; |
659 switch (c) | 647 for ( i = 0; i < (signed int)pNumLen; ++i ) |
660 { | 648 { |
661 case '\t': | 649 if ( IsCharValid(v7 = pStr[i]) ) |
662 case '\n': | 650 { |
663 case '\r': | 651 if ( v7 < 9u ) |
664 return string_line_width; | 652 { |
665 case '\f': | 653 if ( i > 0 ) |
666 i += 5; | 654 v5 += pFont->pMetrics[v7].uLeftSpacing; |
667 break; | 655 v5 += *((int *)&pFont->cFirstChar + 3 * v7 + 9); |
668 default: | 656 if ( i < (signed int)pNumLen ) |
669 if (i > 0) | 657 v5 += pFont->pMetrics[v7].uRightSpacing; |
670 string_line_width += this->pMetrics[c].uLeftSpacing; | 658 continue; |
671 string_line_width += this->pMetrics[c].uWidth; | 659 } |
672 if (i < str_len) | 660 if ( v7 <= 0xAu ) |
673 string_line_width +=this->pMetrics[c].uRightSpacing; | 661 return v5; |
674 } | 662 if ( v7 != '\f' ) |
675 } | 663 { |
676 } | 664 if ( v7 == '\r' ) |
677 return string_line_width; | 665 return v5; |
678 } | 666 if ( i > 0 ) |
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 | |
679 | 680 |
680 | 681 |
681 //----- (0044C502) -------------------------------------------------------- | 682 //----- (0044C502) -------------------------------------------------------- |
682 int GUIFont::AlignText_Center(unsigned int uCenterX, const char *pString) | 683 int GUIFont::AlignText_Center(unsigned int uCenterX, const char *pString) |
683 { | 684 { |
684 signed int position; // esi@1 | 685 signed int v3; // esi@1 |
685 | 686 signed int result; // eax@2 |
686 position = (signed int)(uCenterX - GetLineWidth(pString)) >> 1; | 687 |
687 if ( position >= 0 ) | 688 v3 = (signed int)(uCenterX - GetLineWidth(pString)) >> 1; |
688 return position; | 689 if ( v3 >= 0 ) |
690 result = v3; | |
689 else | 691 else |
690 return 0; | 692 result = 0; |
691 | 693 return result; |
692 } | 694 } |
693 | 695 |
694 //----- (0044C768) -------------------------------------------------------- | 696 |
695 char * FitTextInAWindow(const char *pInString, GUIFont *pFont, GUIWindow *pWindow, unsigned int uX, int a5) | 697 //----- (0044C4DE) -------------------------------------------------------- |
696 { | 698 bool GUIFont::IsCharValid(char _c) |
697 const char *v5; // edi@1 | 699 { |
698 GUIFont *v6; // esi@1 | 700 unsigned char c = _c; |
699 unsigned int v8; // eax@3 | 701 return c >= cFirstChar && c <= cLastChar || c == '\f' || c == '\r' || c == '\t' || c == '\n'; |
700 int v9; // edi@3 | 702 } |
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 } |