- Added support for NTLDR style freeloader GUI. To enable, edit freeldr.ini and add:
[reactos.git] / reactos / boot / freeldr / freeldr / ui / ui.c
index 1c21029..299f817 100644 (file)
  */
 
 #include <freeldr.h>
-#include <ui.h>
-#include "tui.h"
-#include <rtl.h>
-#include <mm.h>
-#include <machine.h>
+
+#define NDEBUG
 #include <debug.h>
-#include <inifile.h>
-#include <version.h>
-#include <video.h>
+
 
 ULONG  UiScreenWidth = 80;                                                     // Screen Width
 ULONG  UiScreenHeight = 25;                                                    // Screen Height
@@ -55,8 +50,13 @@ BOOL UserInterfaceUp                         = FALSE;                                // Tells us if the user interface is display
 VIDEODISPLAYMODE       UiDisplayMode           = VideoTextMode;                // Tells us if we are in text or graphics mode
 
 BOOL   UiUseSpecialEffects                     = FALSE;                                // Tells us if we should use fade effects
+BOOL   UiDrawTime                                      = TRUE;                                 // Tells us if we should draw the time
+BOOL   UiMinimal                                       = FALSE;                                // Tells us if we should use a minimal console-like UI
+BOOL   UiCenterMenu                            = TRUE;                                 // Tells us if we should use a centered or left-aligned menu
+BOOL   UiMenuBox                                       = TRUE;                                 // Tells us if we shuld draw a box around the menu
+CHAR   UiTimeText[260] = "[Time Remaining: ] ";
 
-CHAR   UiMonthNames[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
+const CHAR     UiMonthNames[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
 
 
 BOOL UiInitialize(BOOLEAN ShowGui)
@@ -92,6 +92,10 @@ BOOL UiInitialize(BOOLEAN ShowGui)
                {
                        strcpy(UiTitleBoxTitleText, SettingText);
                }
+               if (IniReadSettingByName(SectionId, "TimeText", SettingText, 260))
+               {
+                       strcpy(UiTimeText, SettingText);
+               }
                if (IniReadSettingByName(SectionId, "StatusBarColor", SettingText, 260))
                {
                        UiStatusBarBgColor = UiTextToColor(SettingText);
@@ -158,7 +162,7 @@ BOOL UiInitialize(BOOLEAN ShowGui)
                }
                if (IniReadSettingByName(SectionId, "SpecialEffects", SettingText, 260))
                {
-                       if (stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
+                       if (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
                        {
                                UiUseSpecialEffects = TRUE;
                        }
@@ -167,6 +171,50 @@ BOOL UiInitialize(BOOLEAN ShowGui)
                                UiUseSpecialEffects = FALSE;
                        }
                }
+               if (IniReadSettingByName(SectionId, "ShowTime", SettingText, 260))
+               {
+                       if (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
+                       {
+                               UiDrawTime = TRUE;
+                       }
+                       else
+                       {
+                               UiDrawTime = FALSE;
+                       }
+               }
+               if (IniReadSettingByName(SectionId, "MinimalUI", SettingText, 260))
+               {
+                       if (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
+                       {
+                               UiMinimal = TRUE;
+                       }
+                       else
+                       {
+                               UiMinimal = FALSE;
+                       }
+               }
+               if (IniReadSettingByName(SectionId, "MenuBox", SettingText, 260))
+               {
+                       if (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
+                       {
+                               UiMenuBox = TRUE;
+                       }
+                       else
+                       {
+                               UiMenuBox = FALSE;
+                       }
+               }
+               if (IniReadSettingByName(SectionId, "CenterMenu", SettingText, 260))
+               {
+                       if (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
+                       {
+                               UiCenterMenu = TRUE;
+                       }
+                       else
+                       {
+                               UiCenterMenu = FALSE;
+                       }
+               }
        }
 
        UiDisplayMode = MachVideoSetDisplayMode(DisplayModeText, TRUE);
@@ -196,12 +244,45 @@ BOOL UiInitialize(BOOLEAN ShowGui)
 
        UserInterfaceUp = TRUE;
 
+       DbgPrint((DPRINT_UI, "UiInitialize() returning TRUE.\n"));
+       return TRUE;
+}
+
+BOOL SetupUiInitialize(VOID)
+{
+
+       CHAR    DisplayModeText[260];
+       ULONG   Depth;
+
+       
+       DisplayModeText[0] = '\0';
+       
+
+       UiDisplayMode = MachVideoSetDisplayMode(DisplayModeText, TRUE);
+       MachVideoGetDisplaySize(&UiScreenWidth, &UiScreenHeight, &Depth);
+
+       TuiInitialize();
+
+       // Draw the backdrop and fade it in if special effects are enabled
+       TuiFillArea(0,
+                       0,
+                       UiScreenWidth - 1,
+                       UiScreenHeight - 2,
+                       0,
+                       ATTR(UiBackdropFgColor, UiBackdropBgColor));
+
+    UiStatusBarBgColor = 7;
+       UserInterfaceUp = TRUE;
+    
+    TuiDrawText(4, 1, "ReactOS " KERNEL_VERSION_STR " Setup", ATTR(COLOR_GRAY, UiBackdropBgColor));
+    TuiDrawText(3, 2, "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD", ATTR(COLOR_GRAY, UiBackdropBgColor));
+
        DbgPrint((DPRINT_UI, "UiInitialize() returning TRUE.\n"));
 
        return TRUE;
 }
 
-VOID UiUnInitialize(PCHAR BootText)
+VOID UiUnInitialize(PCSTR BootText)
 {
        UiDrawBackdrop();
        UiDrawStatusText("Booting...");
@@ -272,7 +353,7 @@ VOID UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle
        }
 }
 
-VOID UiDrawText(ULONG X, ULONG Y, PCHAR Text, UCHAR Attr)
+VOID UiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr)
 {
        if (VideoTextMode == UiDisplayMode)
        {
@@ -285,7 +366,7 @@ VOID UiDrawText(ULONG X, ULONG Y, PCHAR Text, UCHAR Attr)
        }
 }
 
-VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCHAR TextString, UCHAR Attr)
+VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr)
 {
        if (VideoTextMode == UiDisplayMode)
        {
@@ -298,7 +379,7 @@ VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCHAR
        }
 }
 
-VOID UiDrawStatusText(PCHAR StatusText)
+VOID UiDrawStatusText(PCSTR StatusText)
 {
        if (!UserInterfaceUp) return;
 
@@ -326,7 +407,7 @@ VOID UiUpdateDateTime(VOID)
        }
 }
 
