[FREELDR:UI] Improve setting UI colors/strings ("theme") defaults.

Now, default UI colors/strings (e.g. titles/timeout text) that are
dependent of the UI "theme" (mini vs. full TUI) are set first when
calling their corresponding Initialize() function.
Then, the user UI settings are read from the user's freeldr.ini file
and override the UI theme defaults.

These settings get effectively applied at the first drawing operation
(usually the UiFadeInBackdrop() call done by the main UiInitialize()
function).
For "directui" we don't care about the settings -- they are hardcoded.

This allows not having to specify the default settings in the
freeldr.ini files anymore.

+ Add support for "None" UiBackdropFillStyle: fill with whitespace,
  instead of the specific patterns.
This commit is contained in:
Hermès Bélusca-Maïto 2022-02-20 20:17:02 +01:00
parent 44ed4fb001
commit d215039216
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 195 additions and 131 deletions

View file

@ -39,13 +39,13 @@ extern UCHAR UiSelectedTextBgColor; // Selected text background color
extern UCHAR UiEditBoxTextColor; // Edit box text color extern UCHAR UiEditBoxTextColor; // Edit box text color
extern UCHAR UiEditBoxBgColor; // Edit box text background color extern UCHAR UiEditBoxBgColor; // Edit box text background color
extern CHAR UiTitleBoxTitleText[260]; // Title box's title text extern BOOLEAN UiShowTime; // Whether to draw the time
extern BOOLEAN UiMenuBox; // Whether to draw a box around the menu
extern BOOLEAN UiCenterMenu; // Whether to use a centered or left-aligned menu
extern BOOLEAN UiUseSpecialEffects; // Whether to use fade effects
extern BOOLEAN UiUseSpecialEffects; // Tells us if we should use fade effects extern CHAR UiTitleBoxTitleText[260]; // Title box's title text
extern BOOLEAN UiCenterMenu; extern CHAR UiTimeText[260];
extern BOOLEAN UiMenuBox;
extern CHAR UiTimeText[];
extern BOOLEAN UiDrawTime;
extern const PCSTR UiMonthNames[12]; extern const PCSTR UiMonthNames[12];

View file

