[FREELDR:UI] Code formatting only.

This commit is contained in:
Hermès Bélusca-Maïto 2022-01-04 00:24:42 +01:00
parent 942e79963a
commit 844c9dce6c
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
8 changed files with 224 additions and 384 deletions

View file

@ -19,35 +19,35 @@
#pragma once
extern ULONG UiScreenWidth; // Screen Width
extern ULONG UiScreenHeight; // Screen Height
extern ULONG UiScreenWidth; // Screen Width
extern ULONG UiScreenHeight; // Screen Height
extern UCHAR UiStatusBarFgColor; // Status bar foreground color
extern UCHAR UiStatusBarBgColor; // Status bar background color
extern UCHAR UiBackdropFgColor; // Backdrop foreground color
extern UCHAR UiBackdropBgColor; // Backdrop background color
extern UCHAR UiBackdropFillStyle; // Backdrop fill style
extern UCHAR UiTitleBoxFgColor; // Title box foreground color
extern UCHAR UiTitleBoxBgColor; // Title box background color
extern UCHAR UiMessageBoxFgColor; // Message box foreground color
extern UCHAR UiMessageBoxBgColor; // Message box background color
extern UCHAR UiMenuFgColor; // Menu foreground color
extern UCHAR UiMenuBgColor; // Menu background color
extern UCHAR UiTextColor; // Normal text color
extern UCHAR UiSelectedTextColor; // Selected text color
extern UCHAR UiSelectedTextBgColor; // Selected text background color
extern UCHAR UiEditBoxTextColor; // Edit box text color
extern UCHAR UiEditBoxBgColor; // Edit box text background color
extern UCHAR UiStatusBarFgColor; // Status bar foreground color
extern UCHAR UiStatusBarBgColor; // Status bar background color
extern UCHAR UiBackdropFgColor; // Backdrop foreground color
extern UCHAR UiBackdropBgColor; // Backdrop background color
extern UCHAR UiBackdropFillStyle; // Backdrop fill style
extern UCHAR UiTitleBoxFgColor; // Title box foreground color
extern UCHAR UiTitleBoxBgColor; // Title box background color
extern UCHAR UiMessageBoxFgColor; // Message box foreground color
extern UCHAR UiMessageBoxBgColor; // Message box background color
extern UCHAR UiMenuFgColor; // Menu foreground color
extern UCHAR UiMenuBgColor; // Menu background color
extern UCHAR UiTextColor; // Normal text color
extern UCHAR UiSelectedTextColor; // Selected text color
extern UCHAR UiSelectedTextBgColor; // Selected text background color
extern UCHAR UiEditBoxTextColor; // Edit box text color
extern UCHAR UiEditBoxBgColor; // Edit box text background color
extern CHAR UiTitleBoxTitleText[260]; // Title box's title text
extern CHAR UiTitleBoxTitleText[260]; // Title box's title text
extern BOOLEAN UiUseSpecialEffects; // Tells us if we should use fade effects
extern BOOLEAN UiCenterMenu;
extern BOOLEAN UiMenuBox;
extern CHAR UiTimeText[];
extern BOOLEAN UiDrawTime;
extern BOOLEAN UiUseSpecialEffects; // Tells us if we should use fade effects
extern BOOLEAN UiCenterMenu;
extern BOOLEAN UiMenuBox;
extern CHAR UiTimeText[];
extern BOOLEAN UiDrawTime;
extern const CHAR UiMonthNames[12][15];
extern const CHAR UiMonthNames[12][15];
///////////////////////////////////////////////////////////////////////////////////////
//
@ -186,46 +186,46 @@ VOID UiInit(const char *CmdLine);
extern UIVTBL UiVtbl;
/*
* Combines the foreground and background colors into a single attribute byte
*/
#define ATTR(cFore, cBack) ((cBack << 4)|cFore)
/*
* Fill styles for DrawBackdrop()
*/
#define LIGHT_FILL 0xB0
#define MEDIUM_FILL 0xB1
#define DARK_FILL 0xB2
#define LIGHT_FILL 0xB0
#define MEDIUM_FILL 0xB1
#define DARK_FILL 0xB2
/*
* Combines the foreground and background colors into a single attribute byte
*/
#define ATTR(cFore, cBack) ((cBack << 4) | cFore)
/*
* Screen colors
*/
#define COLOR_BLACK 0
#define COLOR_BLUE 1
#define COLOR_GREEN 2
#define COLOR_CYAN 3
#define COLOR_RED 4
#define COLOR_MAGENTA 5
#define COLOR_BROWN 6
#define COLOR_GRAY 7
#define COLOR_BLACK 0
#define COLOR_BLUE 1
#define COLOR_GREEN 2
#define COLOR_CYAN 3
#define COLOR_RED 4
#define COLOR_MAGENTA 5
#define COLOR_BROWN 6
#define COLOR_GRAY 7
#define COLOR_DARKGRAY 8
#define COLOR_LIGHTBLUE 9
#define COLOR_DARKGRAY 8
#define COLOR_LIGHTBLUE 9
#define COLOR_LIGHTGREEN 10
#define COLOR_LIGHTCYAN 11
#define COLOR_LIGHTRED 12
#define COLOR_LIGHTMAGENTA 13
#define COLOR_LIGHTCYAN 11
#define COLOR_LIGHTRED 12
#define COLOR_LIGHTMAGENTA 13
#define COLOR_YELLOW 14
#define COLOR_WHITE 15
#define COLOR_WHITE 15
/* Add COLOR_BLINK to a background to cause blinking */
//#define COLOR_BLINK 8
// #define COLOR_BLINK 8
/*
* Defines for IBM box drawing characters
*/
#define HORZ (0xc4) /* Single horizontal line */
#define D_HORZ (0xcd) /* Double horizontal line.*/
#define VERT (0xb3) /* Single vertical line */
#define D_VERT (0xba) /* Double vertical line. */
#define HORZ 0xC4 // Single horizontal line
#define D_HORZ 0xCD // Double horizontal line
#define VERT 0xB3 // Single vertical line
#define D_VERT 0xBA // Double vertical line

