changeset 2528:e72e62ec9273

GUIWindow::DrawText: some cleanings
author a.parshin
date Mon, 13 Oct 2014 16:14:07 +0300
parents 8f12e6a1fcc2
children dbaf6fc71525
files Engine/Game.cpp GUI/GUIWindow.cpp GUI/GUIWindow.h
diffstat 3 files changed, 41 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/Engine/Game.cpp	Mon Oct 13 14:58:54 2014 +0300
+++ b/Engine/Game.cpp	Mon Oct 13 16:14:07 2014 +0300
@@ -248,10 +248,10 @@
     {
       int sector_id = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
       sprintf(pTmpBuf.data(), "Party Sector ID:        %u/%u\n", sector_id, pIndoor->uNumSectors);
-      pPrimaryWindow->DrawText(pFontArrus, 16, 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, -1);
+      pPrimaryWindow->DrawText(pFontArrus, 16, 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, Color16(255, 255, 255));
     }
     sprintf(pTmpBuf.data(), "Party Position:         % d % d % d", pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
-    pPrimaryWindow->DrawText(pFontArrus, 16, 16 + 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, -1);
+    pPrimaryWindow->DrawText(pFontArrus, 16, 16 + 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, Color16(255, 255, 255));
   
     if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
     {
@@ -266,7 +266,7 @@
       int floor_level = ODM_GetFloorLevel(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z, 0, &on_water, &_a6, false);
       sprintf(pTmpBuf.data(), "ODM_GetFloorLevel: %d   on_water: %s    a6 = %d\n", floor_level, on_water ? "true" : "false", _a6);
     }
-    pPrimaryWindow->DrawText(pFontArrus, 16, 16 + 16 + 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, -1);
+    pPrimaryWindow->DrawText(pFontArrus, 16, 16 + 16 + 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, Color16(255, 255, 255));
   }
 
   GUI_UpdateWindows();
--- a/GUI/GUIWindow.cpp	Mon Oct 13 14:58:54 2014 +0300
+++ b/GUI/GUIWindow.cpp	Mon Oct 13 16:14:07 2014 +0300
@@ -1071,75 +1071,65 @@
 // 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 a8, signed int uFontShadowColor )