-VOID UiInfoBox(PCHAR MessageText)
+VOID UiInfoBox(PCSTR MessageText)
 {
        ULONG           TextLength;
        ULONG           BoxWidth;
@@ -387,7 +468,7 @@ VOID UiInfoBox(PCHAR MessageText)
        UiDrawCenteredText(Left, Top, Right, Bottom, MessageText, ATTR(UiTextColor, UiMenuBgColor));
 }
 
-VOID UiMessageBox(PCHAR MessageText)
+VOID UiMessageBox(PCSTR MessageText)
 {
        // We have not yet displayed the user interface
        // We are probably still reading the .ini file
@@ -412,7 +493,7 @@ VOID UiMessageBox(PCHAR MessageText)
        }
 }
 
-VOID UiMessageBoxCritical(PCHAR MessageText)
+VOID UiMessageBoxCritical(PCSTR MessageText)
 {
        // We have not yet displayed the user interface
        // We are probably still reading the .ini file
@@ -437,7 +518,7 @@ VOID UiMessageBoxCritical(PCHAR MessageText)
        }
 }
 
-UCHAR UiTextToColor(PCHAR ColorText)
+UCHAR UiTextToColor(PCSTR ColorText)
 {
        if (VideoTextMode == UiDisplayMode)
        {
@@ -451,7 +532,7 @@ UCHAR UiTextToColor(PCHAR ColorText)
        }
 }
 
-UCHAR UiTextToFillStyle(PCHAR FillStyleText)
+UCHAR UiTextToFillStyle(PCSTR FillStyleText)
 {
        if (VideoTextMode == UiDisplayMode)
        {
@@ -493,7 +574,7 @@ VOID UiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG P
        }
 }
 
-VOID UiShowMessageBoxesInSection(PCHAR SectionName)
+VOID UiShowMessageBoxesInSection(PCSTR SectionName)
 {
        ULONG           Idx;
        CHAR    SettingName[80];
@@ -516,7 +597,7 @@ VOID UiShowMessageBoxesInSection(PCHAR SectionName)
        {
                IniReadSettingByNumber(SectionId, Idx, SettingName, 79, SettingValue, 79);
 
-               if (stricmp(SettingName, "MessageBox") == 0)
+               if (_stricmp(SettingName, "MessageBox") == 0)
                {
                        // Get the real length of the MessageBox text
                        MessageBoxTextSize = IniGetSectionSettingValueSize(SectionId, Idx);
@@ -571,7 +652,7 @@ VOID UiTruncateStringEllipsis(PCHAR StringText, ULONG MaxChars)
        }
 }
 
-BOOL UiDisplayMenu(PCHAR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOL CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter)
+BOOL UiDisplayMenu(PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOL CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter)
 {
        if (VideoTextMode == UiDisplayMode)
        {
@@ -611,7 +692,7 @@ VOID UiFadeOut(VOID)
        }
 }
 
-BOOL UiEditBox(PCHAR MessageText, PCHAR EditTextBuffer, ULONG Length)
+BOOL UiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
 {
        if (VideoTextMode == UiDisplayMode)
        {