@ -15,10 +15,52 @@
#ifndef _M_ARM #ifndef _M_ARM
BOOLEAN MiniTuiInitialize(VOID)
{
/* Initialize main TUI */
if (!TuiInitialize())
return FALSE;
/* Override default settings with "Mini" TUI Theme */
UiTextColor = TuiTextToColor("Default");
UiStatusBarFgColor = UiTextColor;
UiStatusBarBgColor = COLOR_BLACK;
UiBackdropFgColor = UiTextColor;
UiBackdropBgColor = COLOR_BLACK;
UiBackdropFillStyle = ' '; // TuiTextToFillStyle("None");
UiTitleBoxFgColor = COLOR_WHITE;
UiTitleBoxBgColor = COLOR_BLACK;
// UiMessageBoxFgColor = COLOR_WHITE;
// UiMessageBoxBgColor = COLOR_BLUE;
UiMenuFgColor = UiTextColor;
UiMenuBgColor = COLOR_BLACK;
UiSelectedTextColor = COLOR_BLACK;
UiSelectedTextBgColor = UiTextColor;
// UiEditBoxTextColor = COLOR_WHITE;
// UiEditBoxBgColor = COLOR_BLACK;
UiShowTime = FALSE;
UiMenuBox = FALSE;
UiCenterMenu = FALSE;
UiUseSpecialEffects = FALSE;
// TODO: Have a boolean to show/hide title box?
UiTitleBoxTitleText[0] = ANSI_NULL;
RtlStringCbCopyA(UiTimeText, sizeof(UiTimeText),
"Seconds until highlighted choice will be started automatically:");
return TRUE;
}
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,
UiBackdropFillStyle,
ATTR(UiBackdropFgColor, UiBackdropBgColor));
/* Update the screen buffer */ /* Update the screen buffer */
VideoCopyOffScreenBufferToVRAM(); VideoCopyOffScreenBufferToVRAM();
@ -206,7 +248,7 @@ MiniTuiDrawMenu(
const UIVTBL MiniTuiVtbl = const UIVTBL MiniTuiVtbl =
{ {
TuiInitialize, MiniTuiInitialize,
TuiUnInitialize, TuiUnInitialize,
MiniTuiDrawBackdrop, MiniTuiDrawBackdrop,
TuiFillArea, TuiFillArea,

View file

@ -215,6 +215,37 @@ BOOLEAN TuiInitialize(VOID)
return FALSE; return FALSE;
} }
/* Load default settings with "Full" TUI Theme */
UiStatusBarFgColor = COLOR_BLACK;
UiStatusBarBgColor = COLOR_CYAN;
UiBackdropFgColor = COLOR_WHITE;
UiBackdropBgColor = COLOR_BLUE;
UiBackdropFillStyle = MEDIUM_FILL;
UiTitleBoxFgColor = COLOR_WHITE;
UiTitleBoxBgColor = COLOR_RED;
UiMessageBoxFgColor = COLOR_WHITE;
UiMessageBoxBgColor = COLOR_BLUE;
UiMenuFgColor = COLOR_WHITE;
UiMenuBgColor = COLOR_BLUE;
UiTextColor = COLOR_YELLOW;
UiSelectedTextColor = COLOR_BLACK;
UiSelectedTextBgColor = COLOR_GRAY;
UiEditBoxTextColor = COLOR_WHITE;
UiEditBoxBgColor = COLOR_BLACK;
UiShowTime = TRUE;
UiMenuBox = TRUE;
UiCenterMenu = TRUE;
UiUseSpecialEffects = FALSE;
// TODO: Have a boolean to show/hide title box?
RtlStringCbCopyA(UiTitleBoxTitleText, sizeof(UiTitleBoxTitleText),
"Boot Menu");
RtlStringCbCopyA(UiTimeText, sizeof(UiTimeText),
"[Time Remaining: %d]");
return TRUE; return TRUE;
} }
@ -243,9 +274,7 @@ VOID TuiUnInitialize(VOID)
VOID TuiDrawBackdrop(VOID) VOID TuiDrawBackdrop(VOID)
{ {
// /* Fill in the background (excluding title box & status bar) */
// Fill in the background (excluding title box & status bar)
//
TuiFillArea(0, TuiFillArea(0,
TUI_TITLE_BOX_CHAR_HEIGHT, TUI_TITLE_BOX_CHAR_HEIGHT,
UiScreenWidth - 1, UiScreenWidth - 1,
@ -253,9 +282,7 @@ VOID TuiDrawBackdrop(VOID)
UiBackdropFillStyle, UiBackdropFillStyle,
ATTR(UiBackdropFgColor, UiBackdropBgColor)); ATTR(UiBackdropFgColor, UiBackdropBgColor));
// /* Draw the title box */
// Draw the title box
//
TuiDrawBox(0, TuiDrawBox(0,
0, 0,
UiScreenWidth - 1, UiScreenWidth - 1,
@ -266,17 +293,13 @@ VOID TuiDrawBackdrop(VOID)
FALSE, FALSE,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
// /* Draw version text */
// Draw version text
//
TuiDrawText(2, TuiDrawText(2,
1, 1,
FrLdrVersionString, FrLdrVersionString,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
// /* Draw copyright */
// Draw copyright
//
TuiDrawText(2, TuiDrawText(2,
2, 2,
BY_AUTHOR, BY_AUTHOR,
@ -286,24 +309,19 @@ VOID TuiDrawBackdrop(VOID)
AUTHOR_EMAIL, AUTHOR_EMAIL,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
// /* Draw help text */
// Draw help text TuiDrawText(UiScreenWidth - 16, 3,
// /*"F1 for Help"*/ "F8 for Options",
TuiDrawText(UiScreenWidth - 16, 3, /*"F1 for Help"*/"F8 for Options", ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
// /* Draw title text */
// Draw title text
//
TuiDrawText((UiScreenWidth - (ULONG)strlen(UiTitleBoxTitleText)) / 2, TuiDrawText((UiScreenWidth - (ULONG)strlen(UiTitleBoxTitleText)) / 2,
2, 2,
UiTitleBoxTitleText, UiTitleBoxTitleText,
ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
// /* Update the date & time */
// Update the date & time
//
TuiUpdateDateTime(); TuiUpdateDateTime();
VideoCopyOffScreenBufferToVRAM(); VideoCopyOffScreenBufferToVRAM();
} }
@ -539,7 +557,7 @@ VOID TuiUpdateDateTime(VOID)
CHAR Buffer[40]; CHAR Buffer[40];
/* Don't draw the time if this has been disabled */ /* Don't draw the time if this has been disabled */
if (!UiDrawTime) return; if (!UiShowTime) return;
TimeInfo = ArcGetTime(); TimeInfo = ArcGetTime();
if (TimeInfo->Year < 1 || 9999 < TimeInfo->Year || if (TimeInfo->Year < 1 || 9999 < TimeInfo->Year ||
@ -874,7 +892,7 @@ UCHAR TuiTextToColor(PCSTR ColorText)
if (_stricmp(ColorText, "Default") == 0) if (_stricmp(ColorText, "Default") == 0)
return MachDefaultTextColor; return MachDefaultTextColor;
for (i = 0; i < sizeof(Colors)/sizeof(Colors[0]); ++i) for (i = 0; i < RTL_NUMBER_OF(Colors); ++i)
{ {
if (_stricmp(ColorText, Colors[i].ColorName) == 0) if (_stricmp(ColorText, Colors[i].ColorName) == 0)
return Colors[i].ColorValue; return Colors[i].ColorValue;
@ -891,13 +909,14 @@ UCHAR TuiTextToFillStyle(PCSTR FillStyleText)
UCHAR FillStyleValue; UCHAR FillStyleValue;
} FillStyles[] = } FillStyles[] =
{ {
{"None" , ' '},
{"Light" , LIGHT_FILL }, {"Light" , LIGHT_FILL },
{"Medium", MEDIUM_FILL}, {"Medium", MEDIUM_FILL},
{"Dark" , DARK_FILL }, {"Dark" , DARK_FILL },
}; };
ULONG i; ULONG i;
for (i = 0; i < sizeof(FillStyles)/sizeof(FillStyles[0]); ++i) for (i = 0; i < RTL_NUMBER_OF(FillStyles); ++i)
{ {
if (_stricmp(FillStyleText, FillStyles[i].FillStyleName) == 0) if (_stricmp(FillStyleText, FillStyles[i].FillStyleName) == 0)
return FillStyles[i].FillStyleValue; return FillStyles[i].FillStyleValue;

View file

@ -24,38 +24,38 @@ DBG_DEFAULT_CHANNEL(UI);
#ifndef _M_ARM #ifndef _M_ARM
UCHAR UiStatusBarFgColor; // Status bar foreground color
UCHAR UiStatusBarBgColor; // Status bar background color
UCHAR UiBackdropFgColor; // Backdrop foreground color
UCHAR UiBackdropBgColor; // Backdrop background color
UCHAR UiBackdropFillStyle; // Backdrop fill style
UCHAR UiTitleBoxFgColor; // Title box foreground color
UCHAR UiTitleBoxBgColor; // Title box background color
UCHAR UiMessageBoxFgColor; // Message box foreground color
UCHAR UiMessageBoxBgColor; // Message box background color
UCHAR UiMenuFgColor; // Menu foreground color
UCHAR UiMenuBgColor; // Menu background color
UCHAR UiTextColor; // Normal text color
UCHAR UiSelectedTextColor; // Selected text color
UCHAR UiSelectedTextBgColor; // Selected text background color
UCHAR UiEditBoxTextColor; // Edit box text color
UCHAR UiEditBoxBgColor; // Edit box text background color
BOOLEAN UiShowTime; // Whether to draw the time
BOOLEAN UiMenuBox; // Whether to draw a box around the menu
BOOLEAN UiCenterMenu; // Whether to use a centered or left-aligned menu
BOOLEAN UiUseSpecialEffects; // Whether to use fade effects
CHAR UiTitleBoxTitleText[260] = "Boot Menu"; // Title box's title text
CHAR UiTimeText[260] = "[Time Remaining: %d]";
const PCSTR UiMonthNames[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
#define TAG_UI_TEXT 'xTiU' #define TAG_UI_TEXT 'xTiU'
ULONG UiScreenWidth; // Screen Width ULONG UiScreenWidth; // Screen Width
ULONG UiScreenHeight; // Screen Height ULONG UiScreenHeight; // Screen Height
UCHAR UiStatusBarFgColor = COLOR_BLACK; // Status bar foreground color
UCHAR UiStatusBarBgColor = COLOR_CYAN; // Status bar background color
UCHAR UiBackdropFgColor = COLOR_WHITE; // Backdrop foreground color
UCHAR UiBackdropBgColor = COLOR_BLUE; // Backdrop background color
UCHAR UiBackdropFillStyle = MEDIUM_FILL; // Backdrop fill style
UCHAR UiTitleBoxFgColor = COLOR_WHITE; // Title box foreground color
UCHAR UiTitleBoxBgColor = COLOR_RED; // Title box background color
UCHAR UiMessageBoxFgColor = COLOR_WHITE; // Message box foreground color
UCHAR UiMessageBoxBgColor = COLOR_BLUE; // Message box background color
UCHAR UiMenuFgColor = COLOR_WHITE; // Menu foreground color
UCHAR UiMenuBgColor = COLOR_BLUE; // Menu background color
UCHAR UiTextColor = COLOR_YELLOW; // Normal text color
UCHAR UiSelectedTextColor = COLOR_BLACK; // Selected text color
UCHAR UiSelectedTextBgColor = COLOR_GRAY; // Selected text background color
UCHAR UiEditBoxTextColor = COLOR_WHITE; // Edit box text color
UCHAR UiEditBoxBgColor = COLOR_BLACK; // Edit box text background color
CHAR UiTitleBoxTitleText[260] = "Boot Menu"; // Title box's title text
BOOLEAN UiUseSpecialEffects = FALSE; // Tells us if we should use fade effects
BOOLEAN UiDrawTime = TRUE; // Tells us if we should draw the time
BOOLEAN UiCenterMenu = TRUE; // Tells us if we should use a centered or left-aligned menu
BOOLEAN UiMenuBox = TRUE; // Tells us if we should draw a box around the menu
CHAR UiTimeText[260] = "[Time Remaining: %d]";
const PCSTR UiMonthNames[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
#endif // _M_ARM #endif // _M_ARM
/* /*
@ -132,7 +132,7 @@ BOOLEAN UiInitialize(BOOLEAN ShowUi)
/* Select the UI */ /* Select the UI */
if ((SectionId != 0) && IniReadSettingByName(SectionId, "MinimalUI", SettingText, sizeof(SettingText))) if ((SectionId != 0) && IniReadSettingByName(SectionId, "MinimalUI", SettingText, sizeof(SettingText)))
{ {
UiMinimal = (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3); UiMinimal = (_stricmp(SettingText, "Yes") == 0);
} }
if (UiDisplayMode == VideoGraphicsMode) if (UiDisplayMode == VideoGraphicsMode)
@ -148,51 +148,53 @@ BOOLEAN UiInitialize(BOOLEAN ShowUi)
else // if (UiDisplayMode == VideoTextMode) else // if (UiDisplayMode == VideoTextMode)
UiVtbl = (UiMinimal ? MiniTuiVtbl : TuiVtbl); UiVtbl = (UiMinimal ? MiniTuiVtbl : TuiVtbl);
/* Load the UI and initialize its default settings */
if (!UiVtbl.Initialize()) if (!UiVtbl.Initialize())
{ {
MachVideoSetDisplayMode(NULL, FALSE); MachVideoSetDisplayMode(NULL, FALSE);
return FALSE; return FALSE;
} }
/* Load the settings */ /* Load the user UI settings */
if (SectionId != 0) if (SectionId != 0)
{ {
static const struct static const struct
{ {
PCSTR SettingName; PCSTR SettingName;
PVOID SettingVar; PVOID SettingVar;
SIZE_T SettingSize OPTIONAL; // Must be non-zero only for text buffers.
UCHAR SettingType; // 0: Text, 1: Yes/No, 2: Color, 3: Fill style UCHAR SettingType; // 0: Text, 1: Yes/No, 2: Color, 3: Fill style
} Settings[] = } Settings[] =
{ {
{"TitleText", &UiTitleBoxTitleText, 0}, {"TitleText", &UiTitleBoxTitleText, sizeof(UiTitleBoxTitleText), 0},
{"TimeText" , &UiTimeText , 0}, {"TimeText" , &UiTimeText, sizeof(UiTimeText), 0},
{"SpecialEffects", &UiUseSpecialEffects, 1}, {"ShowTime" , &UiShowTime , 0, 1},
{"ShowTime" , &UiDrawTime , 1}, {"MenuBox" , &UiMenuBox , 0, 1},
{"MenuBox" , &UiMenuBox , 1}, {"CenterMenu" , &UiCenterMenu , 0, 1},
{"CenterMenu" , &UiCenterMenu , 1}, {"SpecialEffects", &UiUseSpecialEffects, 0, 1},
{"BackdropColor" , &UiBackdropBgColor , 2}, {"BackdropColor" , &UiBackdropBgColor , 0, 2},
{"BackdropTextColor" , &UiBackdropFgColor , 2}, {"BackdropTextColor" , &UiBackdropFgColor , 0, 2},
{"StatusBarColor" , &UiStatusBarBgColor , 2}, {"StatusBarColor" , &UiStatusBarBgColor , 0, 2},
{"StatusBarTextColor" , &UiStatusBarFgColor , 2}, {"StatusBarTextColor" , &UiStatusBarFgColor , 0, 2},
{"TitleBoxColor" , &UiTitleBoxBgColor , 2}, {"TitleBoxColor" , &UiTitleBoxBgColor , 0, 2},
{"TitleBoxTextColor" , &UiTitleBoxFgColor , 2}, {"TitleBoxTextColor" , &UiTitleBoxFgColor , 0, 2},
{"MessageBoxColor" , &UiMessageBoxBgColor , 2}, {"MessageBoxColor" , &UiMessageBoxBgColor , 0, 2},
{"MessageBoxTextColor", &UiMessageBoxFgColor , 2}, {"MessageBoxTextColor", &UiMessageBoxFgColor , 0, 2},
{"MenuColor" , &UiMenuBgColor , 2}, {"MenuColor" , &UiMenuBgColor , 0, 2},
{"MenuTextColor" , &UiMenuFgColor , 2}, {"MenuTextColor" , &UiMenuFgColor , 0, 2},
{"TextColor" , &UiTextColor , 2}, {"TextColor" , &UiTextColor , 0, 2},
{"SelectedColor" , &UiSelectedTextBgColor, 2}, {"SelectedColor" , &UiSelectedTextBgColor, 0, 2},
{"SelectedTextColor" , &UiSelectedTextColor , 2}, {"SelectedTextColor" , &UiSelectedTextColor , 0, 2},
{"EditBoxColor" , &UiEditBoxBgColor , 2}, {"EditBoxColor" , &UiEditBoxBgColor , 0, 2},
{"EditBoxTextColor" , &UiEditBoxTextColor , 2}, {"EditBoxTextColor" , &UiEditBoxTextColor , 0, 2},
{"BackdropFillStyle", &UiBackdropFillStyle, 3}, {"BackdropFillStyle", &UiBackdropFillStyle, 0, 3},
}; };
ULONG i; ULONG i;
for (i = 0; i < sizeof(Settings)/sizeof(Settings[0]); ++i) for (i = 0; i < RTL_NUMBER_OF(Settings); ++i)
{ {
if (!IniReadSettingByName(SectionId, Settings[i].SettingName, SettingText, sizeof(SettingText))) if (!IniReadSettingByName(SectionId, Settings[i].SettingName, SettingText, sizeof(SettingText)))
continue; continue;
@ -200,10 +202,11 @@ BOOLEAN UiInitialize(BOOLEAN ShowUi)
switch (Settings[i].SettingType) switch (Settings[i].SettingType)
{ {
case 0: // Text case 0: // Text
strcpy((PCHAR)Settings[i].SettingVar, SettingText); RtlStringCbCopyA((PCHAR)Settings[i].SettingVar,
Settings[i].SettingSize, SettingText);
break; break;
case 1: // Yes/No case 1: // Yes/No
*(PBOOLEAN)Settings[i].SettingVar = (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3); *(PBOOLEAN)Settings[i].SettingVar = (_stricmp(SettingText, "Yes") == 0);
break; break;
case 2: // Color case 2: // Color
*(PUCHAR)Settings[i].SettingVar = UiTextToColor(SettingText); *(PUCHAR)Settings[i].SettingVar = UiTextToColor(SettingText);