[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

@ -186,11 +186,6 @@ VOID UiInit(const char *CmdLine);
extern UIVTBL UiVtbl; 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() * Fill styles for DrawBackdrop()
*/ */
@ -198,6 +193,11 @@ extern UIVTBL UiVtbl;
#define MEDIUM_FILL 0xB1 #define MEDIUM_FILL 0xB1
#define DARK_FILL 0xB2 #define DARK_FILL 0xB2
/*
* Combines the foreground and background colors into a single attribute byte
*/
#define ATTR(cFore, cBack) ((cBack << 4) | cFore)
/* /*
* Screen colors * Screen colors
*/ */
@ -220,12 +220,12 @@ extern UIVTBL UiVtbl;
#define COLOR_WHITE 15 #define COLOR_WHITE 15
/* Add COLOR_BLINK to a background to cause blinking */ /* Add COLOR_BLINK to a background to cause blinking */
//#define COLOR_BLINK 8 // #define COLOR_BLINK 8
/* /*
* Defines for IBM box drawing characters * Defines for IBM box drawing characters
*/ */
#define HORZ (0xc4) /* Single horizontal line */ #define HORZ 0xC4 // Single horizontal line
#define D_HORZ (0xcd) /* Double horizontal line.*/ #define D_HORZ 0xCD // Double horizontal line
#define VERT (0xb3) /* Single vertical line */ #define VERT 0xB3 // Single vertical line
#define D_VERT (0xba) /* Double vertical line. */ #define D_VERT 0xBA // Double vertical line

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -156,25 +156,20 @@ VOID TuiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer; PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
ULONG i, j; ULONG i, j;
// Clip the area to the screen /* Clip the area to the screen */
if ((Left >= UiScreenWidth) || (Top >= UiScreenHeight)) if ((Left >= UiScreenWidth) || (Top >= UiScreenHeight))
{ {
return; return;
} }
if (Right >= UiScreenWidth) if (Right >= UiScreenWidth)
{
Right = UiScreenWidth - 1; Right = UiScreenWidth - 1;
}
if (Bottom >= UiScreenHeight) if (Bottom >= UiScreenHeight)
{
Bottom = UiScreenHeight - 1; Bottom = UiScreenHeight - 1;
}
// Loop through each line and fill it in /* Loop through each line and column and fill it in */
for (i=Top; i<=Bottom; i++) 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)] = (UCHAR)FillChar;
ScreenMemory[((i*2)*UiScreenWidth)+(j*2)+1] = Attr; ScreenMemory[((i*2)*UiScreenWidth)+(j*2)+1] = Attr;
@ -191,25 +186,21 @@ VOID TuiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom)
PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer; PUCHAR ScreenMemory = (PUCHAR)TextVideoBuffer;
ULONG Idx; ULONG Idx;
// Shade the bottom of the area /* Shade the bottom of the area */
if (Bottom < (UiScreenHeight - 1)) if (Bottom < (UiScreenHeight - 1))
{ {
if (UiScreenHeight < 34) if (UiScreenHeight < 34)
{ Idx = Left + 2;
Idx=Left + 2;
}
else 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); 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)) if (Right < (UiScreenWidth - 1))
{ {
for (Idx=Top+1; Idx<=Bottom; Idx++) 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))) if ((Right < (UiScreenWidth - 1)) && (Bottom < (UiScreenHeight - 1)))
{ {
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);
@ -666,32 +657,29 @@ VOID TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG
ULONG i; ULONG i;
ULONG ProgressBarWidth = (Right - Left) - 3; 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); UiTruncateStringEllipsis(ProgressText, ProgressBarWidth - 4);
if (Position > Range) if (Position > Range)
{
Position = Range; Position = Range;
}
// Draw the box /* Draw the box */
TuiDrawBox(Left, Top, Right, Bottom, VERT, HORZ, TRUE, TRUE, ATTR(UiMenuFgColor, UiMenuBgColor)); 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)); TuiDrawCenteredText(Left + 2, Top + 2, Right - 2, Top + 2, ProgressText, ATTR(UiTextColor, UiMenuBgColor));
// Draw the percent complete /* Draw the percent complete */
for (i=0; i<(Position*ProgressBarWidth)/Range; i++) 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 /* Draw the shadow */
for (; i<ProgressBarWidth; i++) 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(); TuiUpdateDateTime();

View file

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