+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 )
     {
-  GUIWindow *v9; // edi@1
   GUIFont *v10; // ebx@1
-  int v11; // eax@2
   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@27
+  int v17; // eax@27v21
   int v18; // edi@32
   int v19; // esi@38
-  std::string v21; // [sp-18h] [bp-50h]@2
-//  const char *v22; // [sp-8h] [bp-40h]@2
-//  int v23; // [sp-4h] [bp-3Ch]@2
   char Dest[6]; // [sp+Ch] [bp-2Ch]@32
-  //char v25; // [sp+Fh] [bp-29h]@32
-  //char v26; // [sp+11h] [bp-27h]@34
   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
-  GUIWindow *v31; // [sp+30h] [bp-8h]@1
   const char *v32; // [sp+34h] [bp-4h]@7
   size_t pInString; // [sp+4Ch] [bp+14h]@11
-  
-  GUIWindow* a1 = this;
+
   v29 = 0;
-  v9 = a1;
   v10 = a2;
-  v31 = a1;
   if ( !Str )
   {
     MessageBoxW(nullptr, L"Invalid string passed!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:859", 0);
     return;
   }
-  v11 = strcmp(Str, "null");
-  if ( v11 )
-  {
+  if (!strcmp(Str, "null"))
+    return;
+
     v30 = strlen(Str);
-    LOBYTE(v11) = 0;
+    //int v11 = 0;
     if ( !uX )
       uX = 12;
-    if ( a8 )
+
+    if ( max_text_height != 0 )
       v32 = Str;
     else
-    {
-      v11 = (int)FitTextInAWindow(Str, v10, v9, uX, 0);
-      v32 = (const char *)v11;
-    }
-    v12 = uX + v9->uFrameX;
-    v13 = uY + v9->uFrameY;
+      v32 = FitTextInAWindow(Str, v10, this, uX, 0);
+
+    v12 = uX + uFrameX;
+    v13 = uY + uFrameY;
     v14 = 0;
-    if ( !a8 || (v11 = v13 + LOBYTE(v10->uFontHeight), v11 <= a8) )
-    {
+
+    if (max_text_height != 0 && v13 + LOBYTE(v10->uFontHeight) > max_text_height)
+      return;
+
       pInString = 0;
       if ( (signed int)v30 > 0 )
       {
         do
         {
-          LOBYTE(v11) = v32[v14];
-          if ( (unsigned __int8)v11 >= v10->cFirstChar && (unsigned __int8)v11 <= v10->cLastChar
-            || (char)v11 == 12
-            || (char)v11 == 13
-            || (char)v11 == 9
-            || (char)v11 == 10 )
+          unsigned char c = v32[v14];
+          if ( c >= v10->cFirstChar && c <= v10->cLastChar
+            || c == 12
+            || c == 13
+            || c == 9
+            || c == 10 )
           {
-            switch ( (unsigned __int8)v11 )
+            switch ( c )
             {
               case 9u:
                 strncpy(Dest, &v32[v14 + 1], 3);
@@ -1147,47 +1137,40 @@
                 pInString += 3;
                 v29 = atoi(Dest);
                 v19 = atoi(Dest);
-                LOBYTE(v11) = (char)v31;
-                v12 = uX + v31->uFrameX + v19;
+                v12 = uX + uFrameX + v19;
                 break;
               case 0xAu:
-                v11 = LOBYTE(v10->uFontHeight);
-                uY = uY + v11 - 3;
-                v13 = uY + v31->uFrameY;
-                v12 = uX + v29 + v31->uFrameX;
-                if ( a8 )
+                uY = uY + LOBYTE(v10->uFontHeight) - 3;
+                v13 = uY + uFrameY;
+                v12 = uX + v29 + uFrameX;
+                if ( max_text_height != 0 )
                 {
-                  v11 = v11 + v13 - 3;
-                  if ( v11 > a8 )
+                  if (LOBYTE(v10->uFontHeight) + v13 - 3 > max_text_height )
                     return;
                 }
                 break;
               case 0xCu:
                 strncpy(Dest, &v32[v14 + 1], 5);
                 Dest[5] = 0;
-                v11 = atoi(Dest);
+                uFontColor = atoi(Dest);
                 pInString += 5;
-                uFontColor = v11;
                 break;
               case 0xDu:
                 strncpy(Dest, &v32[v14 + 1], 3);
                 Dest[3] = 0;
                 pInString += 3;
                 v18 = atoi(Dest);
-                v11 = v10->GetLineWidth(&v32[pInString]);
-                v12 = v31->uFrameZ - v11 - v18;
-                v13 = uY + v31->uFrameY;
-                if ( a8 )
+                v12 = uFrameZ - v10->GetLineWidth(&v32[pInString]) - v18;
+                v13 = uY + uFrameY;
+                if ( max_text_height != 0 )
                 {
-                  v11 = LOBYTE(v10->uFontHeight);
-                  v11 = v11 + v13 - 3;
-                  if ( v11 > a8 )
+                  if (LOBYTE(v10->uFontHeight) + v13 - 3 > max_text_height )
                     return;
                   break;
                 }
                 break;
               default:
-                if ( (char)v11 == 34 && v32[v14 + 1] == 34 )
+                if (c == 34 && v32[v14 + 1] == 34 )
                 {
                   ++v14;
                   pInString = v14;
@@ -1205,13 +1188,9 @@
                 else
                   pRenderer->DrawTextAlpha(v12, v13, (unsigned char*)v17, v16, LOBYTE(v10->uFontHeight),
                     v10->pFontPalettes[0], a7);
-                LOBYTE(v11) = v30;
                 v12 += v28;
                 if ( (signed int)pInString < (signed int)v30 )
-                {
-                  LOBYTE(v11) = 3 * *v27;
                   v12 += v10->pMetrics[(unsigned __int8)*v27].uRightSpacing;
-                }
                 break;
             }
           }
@@ -1219,9 +1198,6 @@
         }
         while ( (signed int)pInString < (signed int)v30 );
       }
-    }
-  }
-  return;
 }
 
 
@@ -3178,8 +3154,7 @@
 	pDialogueWindow->_41D08F_set_keyboard_control_group(1, 1, 0, 2);
 	dialog_menu_id = HOUSE_DIALOGUE_OTHER;
 }
-// F8B19C: using guessed type int dword_F8B19C;
-// F8B1A8: using guessed type int dword_F8B1A8;
+
 //----- (004B1ECE) --------------------------------------------------------
 void OracleDialogue()
 {
--- a/GUI/GUIWindow.h	Mon Oct 13 14:58:54 2014 +0300
+++ b/GUI/GUIWindow.h	Mon Oct 13 16:14:07 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 a8, signed int uFontShadowColor);
+  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 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();