[FREELDR:UI] Minor miscellaneous fixes.

- UiMessageBox(): Enlarge the default buffer used to printf msgbox strings.

- TuiUpdateDateTime(): When displaying the time, don't pad too much
  with spaces on the left.

- TuiDrawShadow():
  * Pre-calculate whether we need to show the right/bottom shadows,
    and whether the right-shadow has a double width.
  * Cap the right and bottom upper-bound coordinates before looping,
    in order to avoid buffer overflows if the given coordinates go
    beyond the screen.

- TuiDrawMsgBoxCommon(): Improve how the message box centering
  calculations are done:
  * When the "full-UI" is used (and center-menu is used), try to
    center the message box in the space between the header and
    the status bar.
  * Ensure the top-left box corner is inside the screen, in case
    the calculated message box borders go off-screen.

- TuiCalcMenuBoxSize():
  * Uniformize the way the menu box coordinates are calculated.
  * Reduce the space between menu box margins and the longest item.
  * Ensure the top-left menu corner is inside the screen, in case
    the calculated menu box borders go off-screen.
This commit is contained in:
Hermès Bélusca-Maïto 2024-04-10 14:47:01 +02:00
parent c044201472
commit c25a0e1919
No known key found for this signature in database
GPG Key ID: 3B2539C65E7B93D0
3 changed files with 65 additions and 43 deletions

View File

