From 7e3a6bd44c471303082ce0bfcc4e008ee1961a11 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sat, 31 Oct 2020 09:08:48 -0500 Subject: [PATCH 1/3] Increase Connect via IP textbox width and have shorten and truncate the text as necessary --- src/m_menu.c | 60 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index db2aa09c6..452a31c71 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -11605,7 +11605,10 @@ static void M_StartServerMenu(INT32 choice) // CONNECT VIA IP // ============== -static char setupm_ip[28]; +#define CONNIP_LEN 128 +static char setupm_ip[CONNIP_LEN]; + +#define DOTS "... " // Draw the funky Connect IP menu. Tails 11-19-2002 // So much work for such a little thing! @@ -11613,6 +11616,11 @@ static void M_DrawMPMainMenu(void) { INT32 x = currentMenu->x; INT32 y = currentMenu->y; + const INT32 boxwidth = /*16*8 + 6*/ (BASEVIDWIDTH - 2*(x+5)); + const INT32 maxstrwidth = boxwidth - 5; + char drawnstr[CONNIP_LEN]; + char *drawnstrptr = malloc(sizeof(setupm_ip)); + boolean drawthin, shorten = false; // use generic drawer for cursor, items and title M_DrawGenericMenu(); @@ -11628,17 +11636,53 @@ static void M_DrawMPMainMenu(void) y += 22; - V_DrawFill(x+5, y+4+5, /*16*8 + 6,*/ BASEVIDWIDTH - 2*(x+5), 8+6, 159); + V_DrawFill(x+5, y+4+5, boxwidth, 8+6, 159); + + strcpy(drawnstrptr, setupm_ip); + drawthin = V_StringWidth(drawnstrptr, V_ALLOWLOWERCASE) + V_StringWidth("_", V_ALLOWLOWERCASE) > maxstrwidth; // draw name string - V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, setupm_ip); + if (drawthin) + { + INT32 dotswidth = V_ThinStringWidth(DOTS, V_ALLOWLOWERCASE); + //UINT32 color = 0; + while (V_ThinStringWidth(drawnstrptr, V_ALLOWLOWERCASE) + V_ThinStringWidth("_", V_ALLOWLOWERCASE) >= maxstrwidth) + { + shorten = true; + drawnstrptr++; + } + + if (shorten) + { + INT32 initiallen = V_ThinStringWidth(drawnstrptr, V_ALLOWLOWERCASE); + INT32 cutofflen = 0; + while ((cutofflen = initiallen - V_ThinStringWidth(drawnstrptr, V_ALLOWLOWERCASE)) < dotswidth) + drawnstrptr++; + + V_DrawThinString(x+8,y+13, V_ALLOWLOWERCASE|V_GRAYMAP, DOTS); + x += V_ThinStringWidth(DOTS, V_ALLOWLOWERCASE); + } + + V_DrawThinString(x+8,y+13, V_ALLOWLOWERCASE, drawnstrptr); + } + else + { + V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, drawnstrptr); + } // draw text cursor for name if (itemOn == 2 //0 - && skullAnimCounter < 4) //blink cursor - V_DrawCharacter(x+8+V_StringWidth(setupm_ip, V_ALLOWLOWERCASE),y+12,'_',false); + && skullAnimCounter < 4) //blink cursor + { + if (drawthin) + V_DrawCharacter(x+8+V_ThinStringWidth(drawnstrptr, V_ALLOWLOWERCASE),y+12,'_',false); + else + V_DrawCharacter(x+8+V_StringWidth(drawnstrptr, V_ALLOWLOWERCASE),y+12,'_',false); + } } +#undef DOTS + // Tails 11-19-2002 static void M_ConnectIP(INT32 choice) { @@ -11719,7 +11763,7 @@ static void M_HandleConnectIP(INT32 choice) const char *paste = I_ClipboardPaste(); if (paste != NULL) { - strncat(setupm_ip, paste, 28-1 - l); // Concat the ip field with clipboard + strncat(setupm_ip, paste, CONNIP_LEN-1 - l); // Concat the ip field with clipboard if (strlen(paste) != 0) // Don't play sound if nothing was pasted S_StartSound(NULL,sfx_menu1); // Tails } @@ -11753,7 +11797,7 @@ static void M_HandleConnectIP(INT32 choice) const char *paste = I_ClipboardPaste(); if (paste != NULL) { - strncat(setupm_ip, paste, 28-1 - l); // Concat the ip field with clipboard + strncat(setupm_ip, paste, CONNIP_LEN-1 - l); // Concat the ip field with clipboard if (strlen(paste) != 0) // Don't play sound if nothing was pasted S_StartSound(NULL,sfx_menu1); // Tails } @@ -11770,7 +11814,7 @@ static void M_HandleConnectIP(INT32 choice) } } - if (l >= 28-1) + if (l >= CONNIP_LEN-1) break; // Rudimentary number and period enforcing - also allows letters so hostnames can be used instead From f0bee67d6e097fea8d07e16b85bf459948de06cf Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sat, 20 Feb 2021 17:01:45 -0600 Subject: [PATCH 2/3] Remove unused static-alloc `drawnstr`, rename `drawnstrptr` to `drawnstr`. --- src/m_menu.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 452a31c71..6db0f4c78 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -11618,8 +11618,7 @@ static void M_DrawMPMainMenu(void) INT32 y = currentMenu->y; const INT32 boxwidth = /*16*8 + 6*/ (BASEVIDWIDTH - 2*(x+5)); const INT32 maxstrwidth = boxwidth - 5; - char drawnstr[CONNIP_LEN]; - char *drawnstrptr = malloc(sizeof(setupm_ip)); + char *drawnstr = malloc(sizeof(setupm_ip)); boolean drawthin, shorten = false; // use generic drawer for cursor, items and title @@ -11638,36 +11637,36 @@ static void M_DrawMPMainMenu(void) V_DrawFill(x+5, y+4+5, boxwidth, 8+6, 159); - strcpy(drawnstrptr, setupm_ip); - drawthin = V_StringWidth(drawnstrptr, V_ALLOWLOWERCASE) + V_StringWidth("_", V_ALLOWLOWERCASE) > maxstrwidth; + strcpy(drawnstr, setupm_ip); + drawthin = V_StringWidth(drawnstr, V_ALLOWLOWERCASE) + V_StringWidth("_", V_ALLOWLOWERCASE) > maxstrwidth; // draw name string if (drawthin) { INT32 dotswidth = V_ThinStringWidth(DOTS, V_ALLOWLOWERCASE); //UINT32 color = 0; - while (V_ThinStringWidth(drawnstrptr, V_ALLOWLOWERCASE) + V_ThinStringWidth("_", V_ALLOWLOWERCASE) >= maxstrwidth) + while (V_ThinStringWidth(drawnstr, V_ALLOWLOWERCASE) + V_ThinStringWidth("_", V_ALLOWLOWERCASE) >= maxstrwidth) { shorten = true; - drawnstrptr++; + drawnstr++; } if (shorten) { - INT32 initiallen = V_ThinStringWidth(drawnstrptr, V_ALLOWLOWERCASE); + INT32 initiallen = V_ThinStringWidth(drawnstr, V_ALLOWLOWERCASE); INT32 cutofflen = 0; - while ((cutofflen = initiallen - V_ThinStringWidth(drawnstrptr, V_ALLOWLOWERCASE)) < dotswidth) - drawnstrptr++; + while ((cutofflen = initiallen - V_ThinStringWidth(drawnstr, V_ALLOWLOWERCASE)) < dotswidth) + drawnstr++; V_DrawThinString(x+8,y+13, V_ALLOWLOWERCASE|V_GRAYMAP, DOTS); x += V_ThinStringWidth(DOTS, V_ALLOWLOWERCASE); } - V_DrawThinString(x+8,y+13, V_ALLOWLOWERCASE, drawnstrptr); + V_DrawThinString(x+8,y+13, V_ALLOWLOWERCASE, drawnstr); } else { - V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, drawnstrptr); + V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, drawnstr); } // draw text cursor for name @@ -11675,9 +11674,9 @@ static void M_DrawMPMainMenu(void) && skullAnimCounter < 4) //blink cursor { if (drawthin) - V_DrawCharacter(x+8+V_ThinStringWidth(drawnstrptr, V_ALLOWLOWERCASE),y+12,'_',false); + V_DrawCharacter(x+8+V_ThinStringWidth(drawnstr, V_ALLOWLOWERCASE),y+12,'_',false); else - V_DrawCharacter(x+8+V_StringWidth(drawnstrptr, V_ALLOWLOWERCASE),y+12,'_',false); + V_DrawCharacter(x+8+V_StringWidth(drawnstr, V_ALLOWLOWERCASE),y+12,'_',false); } } From 1639676e8da2db5c20cfc0f9465739600e40384a Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Fri, 3 Sep 2021 09:14:04 -0500 Subject: [PATCH 3/3] Actually free the drawnstr pointer after we're done using it. It probably was like this originally because past Golden was confused about why free was throwing errors :P --- src/m_menu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/m_menu.c b/src/m_menu.c index 6db0f4c78..ac5269c3e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -11619,6 +11619,7 @@ static void M_DrawMPMainMenu(void) const INT32 boxwidth = /*16*8 + 6*/ (BASEVIDWIDTH - 2*(x+5)); const INT32 maxstrwidth = boxwidth - 5; char *drawnstr = malloc(sizeof(setupm_ip)); + char *drawnstr_orig = drawnstr; boolean drawthin, shorten = false; // use generic drawer for cursor, items and title @@ -11678,6 +11679,8 @@ static void M_DrawMPMainMenu(void) else V_DrawCharacter(x+8+V_StringWidth(drawnstr, V_ALLOWLOWERCASE),y+12,'_',false); } + + free(drawnstr_orig); } #undef DOTS