View file

@ -3,7 +3,7 @@
* PROJECT: FreeLoader
* FILE: boot/freeldr/freeldr/include/ui/minitui.h
* PURPOSE: Mini Text UI interface header
* PROGRAMMERS: Hervé Poussineau
* PROGRAMMERS: Hervé Poussineau
*/
#pragma once

View file

@ -3,7 +3,7 @@
* PROJECT: FreeLoader
* FILE: boot/freeldr/freeldr/include/ui/noui.h
* PURPOSE: No UI interface header
* PROGRAMMERS: Hervé Poussineau
* PROGRAMMERS: Hervé Poussineau
*/
#pragma once

View file

@ -78,25 +78,27 @@ TuiDisplayMenu(
IN UiMenuKeyPressFilterCallback KeyPressFilter OPTIONAL,
IN PVOID Context OPTIONAL);
/* Definitions for corners, depending on HORIZ and VERT */
#define UL (0xda)
#define UR (0xbf) /* HORZ and VERT */
#define LL (0xc0)
#define LR (0xd9)
/*
* Definitions for corners, depending on HORZ and VERT
*/
#define UL 0xDA /* HORZ and VERT */
#define UR 0xBF
#define LL 0xC0
#define LR 0xD9
#define D_UL (0xc9)
#define D_UR (0xbb) /* D_HORZ and D_VERT */
#define D_LL (0xc8)
#define D_LR (0xbc)
#define D_UL 0xC9 /* D_HORZ and D_VERT */
#define D_UR 0xBB
#define D_LL 0xC8
#define D_LR 0xBC
#define HD_UL (0xd5)
#define HD_UR (0xb8) /* D_HORZ and VERT */
#define HD_LL (0xd4)
#define HD_LR (0xbe)
#define HD_UL 0xD5 /* D_HORZ and VERT */
#define HD_UR 0xB8
#define HD_LL 0xD4
#define HD_LR 0xBE
#define VD_UL (0xd6)
#define VD_UR (0xb7) /* HORZ and D_VERT */
#define VD_LL (0xd3)
#define VD_LR (0xbd)
#define VD_UL 0xD6 /* HORZ and D_VERT */
#define VD_UR 0xB7
#define VD_LL 0xD3
#define VD_LR 0xBD
extern const UIVTBL TuiVtbl;

