From 5239a0ca4d37cebfbe3029323b6e006e71b39137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Mon, 14 Feb 2022 16:58:06 +0100 Subject: [PATCH] [FREELDR:UI] Improve how menu line separators are drawn. When the menu is not boxed, do not draw the specific "T"-shaped box corners for the separators. --- boot/freeldr/freeldr/ui/tuimenu.c | 120 ++++++++++++++++-------------- 1 file changed, 64 insertions(+), 56 deletions(-) diff --git a/boot/freeldr/freeldr/ui/tuimenu.c b/boot/freeldr/freeldr/ui/tuimenu.c index 1e4a2c64d18..500a8995467 100644 --- a/boot/freeldr/freeldr/ui/tuimenu.c +++ b/boot/freeldr/freeldr/ui/tuimenu.c @@ -349,24 +349,6 @@ TuiDrawMenuBox( ATTR(UiMenuFgColor, UiMenuBgColor)); } } - - /* Loop each item */ - for (i = 0; i < MenuInfo->MenuItemCount; i++) - { - /* Check if it's a separator */ - if (MenuInfo->MenuItemList[i] == NULL) - { - /* Draw the separator line */ - UiDrawText(MenuInfo->Left, - MenuInfo->Top + i + 1, - "\xC7", - ATTR(UiMenuFgColor, UiMenuBgColor)); - UiDrawText(MenuInfo->Right, - MenuInfo->Top + i + 1, - "\xB6", - ATTR(UiMenuFgColor, UiMenuBgColor)); - } - } } VOID @@ -374,15 +356,55 @@ TuiDrawMenuItem( _In_ PUI_MENU_INFO MenuInfo, _In_ ULONG MenuItemNumber) { -#ifndef _M_ARM - ULONG i; - ULONG SpaceTotal; ULONG SpaceLeft; - ULONG SpaceRight = 0; -#endif - UCHAR Attribute = ATTR(UiTextColor, UiMenuBgColor); + ULONG SpaceRight; + UCHAR Attribute; CHAR MenuLineText[80]; + /* If this is a separator */ + if (MenuInfo->MenuItemList[MenuItemNumber] == NULL) + { +#ifndef _M_ARM // FIXME: Theme-specific + /* Draw its left box corner */ + if (UiMenuBox) + { + UiDrawText(MenuInfo->Left, + MenuInfo->Top + 1 + MenuItemNumber, + "\xC7", + ATTR(UiMenuFgColor, UiMenuBgColor)); + } +#endif + + /* Make it a separator line and use menu colors */ + RtlZeroMemory(MenuLineText, sizeof(MenuLineText)); + RtlFillMemory(MenuLineText, + min(sizeof(MenuLineText), (MenuInfo->Right - MenuInfo->Left - 1)), + 0xC4); + + /* Draw the item */ + UiDrawText(MenuInfo->Left + 1, + MenuInfo->Top + 1 + MenuItemNumber, + MenuLineText, + ATTR(UiMenuFgColor, UiMenuBgColor)); + +#ifndef _M_ARM // FIXME: Theme-specific + /* Draw its right box corner */ + if (UiMenuBox) + { + UiDrawText(MenuInfo->Right, + MenuInfo->Top + 1 + MenuItemNumber, + "\xB6", + ATTR(UiMenuFgColor, UiMenuBgColor)); + } +#endif + + /* We are done */ + return; + } + + /* This is not a separator */ + ASSERT(MenuInfo->MenuItemList[MenuItemNumber]); + #ifndef _M_ARM /* Check if using centered menu */ if (UiCenterMenu) @@ -391,51 +413,37 @@ TuiDrawMenuItem( * We will want the string centered so calculate * how many spaces will be to the left and right. */ - SpaceTotal = (MenuInfo->Right - MenuInfo->Left - 2) - - (ULONG)(MenuInfo->MenuItemList[MenuItemNumber] ? - strlen(MenuInfo->MenuItemList[MenuItemNumber]) : 0); - SpaceLeft = (SpaceTotal / 2) + 1; + ULONG SpaceTotal = + (MenuInfo->Right - MenuInfo->Left - 2) - + (ULONG)strlen(MenuInfo->MenuItemList[MenuItemNumber]); + SpaceLeft = (SpaceTotal / 2) + 1; SpaceRight = (SpaceTotal - SpaceLeft) + 1; - - /* Insert the spaces on the left */ - for (i = 0; i < SpaceLeft; i++) - MenuLineText[i] = ' '; - MenuLineText[i] = '\0'; } else #endif { /* Simply left-align it */ - MenuLineText[0] = '\0'; - strcat(MenuLineText, " "); + SpaceLeft = 4; + SpaceRight = 0; } - /* Now append the text string */ - if (MenuInfo->MenuItemList[MenuItemNumber]) - strcat(MenuLineText, MenuInfo->MenuItemList[MenuItemNumber]); + /* Format the item text string */ + RtlStringCbPrintfA(MenuLineText, sizeof(MenuLineText), + "%*s%s%*s", + SpaceLeft, "", // Left padding + MenuInfo->MenuItemList[MenuItemNumber], + SpaceRight, ""); // Right padding -#ifndef _M_ARM - /* Check if using centered menu, and add spaces on the right if so */ - if (UiCenterMenu) - { - for (i = 0; i < SpaceRight; i++) - strcat(MenuLineText, " "); - } -#endif - - /* If it is a separator */ - if (MenuInfo->MenuItemList[MenuItemNumber] == NULL) - { - /* Make it a separator line and use menu colors */ - memset(MenuLineText, 0, sizeof(MenuLineText)); - memset(MenuLineText, 0xC4, (MenuInfo->Right - MenuInfo->Left - 1)); - Attribute = ATTR(UiMenuFgColor, UiMenuBgColor); - } - else if (MenuItemNumber == MenuInfo->SelectedMenuItem) + if (MenuItemNumber == MenuInfo->SelectedMenuItem) { /* If this is the selected item, use the selected colors */ Attribute = ATTR(UiSelectedTextColor, UiSelectedTextBgColor); } + else + { + /* Normal item colors */ + Attribute = ATTR(UiTextColor, UiMenuBgColor); + } /* Draw the item */ UiDrawText(MenuInfo->Left + 1,