📄 ui.c
字号:
/*
* FreeLoader
* Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <freeldr.h>
#include <debug.h>
ULONG UiScreenWidth = 80; // Screen Width
ULONG UiScreenHeight = 25; // 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 UserInterfaceUp = FALSE; // Tells us if the user interface is displayed
VIDEODISPLAYMODE UiDisplayMode = VideoTextMode; // Tells us if we are in text or graphics mode
BOOLEAN UiUseSpecialEffects = FALSE; // Tells us if we should use fade effects
BOOLEAN UiDrawTime = TRUE; // Tells us if we should draw the time
BOOLEAN UiMinimal = FALSE; // Tells us if we should use a minimal console-like UI
BOOLEAN UiCenterMenu = TRUE; // Tells us if we should use a centered or left-aligned menu
BOOLEAN UiMenuBox = TRUE; // Tells us if we shuld draw a box around the menu
CHAR UiTimeText[260] = "[Time Remaining: ] ";
const CHAR UiMonthNames[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
BOOLEAN UiInitialize(BOOLEAN ShowGui)
{
ULONG SectionId;
CHAR DisplayModeText[260];
CHAR SettingText[260];
ULONG Depth;
if (!ShowGui) {
if (!TuiInitialize())
{
MachVideoSetDisplayMode(NULL, FALSE);
return FALSE;
}
UserInterfaceUp = FALSE;
return TRUE;
}
DbgPrint((DPRINT_UI, "Initializing User Interface.\n"));
DbgPrint((DPRINT_UI, "Reading in UI settings from [Display] section.\n"));
DisplayModeText[0] = '\0';
if (IniOpenSection("Display", &SectionId))
{
if (! IniReadSettingByName(SectionId, "DisplayMode", DisplayModeText, sizeof(DisplayModeText)))
{
DisplayModeText[0] = '\0';
}
if (IniReadSettingByName(SectionId, "TitleText", SettingText, sizeof(SettingText)))
{
strcpy(UiTitleBoxTitleText, SettingText);
}
if (IniReadSettingByName(SectionId, "TimeText", SettingText, sizeof(SettingText)))
{
strcpy(UiTimeText, SettingText);
}
if (IniReadSettingByName(SectionId, "StatusBarColor", SettingText, sizeof(SettingText)))
{
UiStatusBarBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "StatusBarTextColor", SettingText, sizeof(SettingText)))
{
UiStatusBarFgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "BackdropTextColor", SettingText, sizeof(SettingText)))
{
UiBackdropFgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "BackdropColor", SettingText, sizeof(SettingText)))
{
UiBackdropBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "BackdropFillStyle", SettingText, sizeof(SettingText)))
{
UiBackdropFillStyle = UiTextToFillStyle(SettingText);
}
if (IniReadSettingByName(SectionId, "TitleBoxTextColor", SettingText, sizeof(SettingText)))
{
UiTitleBoxFgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "TitleBoxColor", SettingText, sizeof(SettingText)))
{
UiTitleBoxBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "MessageBoxTextColor", SettingText, sizeof(SettingText)))
{
UiMessageBoxFgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "MessageBoxColor", SettingText, sizeof(SettingText)))
{
UiMessageBoxBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "MenuTextColor", SettingText, sizeof(SettingText)))
{
UiMenuFgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "MenuColor", SettingText, sizeof(SettingText)))
{
UiMenuBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "TextColor", SettingText, sizeof(SettingText)))
{
UiTextColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "SelectedTextColor", SettingText, sizeof(SettingText)))
{
UiSelectedTextColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "SelectedColor", SettingText, sizeof(SettingText)))
{
UiSelectedTextBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "EditBoxTextColor", SettingText, sizeof(SettingText)))
{
UiEditBoxTextColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "EditBoxColor", SettingText, sizeof(SettingText)))
{
UiEditBoxBgColor = UiTextToColor(SettingText);
}
if (IniReadSettingByName(SectionId, "SpecialEffects", SettingText, sizeof(SettingText)))
{
if (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
{
UiUseSpecialEffects = TRUE;
}
else
{
UiUseSpecialEffects = FALSE;
}
}
if (IniReadSettingByName(SectionId, "ShowTime", SettingText, sizeof(SettingText)))
{
if (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
{
UiDrawTime = TRUE;
}
else
{
UiDrawTime = FALSE;
}
}
if (IniReadSettingByName(SectionId, "MinimalUI", SettingText, sizeof(SettingText)))
{
if (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
{
UiMinimal = TRUE;
}
else
{
UiMinimal = FALSE;
}
}
if (IniReadSettingByName(SectionId, "MenuBox", SettingText, sizeof(SettingText)))
{
if (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
{
UiMenuBox = TRUE;
}
else
{
UiMenuBox = FALSE;
}
}
if (IniReadSettingByName(SectionId, "CenterMenu", SettingText, sizeof(SettingText)))
{
if (_stricmp(SettingText, "Yes") == 0 && strlen(SettingText) == 3)
{
UiCenterMenu = TRUE;
}
else
{
UiCenterMenu = FALSE;
}
}
}
UiDisplayMode = MachVideoSetDisplayMode(DisplayModeText, TRUE);
MachVideoGetDisplaySize(&UiScreenWidth, &UiScreenHeight, &Depth);
if (VideoTextMode == UiDisplayMode)
{
if (!TuiInitialize())
{
MachVideoSetDisplayMode(NULL, FALSE);
return FALSE;
}
}
else
{
UNIMPLEMENTED();
//if (!GuiInitialize())
//{
// MachSetDisplayMode(NULL, FALSE);
// return FALSE;
//}
}
// Draw the backdrop and fade it in if special effects are enabled
UiFadeInBackdrop();
UserInterfaceUp = TRUE;
DbgPrint((DPRINT_UI, "UiInitialize() returning TRUE.\n"));
return TRUE;
}
BOOLEAN 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));
UiDrawTime = FALSE;
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(PCSTR BootText)
{
UiDrawBackdrop();
UiDrawStatusText("Booting...");
UiInfoBox(BootText);
if (VideoTextMode == UiDisplayMode)
{
TuiUnInitialize();
}
else
{
UNIMPLEMENTED();
//GuiUnInitialize();
}
}
VOID UiDrawBackdrop(VOID)
{
if (!UserInterfaceUp) return;
if (VideoTextMode == UiDisplayMode)
{
TuiDrawBackdrop();
}
else
{
UNIMPLEMENTED();
//GuiDrawBackdrop();
}
}
VOID UiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr /* Color Attributes */)
{
if (VideoTextMode == UiDisplayMode)
{
TuiFillArea(Left, Top, Right, Bottom, FillChar, Attr);
}
else
{
UNIMPLEMENTED();
//GuiFillArea(Left, Top, Right, Bottom, FillChar, Attr);
}
}
VOID UiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom)
{
if (VideoTextMode == UiDisplayMode)
{
TuiDrawShadow(Left, Top, Right, Bottom);
}
else
{
UNIMPLEMENTED();
//GuiDrawShadow(Left, Top, Right, Bottom);
}
}
VOID UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr)
{
if (VideoTextMode == UiDisplayMode)
{
TuiDrawBox(Left, Top, Right, Bottom, VertStyle, HorzStyle, Fill, Shadow, Attr);
}
else
{
UNIMPLEMENTED();
//GuiDrawBox(Left, Top, Right, Bottom, VertStyle, HorzStyle, Fill, Shadow, Attr);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -