changeset 2529:dbaf6fc71525

GUIWindow::DrawText: cleaned
author a.parshin
date Mon, 13 Oct 2014 17:18:55 +0300
parents e72e62ec9273
children dc6f29bb0ec4
files GUI/GUIWindow.cpp GUI/GUIWindow.h
diffstat 2 files changed, 52 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/GUI/GUIWindow.cpp	Mon Oct 13 16:14:07 2014 +0300
+++ b/GUI/GUIWindow.cpp	Mon Oct 13 17:18:55 2014 +0300
@@ -1071,27 +1071,14 @@
 // 5C6DB4: using guessed type int ui_current_text_color;
 
 //----- (0044CE08) --------------------------------------------------------
-void GUIWindow::DrawText(GUIFont *a2, signed int uX, int uY, unsigned int uFontColor, const char *Str, int a7, int max_text_height, signed int uFontShadowColor )
+void GUIWindow::DrawText(GUIFont *font, signed int uX, int uY, unsigned short uFontColor, const char *Str, bool present_time_transparency, int max_text_height, signed int uFontShadowColor )
     {
-  GUIFont *v10; // ebx@1
-  signed int v12; // esi@9
-  signed int v13; // edi@9
   int v14; // edx@9
-  int v15; // eax@25
-  unsigned int v16; // ecx@25
-  int v17; // eax@27v21
   int v18; // edi@32
-  int v19; // esi@38
   char Dest[6]; // [sp+Ch] [bp-2Ch]@32
-  const char *v27; // [sp+20h] [bp-18h]@25
-  int v28; // [sp+24h] [bp-14h]@25
-  int v29; // [sp+28h] [bp-10h]@1
   size_t v30; // [sp+2Ch] [bp-Ch]@4
-  const char *v32; // [sp+34h] [bp-4h]@7
-  size_t pInString; // [sp+4Ch] [bp+14h]@11
 
-  v29 = 0;
-  v10 = a2;
+  int left_margin = 0;
   if ( !Str )
   {
     MessageBoxW(nullptr, L"Invalid string passed!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:859", 0);
@@ -1105,98 +1092,94 @@
     if ( !uX )
       uX = 12;
 
+   const char *string_begin = Str;
     if ( max_text_height != 0 )
-      v32 = Str;
-    else
-      v32 = FitTextInAWindow(Str, v10, this, uX, 0);
+      string_begin = FitTextInAWindow(Str, font, this, uX, 0);
+   auto string_end = string_begin;
+   auto string_base = string_begin;
 
-    v12 = uX + uFrameX;
-    v13 = uY + uFrameY;
+    int out_x = uX + uFrameX;
+    int out_y = uY + uFrameY;
     v14 = 0;
 
-    if (max_text_height != 0 && v13 + LOBYTE(v10->uFontHeight) > max_text_height)
+    if (max_text_height != 0 && out_y + LOBYTE(font->uFontHeight) > max_text_height)
       return;
 
-      pInString = 0;
       if ( (signed int)v30 > 0 )
       {
         do
         {
-          unsigned char c = v32[v14];
-          if ( c >= v10->cFirstChar && c <= v10->cLastChar
-            || c == 12
-            || c == 13
-            || c == 9
-            || c == 10 )
+          unsigned char c = string_base[v14];
+          if ( c >= font->cFirstChar && c <= font->cLastChar
+            || c == '\f'
+            || c == '\r'
+            || c == '\t'
+            || c == '\n' )
           {
             switch ( c )
             {
-              case 9u:
-                strncpy(Dest, &v32[v14 + 1], 3);
+              case '\t':
+                strncpy(Dest, &string_base[v14 + 1], 3);
                 Dest[3] = 0;
-                pInString += 3;
-                v29 = atoi(Dest);
-                v19 = atoi(Dest);
-                v12 = uX + uFrameX + v19;
+                v14 += 3;
+                left_margin = atoi(Dest);
+                out_x = uX + uFrameX + left_margin;
                 break;
-              case 0xAu:
-                uY = uY + LOBYTE(v10->uFontHeight) - 3;
-                v13 = uY + uFrameY;
-                v12 = uX + v29 + uFrameX;
+              case '\n':
+                uY = uY + LOBYTE(font->uFontHeight) - 3;
+                out_y = uY + uFrameY;
+                out_x = uX + uFrameX + left_margin;
                 if ( max_text_height != 0 )
                 {
-                  if (LOBYTE(v10->uFontHeight) + v13 - 3 > max_text_height )
+                  if (LOBYTE(font->uFontHeight) + out_y - 3 > max_text_height )
                     return;
                 }
                 break;
-              case 0xCu:
-                strncpy(Dest, &v32[v14 + 1], 5);
+              case '\f':
+                strncpy(Dest, &string_base[v14 + 1], 5);
                 Dest[5] = 0;
                 uFontColor = atoi(Dest);
-                pInString += 5;
+                v14 += 5;
                 break;
-              case 0xDu:
-                strncpy(Dest, &v32[v14 + 1], 3);
+              case '\r':
+                strncpy(Dest, &string_base[v14 + 1], 3);
                 Dest[3] = 0;
-                pInString += 3;
+                v14 += 3;
                 v18 = atoi(Dest);
-                v12 = uFrameZ - v10->GetLineWidth(&v32[pInString]) - v18;
-                v13 = uY + uFrameY;
+                out_x = uFrameZ - font->GetLineWidth(&string_base[v14]) - v18;
+                out_y = uY + uFrameY;
                 if ( max_text_height != 0 )
                 {
-                  if (LOBYTE(v10->uFontHeight) + v13 - 3 > max_text_height )
+                  if (LOBYTE(font->uFontHeight) + out_y - 3 > max_text_height )
                     return;
                   break;
                 }
                 break;
+
               default:
-                if (c == 34 && v32[v14 + 1] == 34 )
-                {
+                if (c == '\"' && string_base[v14 + 1] == '\"')
                   ++v14;
-                  pInString = v14;
-                }
-                v27 = &v32[v14];
-                v15 = (unsigned __int8)v32[v14];
-                v16 = *((int *)&v10->cFirstChar + 3 * v15 + 9);
-                v28 = *((int *)&v10->cFirstChar + 3 * v15 + 9);
+                
+                c = (unsigned __int8)string_base[v14];
                 if ( v14 > 0 )
-                  v12 += v10->pMetrics[v15].uLeftSpacing;
-                v17 = (int)((char *)&v10[1] + v10->font_pixels_offset[v15]);
-                if ( (short)uFontColor )
-                  pRenderer->DrawText(v12, v13, (unsigned __int8 *)v17, v16, LOBYTE(v10->uFontHeight),
-                    v10->pFontPalettes[0], uFontColor, uFontShadowColor);
+                  out_x += font->pMetrics[c].uLeftSpacing;
+
+                unsigned char *letter_pixels = &font->pFontData[font->font_pixels_offset[c]];
+                if ( uFontColor )
+                  pRenderer->DrawText(out_x, out_y, letter_pixels, font->pMetrics[c].uWidth, LOBYTE(font->uFontHeight),
+                    font->pFontPalettes[0], uFontColor, uFontShadowColor);
                 else
-                  pRenderer->DrawTextAlpha(v12, v13, (unsigned char*)v17, v16, LOBYTE(v10->uFontHeight),
-                    v10->pFontPalettes[0], a7);
-                v12 += v28;
-                if ( (signed int)pInString < (signed int)v30 )
-                  v12 += v10->pMetrics[(unsigned __int8)*v27].uRightSpacing;
+                  pRenderer->DrawTextAlpha(out_x, out_y, letter_pixels, font->pMetrics[c].uWidth, LOBYTE(font->uFontHeight),
+                    font->pFontPalettes[0], present_time_transparency);
+
+                out_x += font->pMetrics[c].uWidth;
+                if ( (signed int)v14 < (signed int)v30 )
+                  out_x += font->pMetrics[c].uRightSpacing;
                 break;
             }
           }
-          v14 = pInString++ + 1;
         }
-        while ( (signed int)pInString < (signed int)v30 );
+        while ( (signed int)++v14 < (signed int)v30 );
       }
 }
 
--- a/GUI/GUIWindow.h	Mon Oct 13 16:14:07 2014 +0300
+++ b/GUI/GUIWindow.h	Mon Oct 13 17:18:55 2014 +0300
@@ -340,7 +340,7 @@
 	                      UIMessageType msg, unsigned int msg_param, unsigned __int8 uHotkey, const char *pName, struct Texture *pTextures, ...);
   void DrawFlashingInputCursor(signed int uX, int uY, struct GUIFont *a2);
   int DrawTextInRect(GUIFont *pFont, unsigned int uX, unsigned int uY, unsigned int uColor, const char *text, int rect_width, int reverse_text);
-  void DrawText(GUIFont *a2, signed int uX, int uY, unsigned int uFontColor, const char *Str, int a7, int max_text_height, signed int uFontShadowColor);
+  void DrawText(GUIFont *a2, signed int uX, int uY, unsigned short uFontColor, const char *Str, bool present_time_transparency, int max_text_height, signed int uFontShadowColor);
   void DrawTitleText(GUIFont *a2, signed int uHorizontalMargin, unsigned int uVerticalMargin, unsigned __int16 uDefaultColor, const char *pInString, unsigned int uLineSpacing);
   void DrawShops_next_generation_time_string(__int64 next_generation_time);
   void HouseDialogManager();