mirror of
https://github.com/reactos/reactos.git
synced 2025-06-06 18:00:41 +00:00
[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:
parent
c044201472
commit
c25a0e1919
3 changed files with 65 additions and 43 deletions
|
@ -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)
|
VOID TuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom)
|
||||||
{
|
{
|
||||||
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
|
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 */
|
/* Shade the bottom of the area */
|
||||||
if (Bottom < (UiScreenHeight - 1))
|
if (BottomShadow)
|
||||||
{
|
{
|
||||||
if (UiScreenHeight < 34)
|
i = Left + (DoubleWidth ? 2 : 1);
|
||||||
Idx = Left + 2;
|
for (; i <= Right; ++i)
|
||||||
else
|
|
||||||
Idx = Left + 1;
|
|
||||||
|
|
||||||
for (; Idx <= Right; ++Idx)
|
|
||||||
{
|
{
|
||||||
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 */
|
/* 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[((i*2)*UiScreenWidth)+((Right+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
|
||||||
{
|
|
||||||
ScreenMemory[((Idx*2)*UiScreenWidth)+((Right+2)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Shade the bottom right corner */
|
/* 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);
|
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" */
|
/* Build the time string in format: "h:mm:ss tt" */
|
||||||
RtlStringCbPrintfA(Buffer, sizeof(Buffer),
|
RtlStringCbPrintfA(Buffer, sizeof(Buffer),
|
||||||
" %d:%02d:%02d %s",
|
" %d:%02d:%02d %s",
|
||||||
TimeInfo->Hour,
|
TimeInfo->Hour,
|
||||||
TimeInfo->Minute,
|
TimeInfo->Minute,
|
||||||
TimeInfo->Second,
|
TimeInfo->Second,
|
||||||
|
@ -666,7 +664,7 @@ TuiDrawMsgBoxCommon(
|
||||||
_Out_ PSMALL_RECT MsgBoxRect)
|
_Out_ PSMALL_RECT MsgBoxRect)
|
||||||
{
|
{
|
||||||
INT width = 8;
|
INT width = 8;
|
||||||
ULONG height = 1;
|
INT height = 1;
|
||||||
INT curline = 0;
|
INT curline = 0;
|
||||||
INT k;
|
INT k;
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
|
@ -696,11 +694,26 @@ TuiDrawMsgBoxCommon(
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate box area */
|
/* Account for the message box margins & bottom button/edit box */
|
||||||
x1 = (UiScreenWidth - (width+2))/2;
|
width += 4; // Border & space on left and right.
|
||||||
x2 = x1 + width + 3;
|
height += 5; // Border on top and bottom, plus 3 lines for button/edit box.
|
||||||
y1 = ((UiScreenHeight - height - 2)/2) + 1;
|
|
||||||
y2 = y1 + height + 4;
|
/* 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->Left = x1; MsgBoxRect->Right = x2;
|
||||||
MsgBoxRect->Top = y1; MsgBoxRect->Bottom = y2;
|
MsgBoxRect->Top = y1; MsgBoxRect->Bottom = y2;
|
||||||
|
|
|
@ -151,7 +151,6 @@ TuiCalcMenuBoxSize(
|
||||||
|
|
||||||
/* Height is the menu item count plus 2 (top border & bottom border) */
|
/* Height is the menu item count plus 2 (top border & bottom border) */
|
||||||
Height = MenuInfo->MenuItemCount + 2;
|
Height = MenuInfo->MenuItemCount + 2;
|
||||||
Height -= 1; // Height is zero-based
|
|
||||||
|
|
||||||
/* Loop every item */
|
/* Loop every item */
|
||||||
for (i = 0; i < MenuInfo->MenuItemCount; ++i)
|
for (i = 0; i < MenuInfo->MenuItemCount; ++i)
|
||||||
|
@ -160,20 +159,30 @@ TuiCalcMenuBoxSize(
|
||||||
if (MenuInfo->MenuItemList[i])
|
if (MenuInfo->MenuItemList[i])
|
||||||
{
|
{
|
||||||
Length = (ULONG)strlen(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 */
|
/* Allow room for left & right borders, plus 4 spaces on each side */
|
||||||
Width += 18;
|
Width += 10;
|
||||||
|
|
||||||
/* Check if we're drawing a centered menu */
|
/* Check if we're drawing a centered menu */
|
||||||
if (UiCenterMenu)
|
if (UiCenterMenu)
|
||||||
{
|
{
|
||||||
/* Calculate the menu box area for a centered menu */
|
/* Calculate the centered menu box area, also ensuring that the top-left
|
||||||
MenuInfo->Left = (UiScreenWidth - Width) / 2;
|
* corner is always visible if the borders are partly off-screen */
|
||||||
MenuInfo->Top = (((UiScreenHeight - TUI_TITLE_BOX_CHAR_HEIGHT) -
|
MenuInfo->Left = (UiScreenWidth - min(Width, UiScreenWidth)) / 2;
|
||||||
Height) / 2) + TUI_TITLE_BOX_CHAR_HEIGHT;
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -183,8 +192,8 @@ TuiCalcMenuBoxSize(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The other margins are the same */
|
/* The other margins are the same */
|
||||||
MenuInfo->Right = MenuInfo->Left + Width;
|
MenuInfo->Right = MenuInfo->Left + Width - 1;
|
||||||
MenuInfo->Bottom = MenuInfo->Top + Height;
|
MenuInfo->Bottom = MenuInfo->Top + Height - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
|
|
@ -360,10 +360,10 @@ UiMessageBox(
|
||||||
_In_ PCSTR Format, ...)
|
_In_ PCSTR Format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
CHAR Buffer[256];
|
CHAR Buffer[1024];
|
||||||
|
|
||||||
va_start(ap, Format);
|
va_start(ap, Format);
|
||||||
vsnprintf(Buffer, sizeof(Buffer) - sizeof(CHAR), Format, ap);
|
_vsnprintf(Buffer, sizeof(Buffer) - sizeof(CHAR), Format, ap);
|
||||||
UiVtbl.MessageBox(Buffer);
|
UiVtbl.MessageBox(Buffer);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue