Mercurial > mm7
diff GUIFont.cpp @ 1160:502b8b2e36b4
font cleaning
author | Gloval |
---|---|
date | Tue, 04 Jun 2013 01:37:23 +0400 |
parents | c0bfb386b15f |
children | 29a8defbad9e |
line wrap: on
line diff
--- a/GUIFont.cpp Sun Jun 02 22:16:58 2013 +0400 +++ b/GUIFont.cpp Tue Jun 04 01:37:23 2013 +0400 @@ -27,38 +27,42 @@ char pTmpBuf3[10000]; +void DrawCharToBuff(unsigned short* uXpos,unsigned char* pCharPixels, int uCharWidth, int uCharHeight, unsigned __int16* pFontPalette, __int16 draw_color, int line_width); + + //----- (0044C448) -------------------------------------------------------- GUIFont *LoadFont(const char *pFontFile, const char *pFontPalette, ...) -{ - - int pallete_index; // eax@3 - GUIFont *pFont; - unsigned int palletes_count =0; - va_list palettes_ptr; +{ + int pallete_index; // eax@3 + GUIFont *pFont; + unsigned int palletes_count =0; + va_list palettes_ptr; - pFont = (GUIFont *)pIcons_LOD->LoadRaw(pFontFile, 0); - va_start(palettes_ptr, pFontFile); + pFont = (GUIFont *)pIcons_LOD->LoadRaw(pFontFile, 0); + va_start(palettes_ptr, pFontFile); - while (NULL!=(pFontPalette=va_arg(palettes_ptr, const char *))) - { - pallete_index =pIcons_LOD->LoadTexture(pFontPalette, TEXTURE_16BIT_PALETTE); - if (pallete_index == -1) - { - wsprintfA(pTmpBuf, "Unable to open %s", pFontPalette); - Abortf(pTmpBuf); - } - pFont->pFontPalettes[palletes_count] = pIcons_LOD->pTextures[pallete_index].pPalette16; - ++palletes_count; - } - va_end(palettes_ptr); - pFont->palletes_count = palletes_count; - return pFont; - } + while (NULL!=(pFontPalette=va_arg(palettes_ptr, const char *))) + { + pallete_index =pIcons_LOD->LoadTexture(pFontPalette, TEXTURE_16BIT_PALETTE); + if (pallete_index == -1) + { + wsprintfA(pTmpBuf, "Unable to open %s", pFontPalette); + Abortf(pTmpBuf); + } + pFont->pFontPalettes[palletes_count] = pIcons_LOD->pTextures[pallete_index].pPalette16; + ++palletes_count; + } + va_end(palettes_ptr); + pFont->palletes_count = palletes_count; + return pFont; +} //----- (0044D2FD) -------------------------------------------------------- -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) +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) { int v11; // ebx@1 int v12; // edi@1 @@ -114,7 +118,7 @@ v18 = (signed int)(w - v16->GetLineWidth(&v14[v17])) >> 1; if ( v18 < 0 ) v18 = 0; - v16->_44D0B5(a4a, a8, (int)&v15[v18 + a7a], Stra, uPixelsWidth); + v16->DrawTextLineToBuff(a4a, a8, &v15[v18 + a7a], Stra, uPixelsWidth); v15 += uPixelsWidth * (LOBYTE(v16->uFontHeight) - 3); Stra = strtok(0, "\n"); if ( !Stra ) @@ -127,176 +131,151 @@ //----- (0044D1E7) -------------------------------------------------------- -void GUIFont::DrawTextLine(unsigned int uDefaultColor, signed int uX, signed int uY, const char *Str, int a6) +void GUIFont::DrawTextLine( unsigned int uDefaultColor, signed int uX, signed int uY, + const char *text, int max_len_pix ) { - size_t v6; // ebx@1 - GUIFont *pFont; // esi@1 - signed int v8; // edi@3 - unsigned __int8 v9; // cl@4 - int v10; // eax@5 - int v11; // ecx@5 - int v12; // ecx@6 - int v13; // ecx@7 - int v14; // ecx@9 - unsigned int v15; // edx@9 - unsigned __int16 v16; // cx@12 - unsigned __int8 *v17; // eax@12 - char Dest[20]; // [sp+Ch] [bp-1Ch]@16 - //char v19; // [sp+11h] [bp-17h]@16 - size_t v20; // [sp+20h] [bp-8h]@2 - int v21; // [sp+24h] [bp-4h]@1 - int uXa; // [sp+30h] [bp+8h]@9 + signed int uX_pos; // edi@3 + unsigned char c; // cl@4 + unsigned __int16 draw_color; // cx@12 + unsigned __int8 *pCharPixels; // eax@12 + char color_code[20]; // [sp+Ch] [bp-1Ch]@16 + int text_length; // [sp+20h] [bp-8h]@2 + int text_color; // [sp+24h] [bp-4h]@1 + int uCharWidth; // [sp+30h] [bp+8h]@9 - v6 = 0; - v21 = uDefaultColor; - pFont = this; - if ( Str ) - { - v21 = ui_current_text_color; - v20 = strlen(Str); - if ( (signed int)v20 > 0 ) - { - v8 = uX; - do - { - if ( pFont->IsCharValid(v9 = Str[v6]) ) + if ( !text ) + return; + text_color = ui_current_text_color; + text_length = strlen(text); + uX_pos=uX; + for (int i=0; i<text_length; ++i ) { - v10 = v9; - v11 = v9 - 9; - if ( v11 ) - { - v12 = v11 - 1; - if ( !v12 ) - return; - v13 = v12 - 2; - if ( v13 ) + c = text[i]; + if ( IsCharValid(c) ) { - if ( v13 != 1 ) - { - v14 = 3 * v10 + 9; - v15 = *((int *)&pFont->cFirstChar + v14); - uXa = *((int *)&pFont->cFirstChar + v14); - if ( v15 ) + switch (c) { - if ( (signed int)v6 > 0 ) - v8 += pFont->pMetrics[v10].uLeftSpacing; - v16 = v21; - v17 = (unsigned __int8 *)((char *)&pFont[1] + pFont->field_C20[v10]); - if ( !v21 ) - v16 = -1; - pRenderer->DrawText(v8, uY, v17, v15, pFont->uFontHeight, pFont->pFontPalettes[0], v16, 0); - v8 += uXa; - if ( (signed int)v6 < (signed int)v20 ) - v8 += pFont->pMetrics[(unsigned __int8)Str[v6]].uRightSpacing; + case '\n': //Line Feed 0A 10: + return; + break; + case '\f': //Form Feed, page eject 0C 12 + strncpy(color_code, &text[i + 1], 5); + color_code[5] = 0; + text_color = atoi(color_code); + ui_current_text_color = text_color; + i += 5; + break; + case '\t': // Horizontal tab 09 + case '\r': //Carriage Return 0D 13 + break; + default: + uCharWidth = pMetrics[c].uWidth; + if ( uCharWidth ) + { + if ( i > 0 ) + uX_pos += pMetrics[c].uLeftSpacing; + draw_color = text_color; + pCharPixels = &pFontData[font_pixels_offset[c]]; + if ( !text_color ) + draw_color = -1; + pRenderer->DrawText(uX_pos, uY, pCharPixels, uCharWidth, uFontHeight, pFontPalettes[0], draw_color, 0); + uX_pos += uCharWidth; + if ( i < text_length ) + uX_pos += pMetrics[c].uRightSpacing; + } } - } } - else + } + +} + +//----- (0040F845) -------------------------------------------------------- +void DrawCharToBuff( unsigned short* uXpos,unsigned char* pCharPixels, int uCharWidth, int uCharHeight, + unsigned __int16* pFontPalette, __int16 draw_color, int line_width ) + { + unsigned __int16* draw_buff; // edi@1 + unsigned char* pPixels; // esi@1 + unsigned char char_pxl; // eax@3 + + draw_buff = uXpos; + pPixels = pCharPixels; + for(int i=0; i<uCharHeight; ++i) + { + for(int j=0; j<uCharWidth; ++j) { - strncpy(Dest, &Str[v6 + 1], 5u); - Dest[5] = 0; - v21 = atoi(Dest); - ui_current_text_color = v21; - v6 += 5; + char_pxl = *pPixels++; + if ( char_pxl ) + { + if ( char_pxl == 1 ) + *draw_buff = pFontPalette[1]; + else + *draw_buff = draw_color; + } + ++draw_buff; } - } + draw_buff+=line_width-uCharWidth; } - ++v6; - } - while ( (signed int)v6 < (signed int)v20 ); - } - } + } -// 5C6DB4: using guessed type int ui_current_text_color; - //----- (0044D0B5) -------------------------------------------------------- -void GUIFont::_44D0B5(int a2, int a3, int a4, const char *pString, int a6) -{ - int v6; // ebx@1 - GUIFont *v7; // esi@1 - int v8; // edi@3 - unsigned __int8 v9; // cl@4 - int v10; // eax@5 - int v11; // ecx@5 - int v12; // ecx@6 - int v13; // ecx@7 - int v14; // ecx@8 - int v15; // ebx@10 - int v16; // edx@13 - __int16 v17; // ax@13 - char Dest; // [sp+Ch] [bp-20h]@17 - char v19; // [sp+11h] [bp-1Bh]@17 - size_t v20; // [sp+20h] [bp-Ch]@2 - int v21; // [sp+24h] [bp-8h]@1 - int v22; // [sp+28h] [bp-4h]@2 - const char *v23; // [sp+38h] [bp+Ch]@4 +void GUIFont::DrawTextLineToBuff( int uColor, int a3, unsigned short* uX_buff_pos, const char *text, int line_width ) + { + + unsigned short* uX_pos; // edi@3 + unsigned char c; // cl@4 + unsigned __int16 draw_color; // cx@12 + unsigned __int8 *pCharPixels; // eax@12 + char color_code[20]; // [sp+Ch] [bp-1Ch]@16 + int text_length; // [sp+20h] [bp-8h]@2 + int text_color; // [sp+24h] [bp-4h]@1 + int uCharWidth; // [sp+30h] [bp+8h]@9 - v6 = 0; - v21 = a2; - v7 = this; - if ( pString ) - { - v21 = ui_current_text_color; - v20 = strlen(pString); - v22 = 0; - if ( (signed int)v20 > 0 ) - { - v8 = a4; - do + if ( !text ) + return; + text_color = ui_current_text_color; + text_length = strlen(text); + uX_pos=uX_buff_pos; + for (int i=0; i<text_length; ++i ) { - v23 = &pString[v6]; - if ( v7->IsCharValid(v9 = pString[v6]) ) - { - v10 = v9; - v11 = v9 - 9; - if ( v11 ) + c = text[i]; + if ( IsCharValid(c) ) { - v12 = v11 - 1; - if ( !v12 ) + switch (c) + { + case '\n': //Line Feed 0A 10: return; - v13 = v12 - 2; - if ( v13 ) - { - v14 = v13 - 1; - if ( v14 ) - { - if ( v14 != 82 ) - { - v15 = *((int *)&v7->cFirstChar + 3 * v10 + 9); - if ( v15 ) + break; + case '\f': //Form Feed, page eject 0C 12 + strncpy(color_code, &text[i + 1], 5); + color_code[5] = 0; + text_color = atoi(color_code); + ui_current_text_color = text_color; + i += 5; + break; + case '\t': // Horizontal tab 09 + case '\r': //Carriage Return 0D 13 + break; + default: + uCharWidth = pMetrics[c].uWidth; + if ( uCharWidth ) { - if ( v22 > 0 ) - v8 += 2 * v7->pMetrics[v10].uLeftSpacing; - v16 = (int)((char *)&v7[1] + v7->field_C20[v10]); - v17 = v21; - if ( !v21 ) - v17 = -1; - sub_40F845(v8, v16, v15, LOBYTE(v7->uFontHeight), (int)v7->pFontPalettes[0], v17, 2 * a6); - v8 += 2 * v15; - if ( v22 < (signed int)v20 ) - v8 += 2 * v7->pMetrics[(unsigned __int8)*v23].uRightSpacing; + if ( i > 0 ) + uX_pos += pMetrics[c].uLeftSpacing; + draw_color = text_color; + pCharPixels = &pFontData[font_pixels_offset[c]]; + if ( !text_color ) + draw_color = -1; + DrawCharToBuff(uX_pos, pCharPixels, uCharWidth, uFontHeight, pFontPalettes[0], draw_color, line_width); + uX_pos += uCharWidth; + if ( i < text_length ) + uX_pos += pMetrics[c].uRightSpacing; } - } } - } - else - { - strncpy(&Dest, &pString[v6 + 1], 5u); - v19 = 0; - v21 = atoi(&Dest); - ui_current_text_color = v21; - v22 = v6 + 5; - } } - } - v6 = v22++ + 1; } - while ( v22 < (signed int)v20 ); - } - } } -// 5C6DB4: using guessed type int ui_current_text_color; + //----- (0044C933) -------------------------------------------------------- @@ -490,71 +469,46 @@ //----- (0044C6C2) -------------------------------------------------------- -int GUIFont::_44C6C2(const char *pInString, GUIWindow *pWindow, unsigned int uX, int a5) -{ - const char *v5; // esi@1 - int v6; // edi@1 - unsigned __int8 *v8; // ebx@3 - size_t v9; // eax@3 - signed int v10; // esi@3 - int v11; // edx@4 - unsigned int v12; // cl@4 - GUIFont *v13; // [sp+Ch] [bp-4h]@1 - size_t uXa; // [sp+1Ch] [bp+Ch]@3 +char* GUIFont::_44C6C2( const char *pInString, GUIWindow *pWindow, unsigned int uX, int a5 ) + { + int text_height; // edi@1 + char *text_str; // ebx@3 + int i; + unsigned char c; // cl@4 + int text_length; - auto pFont = this; - v5 = pInString; - v6 = 0; - v13 = pFont; + text_height = 0; + if ( !pInString ) return 0; - v8 = (unsigned __int8 *)FitTextInAWindow(pInString, pFont, pWindow, uX, 0); - v9 = strlen(v5); - v10 = 0; - uXa = v9; - if ( (signed int)v9 > 0 ) - { - while ( v10 < (signed int)uXa ) - { - if(IsCharValid(*v8)) - { - v12=(unsigned int)v8; - if ( v12 != 9 ) - { - if ( v12 == 10 ) - { - v6 = v6 + *(char *)(v11 + 5) - 3; - if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) ) - return (int)(v8 + 1); - if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) ) - return (int)v8; - } - else if ( v12 == 12 ) - { - v8 += 5; - v10 += 5; - if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) ) - return (int)v8; - } - else if ( v12 != 13 ) - { - if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) ) - return (int)v8; - } - } - if(v12 == 13 || v12 == 9) - { - v8 += 3; - v10 += 3; - } - if ( v6 >= (signed int)(a5 * pWindow->uFrameHeight) ) - return (int)v8; - } - ++v10; - ++v8; - } - } - return (int)v8; + text_str = FitTextInAWindow(pInString, this, pWindow, uX, 0); + text_length = strlen(text_str); + //uX_pos=uX_buff_pos; + for (i=0; i<text_length; ++i ) + { + c = text_str[i]; + if ( IsCharValid(c) ) + { + switch (c) + { + case '\n': //Line Feed 0A 10: + text_height = text_height + uFontHeight - 3; + if ( text_height >= (signed int)(a5 * pWindow->uFrameHeight) ) + return &text_str[i+1]; + break; + case '\f': //Form Feed, page eject 0C 12 + i += 5; + break; + case '\t': // Horizontal tab 09 + case '\r': //Carriage Return 0D 13 + i += 3; + break; + } + if ( text_height >= (signed int)(a5 * pWindow->uFrameHeight) ) + return &text_str[i]; + } + } + return &text_str[i]; } @@ -611,11 +565,11 @@ } //----- (0044C59D) -------------------------------------------------------- -int GUIFont::CalcTextHeight(const char *pString, GUIWindow *pWindow, int uXOffset, int a5) - { +int GUIFont::CalcTextHeight( const char *pString, struct GUIWindow *pWindow, int uXOffset, int a5 ) + { int uAllHeght; - unsigned int uStringLen; - char c; + int uStringLen; + unsigned char c; char *test_string; if (!pString) @@ -651,7 +605,7 @@ //----- (0044C51E) -------------------------------------------------------- int GUIFont::GetLineWidth(const char *pString) { - unsigned int str_len; // ebp@3 + int str_len; // ebp@3 int string_line_width; // esi@3 unsigned char c; @@ -703,7 +657,7 @@ char * FitTextInAWindow( const char *pInString, GUIFont *pFont, GUIWindow *pWindow, signed int uX, int a5 ) { unsigned char c; - unsigned int uInStrLen; + int uInStrLen; char digits[4]; int possible_transition_point; int string_pixel_Width;