[FREELDR:UI] Improve setting UI colors/strings ("theme") defaults.
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 20 Feb 2022 19:17:02 +0000 (20:17 +0100)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Mon, 21 Feb 2022 01:54:03 +0000 (02:54 +0100)
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.

boot/freeldr/freeldr/include/ui.h
boot/freeldr/freeldr/ui/minitui.c
boot/freeldr/freeldr/ui/tui.c
boot/freeldr/freeldr/ui/ui.c

index d278155..7a7e5cf 100644 (file)
 
 #pragma once
 
-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 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 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 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 CHAR UiTitleBoxTitleText[260];   // Title box's title text
+extern CHAR UiTimeText[260];
 
 extern const PCSTR UiMonthNames[12];
 
index 694072f..872b9aa 100644 (file)
 
 #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)
 {
     /* 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 */
     VideoCopyOffScreenBufferToVRAM();
@@ -206,7 +248,7 @@ MiniTuiDrawMenu(
 
 const UIVTBL MiniTuiVtbl =
 {
-    TuiInitialize,
+    MiniTuiInitialize,
     TuiUnInitialize,
     MiniTuiDrawBackdrop,
     TuiFillArea,
index 4c3a1ee..be9cb22 100644 (file)
@@ -215,6 +215,37 @@ BOOLEAN TuiInitialize(VOID)
         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;
 }
 
@@ -243,67 +274,54 @@ VOID TuiUnInitialize(VOID)
 
 VOID TuiDrawBackdrop(VOID)
 {
-    //
-    // Fill in the background (excluding title box & status bar)
-    //
+    /* Fill in the background (excluding title box & status bar) */
     TuiFillArea(0,
-            TUI_TITLE_BOX_CHAR_HEIGHT,
-            UiScreenWidth - 1,
-            UiScreenHeight - 2,
-            UiBackdropFillStyle,
-            ATTR(UiBackdropFgColor, UiBackdropBgColor));
+                TUI_TITLE_BOX_CHAR_HEIGHT,
+                UiScreenWidth - 1,
+                UiScreenHeight - 2,
+                UiBackdropFillStyle,
+                ATTR(UiBackdropFgColor, UiBackdropBgColor));
 
-    //
-    // Draw the title box
-    //
+    /* Draw the title box */
     TuiDrawBox(0,
-            0,
-            UiScreenWidth - 1,
-            TUI_TITLE_BOX_CHAR_HEIGHT - 1,
-            D_VERT,
-            D_HORZ,
-            TRUE,
-            FALSE,
-            ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
-
-    //
-    // Draw version text
-    //
+               0,
+               UiScreenWidth - 1,
+               TUI_TITLE_BOX_CHAR_HEIGHT - 1,
+               D_VERT,
+               D_HORZ,
+               TRUE,
+               FALSE,
+               ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
+
+    /* Draw version text */
     TuiDrawText(2,
-            1,
-            FrLdrVersionString,
-            ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
+                1,
+                FrLdrVersionString,
+                ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
 
-    //
-    // Draw copyright
-    //
+    /* Draw copyright */
     TuiDrawText(2,
-            2,
-            BY_AUTHOR,
-            ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
+                2,
+                BY_AUTHOR,
+                ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
     TuiDrawText(2,
-            3,
-            AUTHOR_EMAIL,
-            ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
+                3,
+                AUTHOR_EMAIL,
+                ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
 
-    //
-    // Draw help text
-    //
-    TuiDrawText(UiScreenWidth - 16, 3, /*"F1 for Help"*/"F8 for Options", ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
+    /* Draw help text */
+    TuiDrawText(UiScreenWidth - 16, 3,
+                /*"F1 for Help"*/ "F8 for Options",
+                ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
 
-    //
-    // Draw title text
-    //
+    /* Draw title text */
     TuiDrawText((UiScreenWidth - (ULONG)strlen(UiTitleBoxTitleText)) / 2,
-            2,
-            UiTitleBoxTitleText,
-            ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
+                2,
+                UiTitleBoxTitleText,
+                ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor));
 
-    //
-    // Update the date & time
-    //
+    /* Update the date & time */
     TuiUpdateDateTime();
-
     VideoCopyOffScreenBufferToVRAM();
 }
 
@@ -539,7 +557,7 @@ VOID TuiUpdateDateTime(VOID)
     CHAR Buffer[40];
 
     /* Don't draw the time if this has been disabled */
-    if (!UiDrawTime) return;
+    if (!UiShowTime) return;
 
     TimeInfo = ArcGetTime();
     if (TimeInfo->Year < 1 || 9999 < TimeInfo->Year ||
@@ -874,7 +892,7 @@ UCHAR TuiTextToColor(PCSTR ColorText)
     if (_stricmp(ColorText, "Default") == 0)
         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)
             return Colors[i].ColorValue;
@@ -891,13 +909,14 @@ UCHAR TuiTextToFillStyle(PCSTR FillStyleText)
         UCHAR FillStyleValue;
     } FillStyles[] =
     {
+        {"None"  , ' '},
         {"Light" , LIGHT_FILL },
         {"Medium", MEDIUM_FILL},
         {"Dark"  , DARK_FILL  },
     };
     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)
             return FillStyles[i].FillStyleValue;
index 49636ea..78ea2f1 100644 (file)
@@ -24,38 +24,38 @@ DBG_DEFAULT_CHANNEL(UI);
 
 #ifndef _M_ARM
 
-#define TAG_UI_TEXT 'xTiU'
-
-ULONG UiScreenWidth;    // Screen Width
-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
+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
-
-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]";
+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'
+
+ULONG UiScreenWidth;    // Screen Width
+ULONG UiScreenHeight;   // Screen Height
+
 #endif // _M_ARM
 
 /*
@@ -132,7 +132,7 @@ BOOLEAN UiInitialize(BOOLEAN ShowUi)
     /* Select the UI */
     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)
@@ -148,51 +148,53 @@ BOOLEAN UiInitialize(BOOLEAN ShowUi)
     else // if (UiDisplayMode == VideoTextMode)
         UiVtbl = (UiMinimal ? MiniTuiVtbl : TuiVtbl);
 
+    /* Load the UI and initialize its default settings */
     if (!UiVtbl.Initialize())
     {
         MachVideoSetDisplayMode(NULL, FALSE);
         return FALSE;
     }
 
-    /* Load the settings */
+    /* Load the user UI settings */
     if (SectionId != 0)
     {
         static const struct
         {
             PCSTR SettingName;
             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
         } Settings[] =
         {
-            {"TitleText", &UiTitleBoxTitleText, 0},
-            {"TimeText" , &UiTimeText         , 0},
-
-            {"SpecialEffects", &UiUseSpecialEffects, 1},
-            {"ShowTime"      , &UiDrawTime         , 1},
-            {"MenuBox"       , &UiMenuBox          , 1},
-            {"CenterMenu"    , &UiCenterMenu       , 1},
-
-            {"BackdropColor"      , &UiBackdropBgColor    , 2},
-            {"BackdropTextColor"  , &UiBackdropFgColor    , 2},
-            {"StatusBarColor"     , &UiStatusBarBgColor   , 2},
-            {"StatusBarTextColor" , &UiStatusBarFgColor   , 2},
-            {"TitleBoxColor"      , &UiTitleBoxBgColor    , 2},
-            {"TitleBoxTextColor"  , &UiTitleBoxFgColor    , 2},
-            {"MessageBoxColor"    , &UiMessageBoxBgColor  , 2},
-            {"MessageBoxTextColor", &UiMessageBoxFgColor  , 2},
-            {"MenuColor"          , &UiMenuBgColor        , 2},
-            {"MenuTextColor"      , &UiMenuFgColor        , 2},
-            {"TextColor"          , &UiTextColor          , 2},
-            {"SelectedColor"      , &UiSelectedTextBgColor, 2},
-            {"SelectedTextColor"  , &UiSelectedTextColor  , 2},
-            {"EditBoxColor"       , &UiEditBoxBgColor     , 2},
-            {"EditBoxTextColor"   , &UiEditBoxTextColor   , 2},
-
-            {"BackdropFillStyle", &UiBackdropFillStyle, 3},
+            {"TitleText", &UiTitleBoxTitleText, sizeof(UiTitleBoxTitleText), 0},
+            {"TimeText" , &UiTimeText, sizeof(UiTimeText), 0},
+
+            {"ShowTime"      , &UiShowTime         , 0, 1},
+            {"MenuBox"       , &UiMenuBox          , 0, 1},
+            {"CenterMenu"    , &UiCenterMenu       , 0, 1},
+            {"SpecialEffects", &UiUseSpecialEffects, 0, 1},
+
+            {"BackdropColor"      , &UiBackdropBgColor    , 0, 2},
+            {"BackdropTextColor"  , &UiBackdropFgColor    , 0, 2},
+            {"StatusBarColor"     , &UiStatusBarBgColor   , 0, 2},
+            {"StatusBarTextColor" , &UiStatusBarFgColor   , 0, 2},
+            {"TitleBoxColor"      , &UiTitleBoxBgColor    , 0, 2},
+            {"TitleBoxTextColor"  , &UiTitleBoxFgColor    , 0, 2},
+            {"MessageBoxColor"    , &UiMessageBoxBgColor  , 0, 2},
+            {"MessageBoxTextColor", &UiMessageBoxFgColor  , 0, 2},
+            {"MenuColor"          , &UiMenuBgColor        , 0, 2},
+            {"MenuTextColor"      , &UiMenuFgColor        , 0, 2},
+            {"TextColor"          , &UiTextColor          , 0, 2},
+            {"SelectedColor"      , &UiSelectedTextBgColor, 0, 2},
+            {"SelectedTextColor"  , &UiSelectedTextColor  , 0, 2},
+            {"EditBoxColor"       , &UiEditBoxBgColor     , 0, 2},
+            {"EditBoxTextColor"   , &UiEditBoxTextColor   , 0, 2},
+
+            {"BackdropFillStyle", &UiBackdropFillStyle, 0, 3},
         };
         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)))
                 continue;
@@ -200,10 +202,11 @@ BOOLEAN UiInitialize(BOOLEAN ShowUi)
             switch (Settings[i].SettingType)
             {
             case 0: // Text
-                strcpy((PCHAR)Settings[i].SettingVar, SettingText);
+                RtlStringCbCopyA((PCHAR)Settings[i].SettingVar,
+                                 Settings[i].SettingSize, SettingText);
                 break;
             case 1: // Yes/No
-                *(PBOOLEAN)Settings[i].SettingVar = (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3);
+                *(PBOOLEAN)Settings[i].SettingVar = (_stricmp(SettingText, "Yes") == 0);
                 break;
             case 2: // Color
                 *(PUCHAR)Settings[i].SettingVar = UiTextToColor(SettingText);