@ -359,52 +359,50 @@ VOID TuiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar
VOID TuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom)
{
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
ULONG Idx;
ULONG i;
BOOLEAN RightShadow = (Right < (UiScreenWidth - 1));
BOOLEAN DoubleRightShadow = ((Right + 1) < (UiScreenWidth - 1));
BOOLEAN BottomShadow = (Bottom < (UiScreenHeight - 1));
BOOLEAN DoubleWidth = (UiScreenHeight < 34);
/* Cap the right and bottom borders */
Right = min(Right, UiScreenWidth - 1);
Bottom = min(Bottom, UiScreenHeight - 1);
/* Shade the bottom of the area */
if (Bottom < (UiScreenHeight - 1))
if (BottomShadow)
{
if (UiScreenHeight < 34)
Idx = Left + 2;
else
Idx = Left + 1;
for (; Idx <= Right; ++Idx)
i = Left + (DoubleWidth ? 2 : 1);
for (; i <= Right; ++i)
{
ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+(Idx*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+(i*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
}
/* Shade the right of the area */
if (Right < (UiScreenWidth - 1))
if (RightShadow)
{
for (Idx=Top+1; Idx<=Bottom; Idx++)
for (i = Top + 1; i <= Bottom; ++i)
{
ScreenMemory[((Idx*2)*UiScreenWidth)+((Right+1)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
ScreenMemory[((i*2)*UiScreenWidth)+((Right+1)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
}
if (UiScreenHeight < 34)
if (DoubleWidth && DoubleRightShadow)
{
if ((Right + 1) < (UiScreenWidth - 1))
for (i = Top + 1; i <= Bottom; ++i)
{
for (Idx=Top+1; Idx<=Bottom; Idx++)
{
ScreenMemory[((Idx*2)*UiScreenWidth)+((Right+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
ScreenMemory[((i*2)*UiScreenWidth)+((Right+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
}
/* Shade the bottom right corner */
if ((Right < (UiScreenWidth - 1)) && (Bottom < (UiScreenHeight - 1)))
if (RightShadow && BottomShadow)
{
ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+((Right+1)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
if (UiScreenHeight < 34)
if (DoubleWidth && DoubleRightShadow && BottomShadow)
{
if (((Right + 1) < (UiScreenWidth - 1)) && (Bottom < (UiScreenHeight - 1)))
{
ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+((Right+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+((Right+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
}
@ -603,7 +601,7 @@ VOID TuiUpdateDateTime(VOID)
/* Build the time string in format: "h:mm:ss tt" */
RtlStringCbPrintfA(Buffer, sizeof(Buffer),
" %d:%02d:%02d %s",
" %d:%02d:%02d %s",
TimeInfo->Hour,
TimeInfo->Minute,
TimeInfo->Second,
@ -666,7 +664,7 @@ TuiDrawMsgBoxCommon(
_Out_ PSMALL_RECT MsgBoxRect)
{
INT width = 8;
ULONG height = 1;
INT height = 1;
INT curline = 0;
INT k;
size_t i, j;
@ -696,11 +694,26 @@ TuiDrawMsgBoxCommon(
j++;
}
/* Calculate box area */
x1 = (UiScreenWidth - (width+2))/2;
x2 = x1 + width + 3;
y1 = ((UiScreenHeight - height - 2)/2) + 1;
y2 = y1 + height + 4;
/* Account for the message box margins & bottom button/edit box */
width += 4; // Border & space on left and right.
height += 5; // Border on top and bottom, plus 3 lines for button/edit box.
/* Calculate the centered box area, also ensuring that the top-left
* corner is always visible if the borders are partly off-screen */
x1 = (UiScreenWidth - min(width, UiScreenWidth)) / 2;
if (UiCenterMenu && (height <= UiScreenHeight - TUI_TITLE_BOX_CHAR_HEIGHT - 1))
{
/* Exclude the header and the status bar */
// y1 = (UiScreenHeight - TUI_TITLE_BOX_CHAR_HEIGHT - 1 - height) / 2
// + TUI_TITLE_BOX_CHAR_HEIGHT;
y1 = (UiScreenHeight + TUI_TITLE_BOX_CHAR_HEIGHT - 1 - height) / 2;
}
else
{
y1 = (UiScreenHeight - min(height, UiScreenHeight)) / 2;
}
x2 = x1 + width - 1;
y2 = y1 + height - 1;
MsgBoxRect->Left = x1; MsgBoxRect->Right = x2;
MsgBoxRect->Top = y1; MsgBoxRect->Bottom = y2;

View File

@ -151,7 +151,6 @@ TuiCalcMenuBoxSize(
/* Height is the menu item count plus 2 (top border & bottom border) */
Height = MenuInfo->MenuItemCount + 2;
Height -= 1; // Height is zero-based
/* Loop every item */
for (i = 0; i < MenuInfo->MenuItemCount; ++i)
@ -160,20 +159,30 @@ TuiCalcMenuBoxSize(
if (MenuInfo->MenuItemList[i])
{
Length = (ULONG)strlen(MenuInfo->MenuItemList[i]);
if (Length > Width) Width = Length;
Width = max(Width, Length);
}
}
/* Allow room for left & right borders, plus 8 spaces on each side */
Width += 18;
/* Allow room for left & right borders, plus 4 spaces on each side */
Width += 10;
/* Check if we're drawing a centered menu */
if (UiCenterMenu)
{
/* Calculate the menu box area for a centered menu */
MenuInfo->Left = (UiScreenWidth - Width) / 2;
MenuInfo->Top = (((UiScreenHeight - TUI_TITLE_BOX_CHAR_HEIGHT) -
Height) / 2) + TUI_TITLE_BOX_CHAR_HEIGHT;
/* Calculate the centered menu box area, also ensuring that the top-left
* corner is always visible if the borders are partly off-screen */
MenuInfo->Left = (UiScreenWidth - min(Width, UiScreenWidth)) / 2;
if (Height <= UiScreenHeight - TUI_TITLE_BOX_CHAR_HEIGHT - 1)
{
/* Exclude the header and the status bar */
// MenuInfo->Top = (UiScreenHeight - TUI_TITLE_BOX_CHAR_HEIGHT - 1 - Height) / 2
// + TUI_TITLE_BOX_CHAR_HEIGHT;
MenuInfo->Top = (UiScreenHeight + TUI_TITLE_BOX_CHAR_HEIGHT - 1 - Height) / 2;
}
else
{
MenuInfo->Top = (UiScreenHeight - min(Height, UiScreenHeight)) / 2;
}
}
else
{
@ -183,8 +192,8 @@ TuiCalcMenuBoxSize(
}
/* The other margins are the same */
MenuInfo->Right = MenuInfo->Left + Width;
MenuInfo->Bottom = MenuInfo->Top + Height;
MenuInfo->Right = MenuInfo->Left + Width - 1;
MenuInfo->Bottom = MenuInfo->Top + Height - 1;
}
VOID

View File

@ -360,10 +360,10 @@ UiMessageBox(
_In_ PCSTR Format, ...)
{
va_list ap;
CHAR Buffer[256];
CHAR Buffer[1024];
va_start(ap, Format);
vsnprintf(Buffer, sizeof(Buffer) - sizeof(CHAR), Format, ap);
_vsnprintf(Buffer, sizeof(Buffer) - sizeof(CHAR), Format, ap);
UiVtbl.MessageBox(Buffer);
va_end(ap);
}