View file

@ -6,27 +6,22 @@
* PROGRAMMERS: Brian Palmer <brianp@sginet.com>
* Hervé Poussineau
*/
#ifndef _M_ARM
#include <freeldr.h>
VOID MiniTuiDrawBackdrop(VOID)
{
//
// Fill in a black background
//
/* Fill in a black background */
TuiFillArea(0, 0, UiScreenWidth - 1, UiScreenHeight - 1, 0, 0);
//
// Update the screen buffer
//
/* Update the screen buffer */
VideoCopyOffScreenBufferToVRAM();
}
VOID MiniTuiDrawStatusText(PCSTR StatusText)
{
//
// Minimal UI doesn't have a status bar
//
/* Minimal UI doesn't have a status bar */
}
VOID MiniTuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
@ -47,26 +42,22 @@ VOID MiniTuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressTex
VOID MiniTuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText)
{
ULONG i;
ULONG ProgressBarWidth = (Right - Left) - 3;
ULONG i;
ULONG ProgressBarWidth = (Right - Left) - 3;
// First make sure the progress bar text fits
/* First make sure the progress bar text fits */
UiTruncateStringEllipsis(ProgressText, ProgressBarWidth - 4);
if (Position > Range)
{
Position = Range;
}
//
// Draw the "Loading..." text
//
TuiDrawCenteredText(Left + 2, Top + 1, Right - 2, Top + 1, ProgressText, ATTR(7, 0));
/* Draw the "Loading..." text */
TuiDrawCenteredText(Left + 2, Top + 1, Right - 2, Top + 1, ProgressText, ATTR(COLOR_GRAY, COLOR_BLACK));
// Draw the percent complete
for (i=0; i<(Position*ProgressBarWidth)/Range; i++)
/* Draw the percent complete */
for (i = 0; i < (Position * ProgressBarWidth) / Range; i++)
{
TuiDrawText(Left+2+i, Top+2, "\xDB", ATTR(UiTextColor, UiMenuBgColor));
/* Use the fill character */
TuiDrawText(Left + 2 + i, Top + 2, "\xDB", ATTR(UiTextColor, UiMenuBgColor));
}
TuiUpdateDateTime();
@ -78,14 +69,10 @@ MiniTuiDrawMenu(PUI_MENU_INFO MenuInfo)
{
ULONG i;
//
// Draw the backdrop
//
/* Draw the backdrop */
UiDrawBackdrop();
//
// No GUI status bar text, just minimal text. Show the menu header.
//
/* No GUI status bar text, just minimal text. Show the menu header. */
if (MenuInfo->MenuHeader)
{
UiVtbl.DrawText(0,
@ -94,9 +81,7 @@ MiniTuiDrawMenu(PUI_MENU_INFO MenuInfo)
ATTR(UiMenuFgColor, UiMenuBgColor));
}
//
// Now tell the user how to choose
//
/* Now tell the user how to choose */
UiVtbl.DrawText(0,
MenuInfo->Bottom + 1,
"Use \x18 and \x19 to move the highlight to your choice.",
@ -106,9 +91,7 @@ MiniTuiDrawMenu(PUI_MENU_INFO MenuInfo)
"Press ENTER to choose.",
ATTR(UiMenuFgColor, UiMenuBgColor));
//
// And show the menu footer
//
/* And show the menu footer */
if (MenuInfo->MenuFooter)
{
UiVtbl.DrawText(0,
@ -117,22 +100,16 @@ MiniTuiDrawMenu(PUI_MENU_INFO MenuInfo)
ATTR(UiMenuFgColor, UiMenuBgColor));
}
//
// Draw the menu box
//
/* Draw the menu box */
TuiDrawMenuBox(MenuInfo);
//
// Draw each line of the menu
//
/* Draw each line of the menu */
for (i = 0; i < MenuInfo->MenuItemCount; i++)
{
TuiDrawMenuItem(MenuInfo, i);
}
//
// Display the boot options if needed
//
/* Display the boot options if needed */
if (MenuInfo->ShowBootOptions)
{
DisplayBootTimeOptions();
@ -166,4 +143,5 @@ const UIVTBL MiniTuiVtbl =
TuiDisplayMenu,
MiniTuiDrawMenu,
};
#endif
#endif // _M_ARM

View file

@ -3,7 +3,7 @@
* PROJECT: FreeLoader
* FILE: boot/freeldr/freeldr/ui/noui.c
* PURPOSE: No Text UI interface
* PROGRAMMERS: Hervé Poussineau
* PROGRAMMERS: Hervé Poussineau
*/
#ifndef _M_ARM
#include <freeldr.h>

View file

@ -153,28 +153,23 @@ VOID TuiDrawBackdrop(VOID)
*/
VOID TuiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr /* Color Attributes */)
{
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
ULONG i, j;
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
ULONG i, j;
// Clip the area to the screen
/* Clip the area to the screen */
if ((Left >= UiScreenWidth) || (Top >= UiScreenHeight))
{
return;
}
if (Right >= UiScreenWidth)
{
Right = UiScreenWidth - 1;
}
if (Bottom >= UiScreenHeight)
{
Bottom = UiScreenHeight - 1;
}
// Loop through each line and fill it in
for (i=Top; i<=Bottom; i++)
/* Loop through each line and column and fill it in */
for (i = Top; i <= Bottom; ++i)
{
// Loop through each character (column) in the line and fill it in
for (j=Left; j<=Right; j++)
for (j = Left; j <= Right; ++j)
{
ScreenMemory[((i*2)*UiScreenWidth)+(j*2)] = (UCHAR)FillChar;
ScreenMemory[((i*2)*UiScreenWidth)+(j*2)+1] = Attr;
@ -188,28 +183,24 @@ 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;
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
ULONG Idx;
// Shade the bottom of the area
/* Shade the bottom of the area */
if (Bottom < (UiScreenHeight - 1))
{
if (UiScreenHeight < 34)
{
Idx=Left + 2;
}
Idx = Left + 2;
else
{
Idx=Left + 1;
}
Idx = Left + 1;
for (; Idx<=Right; Idx++)
for (; Idx <= Right; ++Idx)
{
ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+(Idx*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
}
}
// Shade the right of the area
/* Shade the right of the area */
if (Right < (UiScreenWidth - 1))
{
for (Idx=Top+1; Idx<=Bottom; Idx++)
@ -228,7 +219,7 @@ VOID TuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom)
}
}
// Shade the bottom right corner
/* Shade the bottom right corner */
if ((Right < (UiScreenWidth - 1)) && (Bottom < (UiScreenHeight - 1)))
{
ScreenMemory[(((Bottom+1)*2)*UiScreenWidth)+((Right+1)*2)+1] = ATTR(COLOR_GRAY, COLOR_BLACK);
@ -648,9 +639,9 @@ VOID TuiMessageBoxCritical(PCSTR MessageText)
VOID TuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
{
ULONG Left, Top, Right, Bottom;
ULONG Width = 50; // Allow for 50 "bars"
ULONG Height = 2;
ULONG Left, Top, Right, Bottom;
ULONG Width = 50; // Allow for 50 "bars"
ULONG Height = 2;
Left = (UiScreenWidth - Width - 4) / 2;
Right = Left + Width + 3;
@ -663,35 +654,32 @@ VOID TuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
VOID TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText)
{
ULONG i;
ULONG ProgressBarWidth = (Right - Left) - 3;
ULONG i;
ULONG ProgressBarWidth = (Right - Left) - 3;
// First make sure the progress bar text fits
/* First make sure the progress bar text fits */
UiTruncateStringEllipsis(ProgressText, ProgressBarWidth - 4);
if (Position > Range)
{
Position = Range;
}
// Draw the box
/* Draw the box */
TuiDrawBox(Left, Top, Right, Bottom, VERT, HORZ, TRUE, TRUE, ATTR(UiMenuFgColor, UiMenuBgColor));
//
// Draw the "Loading..." text
//
/* Draw the "Loading..." text */
TuiDrawCenteredText(Left + 2, Top + 2, Right - 2, Top + 2, ProgressText, ATTR(UiTextColor, UiMenuBgColor));
// Draw the percent complete
for (i=0; i<(Position*ProgressBarWidth)/Range; i++)
/* Draw the percent complete */
for (i = 0; i < (Position * ProgressBarWidth) / Range; i++)
{
TuiDrawText(Left+2+i, Top+2, "\xDB", ATTR(UiTextColor, UiMenuBgColor));
/* Use the fill character */
TuiDrawText(Left + 2 + i, Top + 2, "\xDB", ATTR(UiTextColor, UiMenuBgColor));
}
// Draw the shadow
for (; i<ProgressBarWidth; i++)
/* Draw the shadow */
for (; i < ProgressBarWidth; i++)
{
TuiDrawText(Left+2+i, Top+2, "\xB2", ATTR(UiTextColor, UiMenuBgColor));
TuiDrawText(Left + 2 + i, Top + 2, "\xB2", ATTR(UiTextColor, UiMenuBgColor));
}
TuiUpdateDateTime();

View file

@ -8,6 +8,7 @@
*/
/* INCLUDES ******************************************************************/
#ifndef _M_ARM
#include <freeldr.h>
@ -32,49 +33,39 @@ TuiDisplayMenu(
ULONG CurrentClockSecond;
ULONG KeyPress;
//
// Before taking any default action if there is no timeout,
// check whether the supplied key filter callback function
// may handle a specific user keypress. If it does, the
// timeout is cancelled.
//
/*
* Before taking any default action if there is no timeout,
* check whether the supplied key filter callback function
* may handle a specific user keypress. If it does, the
* timeout is cancelled.
*/
if (!MenuTimeOut && KeyPressFilter && MachConsKbHit())
{
//
// Get the key (get the extended key if needed)
//
/* Get the key (get the extended key if needed) */
KeyPress = MachConsGetCh();
if (KeyPress == KEY_EXTENDED)
KeyPress = MachConsGetCh();
//
// Call the supplied key filter callback function to see
// if it is going to handle this keypress.
//
/*
* Call the supplied key filter callback function to see
* if it is going to handle this keypress.
*/
if (KeyPressFilter(KeyPress, DefaultMenuItem, Context))
{
//
// It processed the key character, cancel the timeout
//
/* It processed the key character, cancel the timeout */
MenuTimeOut = -1;
}
}
//
// Check if there's no timeout
//
/* Check if there is no timeout */
if (!MenuTimeOut)
{
//
// Return the default selected item
//
/* Return the default selected item */
if (SelectedMenuItem) *SelectedMenuItem = DefaultMenuItem;
return TRUE;
}
//
// Setup the MENU_INFO structure
//
/* Setup the MENU_INFO structure */
MenuInformation.MenuHeader = MenuHeader;
MenuInformation.MenuFooter = MenuFooter;
MenuInformation.ShowBootOptions = ShowBootOptions;
@ -84,85 +75,57 @@ TuiDisplayMenu(
MenuInformation.SelectedMenuItem = DefaultMenuItem;
MenuInformation.Context = Context;
//
// Calculate the size of the menu box
//
/* Calculate the size of the menu box */
TuiCalcMenuBoxSize(&MenuInformation);
//
// Draw the menu
//
/* Draw the menu */
UiVtbl.DrawMenu(&MenuInformation);
//
// Get the current second of time
//
/* Get the current second of time */
LastClockSecond = ArcGetTime()->Second;
//
// Process keys
//
/* Process keys */
while (TRUE)
{
//
// Process key presses
//
/* Process key presses */
KeyPress = TuiProcessMenuKeyboardEvent(&MenuInformation, KeyPressFilter);
//
// Check for ENTER or ESC
//
/* Check for ENTER or ESC */
if (KeyPress == KEY_ENTER) break;
if (CanEscape && KeyPress == KEY_ESC) return FALSE;
//
// Update the date & time
//
/* Update the date & time */
TuiUpdateDateTime();
VideoCopyOffScreenBufferToVRAM();
//
// Check if there is a countdown
//
/* Check if there is a countdown */
if (MenuInformation.MenuTimeRemaining > 0)
{
//
// Get the updated time, seconds only
//
/* Get the updated time, seconds only */
CurrentClockSecond = ArcGetTime()->Second;
//
// Check if more then a second has now elapsed
//
/* Check if more than a second has now elapsed */
if (CurrentClockSecond != LastClockSecond)
{
//
// Update the time information
//
/* Update the time information */
LastClockSecond = CurrentClockSecond;
MenuInformation.MenuTimeRemaining--;
//
// Update the menu
//
/* Update the menu */
TuiDrawMenuBox(&MenuInformation);
VideoCopyOffScreenBufferToVRAM();
}
}
else if (MenuInformation.MenuTimeRemaining == 0)
{
//
// A time out occurred, exit this loop and return default OS
//
/* A time out occurred, exit this loop and return default OS */
break;
}
MachHwIdle();
}
//
// Return the selected item
//
/* Return the selected item */
if (SelectedMenuItem) *SelectedMenuItem = MenuInformation.SelectedMenuItem;
return TRUE;
}
@ -175,20 +138,14 @@ TuiCalcMenuBoxSize(PUI_MENU_INFO MenuInfo)
ULONG Height;
ULONG Length;
//
// 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 -= 1; // Height is zero-based
//
// Loop every item
//
for(i = 0; i < MenuInfo->MenuItemCount; i++)
/* Loop every item */
for (i = 0; i < MenuInfo->MenuItemCount; i++)
{
//
// Get the string length and make it become the new width if necessary
//
/* Get the string length and make it become the new width if necessary */
if (MenuInfo->MenuItemList[i])
{
Length = (ULONG)strlen(MenuInfo->MenuItemList[i]);
@ -196,35 +153,25 @@ TuiCalcMenuBoxSize(PUI_MENU_INFO MenuInfo)
}
}
//
// Allow room for left & right borders, plus 8 spaces on each side
//
/* Allow room for left & right borders, plus 8 spaces on each side */
Width += 18;
//
// Check if we're drawing a centered menu
//
/* Check if we're drawing a centered menu */
if (UiCenterMenu)
{
//
// Calculate the menu box area for a centered menu
//
/* 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;
}
else
{
//
// Put the menu in the default left-corner position
//
/* Put the menu in the default left-corner position */
MenuInfo->Left = -1;
MenuInfo->Top = 4;
}
//
// The other margins are the same
//
/* The other margins are the same */
MenuInfo->Right = (MenuInfo->Left) + Width;
MenuInfo->Bottom = (MenuInfo->Top) + Height;
}
@ -234,24 +181,16 @@ TuiDrawMenu(PUI_MENU_INFO MenuInfo)
{
ULONG i;
//
// Draw the backdrop
//
/* Draw the backdrop */
UiDrawBackdrop();
//
// Update the status bar
//
/* Update the status bar */
UiVtbl.DrawStatusText("Use \x18 and \x19 to select, then press ENTER.");
//
// Draw the menu box
//
/* Draw the menu box */
TuiDrawMenuBox(MenuInfo);
//
// Draw each line of the menu
//
/* Draw each line of the menu */
for (i = 0; i < MenuInfo->MenuItemCount; i++)
{
TuiDrawMenuItem(MenuInfo, i);
@ -272,9 +211,7 @@ TuiDrawMenuBox(PUI_MENU_INFO MenuInfo)
CHAR MenuLineText[80], TempString[80];
ULONG i;
//
// Draw the menu box if requested
//
/* Draw the menu box if requested */
if (UiMenuBox)
{
UiDrawBox(MenuInfo->Left,
@ -283,43 +220,31 @@ TuiDrawMenuBox(PUI_MENU_INFO MenuInfo)
MenuInfo->Bottom,
D_VERT,
D_HORZ,
FALSE, // Filled
TRUE, // Shadow
FALSE, // Filled
TRUE, // Shadow
ATTR(UiMenuFgColor, UiMenuBgColor));
}
//
// If there is a timeout draw the time remaining
//
/* If there is a timeout draw the time remaining */
if (MenuInfo->MenuTimeRemaining >= 0)
{
//
// Copy the integral time text string, and remove the last 2 chars
//
/* Copy the integral time text string, and remove the last 2 chars */
strcpy(TempString, UiTimeText);
i = (ULONG)strlen(TempString);
TempString[i - 2] = 0;
//
// Display the first part of the string and the remaining time
//
/* Display the first part of the string and the remaining time */
strcpy(MenuLineText, TempString);
_itoa(MenuInfo->MenuTimeRemaining, TempString, 10);
strcat(MenuLineText, TempString);
//
// Add the last 2 chars
//
/* Add the last 2 chars */
strcat(MenuLineText, &UiTimeText[i - 2]);
//
// Check if this is a centered menu
//
/* Check if this is a centered menu */
if (UiCenterMenu)
{
//
// Display it in the center of the menu
//
/* Display it in the center of the menu */
UiDrawText(MenuInfo->Right - (ULONG)strlen(MenuLineText) - 1,
MenuInfo->Bottom,
MenuLineText,
@ -327,9 +252,7 @@ TuiDrawMenuBox(PUI_MENU_INFO MenuInfo)
}
else
{
//
// Display under the menu directly
//
/* Display under the menu directly */
UiDrawText(0,
MenuInfo->Bottom + 4,
MenuLineText,
@ -338,18 +261,14 @@ TuiDrawMenuBox(PUI_MENU_INFO MenuInfo)
}
else
{
//
// Erase the timeout string with spaces, and 0-terminate for sure
//
for (i=0; i<sizeof(MenuLineText)-1; i++)
/* Erase the timeout string with spaces, and 0-terminate for sure */
for (i = 0; i < sizeof(MenuLineText)-1; i++)
{
MenuLineText[i] = ' ';
}
MenuLineText[sizeof(MenuLineText)-1] = 0;
//
// Draw this "empty" string to erase
//
/* Draw this "empty" string to erase */
if (UiCenterMenu)
{
UiDrawText(MenuInfo->Right - (ULONG)strlen(MenuLineText) - 1,
@ -366,19 +285,13 @@ TuiDrawMenuBox(PUI_MENU_INFO MenuInfo)
}
}
//
// Loop each item
//
/* Loop each item */
for (i = 0; i < MenuInfo->MenuItemCount; i++)
{
//
// Check if it's a separator
//
/* Check if it's a separator */
if (MenuInfo->MenuItemList[i] == NULL)
{
//
// Draw the separator line
//
/* Draw the separator line */
UiDrawText(MenuInfo->Left,
MenuInfo->Top + i + 1,
"\xC7",
@ -396,76 +309,62 @@ TuiDrawMenuItem(PUI_MENU_INFO MenuInfo,
ULONG MenuItemNumber)
{
ULONG i;
CHAR MenuLineText[80];
CHAR MenuLineText[80];
ULONG SpaceTotal;
ULONG SpaceLeft;
ULONG SpaceRight = 0;
UCHAR Attribute = ATTR(UiTextColor, UiMenuBgColor);
//
// Check if using centered menu
//
/* Check if using centered menu */
if (UiCenterMenu)
{
//
// We will want the string centered so calculate
// how many spaces will be to the left and right
//
/*
* 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;
SpaceRight = (SpaceTotal - SpaceLeft) + 1;
//
// Insert the spaces on the left
//
/* Insert the spaces on the left */
for (i = 0; i < SpaceLeft; i++) MenuLineText[i] = ' ';
MenuLineText[i] = '\0';
}
else
{
//
// Simply left-align it
//
/* Simply left-align it */
MenuLineText[0] = '\0';
strcat(MenuLineText, " ");
}
//
// Now append the text string
//
/* Now append the text string */
if (MenuInfo->MenuItemList[MenuItemNumber])
strcat(MenuLineText, MenuInfo->MenuItemList[MenuItemNumber]);
//
// Check if using centered menu, and add spaces on the right if so
//
if (UiCenterMenu) for (i=0; i < SpaceRight; i++) strcat(MenuLineText, " ");
/* Check if using centered menu, and add spaces on the right if so */
if (UiCenterMenu)
{
for (i = 0; i < SpaceRight; i++)
strcat(MenuLineText, " ");
}
//
// If it is a separator
//
/* If it is a separator */
if (MenuInfo->MenuItemList[MenuItemNumber] == NULL)
{
//
// Make it a separator line and use menu colors
//
/* 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 this is the selected item, use the selected colors
//
/* If this is the selected item, use the selected colors */
Attribute = ATTR(UiSelectedTextColor, UiSelectedTextBgColor);
}
//
// Draw the item
//
/* Draw the item */
UiDrawText(MenuInfo->Left + 1,
MenuInfo->Top + 1 + MenuItemNumber,
MenuLineText,
@ -479,70 +378,52 @@ TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo,
ULONG KeyEvent = 0;
ULONG Selected, Count;
//
// Check for a keypress
//
/* Check for a keypress */
if (!MachConsKbHit())
return 0; // None, bail out
//
// Check if the timeout is not already complete
//
/* Check if the timeout is not already complete */
if (MenuInfo->MenuTimeRemaining != -1)
{
//
// Cancel it and remove it
//
/* Cancel it and remove it */
MenuInfo->MenuTimeRemaining = -1;
TuiDrawMenuBox(MenuInfo); // FIXME: Remove for minimal UI too
}
//
// Get the key (get the extended key if needed)
//
/* Get the key (get the extended key if needed) */
KeyEvent = MachConsGetCh();
if (KeyEvent == KEY_EXTENDED)
KeyEvent = MachConsGetCh();
//
// Call the supplied key filter callback function to see
// if it is going to handle this keypress.
//
/*
* Call the supplied key filter callback function to see
* if it is going to handle this keypress.
*/
if (KeyPressFilter &&
KeyPressFilter(KeyEvent, MenuInfo->SelectedMenuItem, MenuInfo->Context))
{
//
// It processed the key character, so redraw and exit
//
/* It processed the key character, so redraw and exit */
UiVtbl.DrawMenu(MenuInfo);
return 0;
}
//
// Process the key
//
/* Process the key */
if ((KeyEvent == KEY_UP ) || (KeyEvent == KEY_DOWN) ||
(KeyEvent == KEY_HOME) || (KeyEvent == KEY_END ))
{
//
// Get the current selected item and count
//
/* Get the current selected item and count */
Selected = MenuInfo->SelectedMenuItem;
Count = MenuInfo->MenuItemCount - 1;
//
// Check the key and change the selected menu item
//
/* Check the key and change the selected menu item */
if ((KeyEvent == KEY_UP) && (Selected > 0))
{
//
// Deselect previous item and go up
//
/* Deselect previous item and go up */
MenuInfo->SelectedMenuItem--;
TuiDrawMenuItem(MenuInfo, Selected);
Selected--;
// Skip past any separators
/* Skip past any separators */
if ((Selected > 0) &&
(MenuInfo->MenuItemList[Selected] == NULL))
{
@ -552,22 +433,18 @@ TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo,
else if ( ((KeyEvent == KEY_UP) && (Selected == 0)) ||
(KeyEvent == KEY_END) )
{
//
// Go to the end
//
/* Go to the end */
MenuInfo->SelectedMenuItem = Count;
TuiDrawMenuItem(MenuInfo, Selected);
}
else if ((KeyEvent == KEY_DOWN) && (Selected < Count))
{
//
// Deselect previous item and go down
//
/* Deselect previous item and go down */
MenuInfo->SelectedMenuItem++;
TuiDrawMenuItem(MenuInfo, Selected);
Selected++;
// Skip past any separators
/* Skip past any separators */
if ((Selected < Count) &&
(MenuInfo->MenuItemList[Selected] == NULL))
{
@ -577,23 +454,18 @@ TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo,
else if ( ((KeyEvent == KEY_DOWN) && (Selected == Count)) ||
(KeyEvent == KEY_HOME) )
{
//
// Go to the beginning
//
/* Go to the beginning */
MenuInfo->SelectedMenuItem = 0;
TuiDrawMenuItem(MenuInfo, Selected);
}
//
// Select new item and update video buffer
//
/* Select new item and update video buffer */
TuiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem);
VideoCopyOffScreenBufferToVRAM();
}
//
// Return the pressed key
//
/* Return the pressed key */
return KeyEvent;
}
#endif