aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2022-05-12 11:45:34 +0300
committerJoursoir <chat@joursoir.net>2022-05-12 11:45:34 +0300
commit545f9d83e634129b3295f2b98fd7b71f01e55965 (patch)
treed1b36090c5f0bf94e31c8bb5534d03b30a87f320
parent072a1226b09d5372a34b962b126f687f38755477 (diff)
downloadumt-545f9d83e634129b3295f2b98fd7b71f01e55965.tar.gz
umt-545f9d83e634129b3295f2b98fd7b71f01e55965.tar.bz2
umt-545f9d83e634129b3295f2b98fd7b71f01e55965.zip
implement settings menu
-rw-r--r--UefiMonitorTest/SettingsMenu.c116
-rw-r--r--UefiMonitorTest/UefiMonitorTestStrings.uni8
2 files changed, 123 insertions, 1 deletions
diff --git a/UefiMonitorTest/SettingsMenu.c b/UefiMonitorTest/SettingsMenu.c
index 211353d..659f397 100644
--- a/UefiMonitorTest/SettingsMenu.c
+++ b/UefiMonitorTest/SettingsMenu.c
@@ -1,13 +1,113 @@
#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
#include "SettingsMenu.h"
+#define INDENT 15
+#define RECT_HALF_WIDTH 160
+#define RECT_HALF_HEIGHT 28
+
+STATIC UINT32 mModeNumber = 0;
+
+STATIC
+EFI_STATUS
+SetGraphicsMode (
+ IN GRAPHICS_CONTEXT *Graphics,
+ IN UINT32 ModeNumber
+ )
+{
+ EFI_STATUS Status;
+
+ ASSERT (Graphics != NULL);
+
+ if (Graphics->Gop->Mode->Mode == ModeNumber)
+ return EFI_SUCCESS;
+
+ Status = Graphics->Gop->SetMode (Graphics->Gop, ModeNumber);
+ if (!EFI_ERROR (Status)) {
+ ForgetGraphicsInfo (Graphics);
+ PrepareGraphicsInfo (Graphics, Graphics->Gop);
+ }
+ return Status;
+}
+
+STATIC
+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *
+GetGraphicsModeInfo (
+ IN GRAPHICS_CONTEXT *Graphics,
+ IN UINT32 ModeNumber
+ )
+{
+ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeInfo;
+ EFI_STATUS Status;
+ UINTN SizeOfInfo;
+
+ if (ModeNumber >= Graphics->Gop->Mode->MaxMode)
+ return NULL;
+
+ Status = Graphics->Gop->QueryMode(Graphics->Gop, ModeNumber, &SizeOfInfo, &ModeInfo);
+ if (EFI_ERROR(Status)) {
+ ModeInfo = NULL;
+ }
+ return ModeInfo;
+}
+
VOID
SettingsMenuInit (
IN UMT_CONTEXT *Ctx
)
{
+ GRAPHICS_CONTEXT *Graphics;
+ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeInfo;
+ UINT32 Width;
+ UINT32 Height;
+ UINTN FontHeight;
+ UINTN FontWidth;
+ UINTN Y;
+
+ Graphics = Ctx->Graphics;
+ Width = Graphics->Width;
+ Height = Graphics->Height;
+ GetFontParameters (Graphics, &FontWidth, &FontHeight);
+
+ // Background
+ Y = Height / 2 - RECT_HALF_HEIGHT;
+ PutRect (Graphics, 0, 0, Width, Height, &gUmtColors[UMT_COLOR_NAVY].Color);
+ DrawHiiStringF (Graphics,
+ (Width - 13 * FontWidth) / 2,
+ Y - (INDENT * 2),
+ &gUmtColors[UMT_COLOR_WHITE].Color,
+ STRING_TOKEN (STR_SM_TITLE), gUmtHiiHandle);
+
+ // Menu
+ DrawRoundedRect (Graphics,
+ Width / 2 - RECT_HALF_WIDTH,
+ Height / 2 - RECT_HALF_HEIGHT,
+ Width / 2 + RECT_HALF_WIDTH,
+ Height / 2 + RECT_HALF_HEIGHT,
+ 20,
+ &gUmtColors[UMT_COLOR_WHITE].Color
+ );
+ ModeInfo = GetGraphicsModeInfo (Graphics, mModeNumber);
+ ASSERT (ModeInfo != NULL);
+
+ Y += INDENT + 5;
+ DrawHiiStringF (Graphics,
+ Width / 2 - RECT_HALF_WIDTH + INDENT,
+ Y,
+ &gUmtColors[UMT_COLOR_BLACK].Color,
+ STRING_TOKEN (STR_SM_RESOLUTION_TITLE), gUmtHiiHandle);
+ DrawHiiStringF (Graphics,
+ Width / 2 + INDENT,
+ Y,
+ &gUmtColors[UMT_COLOR_BLACK].Color,
+ STRING_TOKEN (STR_SM_RESOLUTION_OPTION), gUmtHiiHandle,
+ ModeInfo->HorizontalResolution,
+ ModeInfo->VerticalResolution,
+ (Graphics->Gop->Mode->Mode == mModeNumber) ? L'*' : L' ');
+
+ FreePool (ModeInfo);
}
VOID
@@ -23,7 +123,13 @@ SettingsMenuTip (
IN UMT_CONTEXT *Ctx
)
{
+ EFI_STATUS Status;
+
+ Status = SetGraphicsMode (Ctx->Graphics, mModeNumber);
+ if (EFI_ERROR(Status))
+ return;
+ SettingsMenuInit (Ctx);
}
VOID
@@ -41,5 +147,13 @@ SettingsMenuChangeValue (
IN INT8 ValueStep
)
{
-
+ if (mModeNumber == 0 && ValueStep < 0)
+ mModeNumber = Ctx->Graphics->Gop->Mode->MaxMode - 1;
+ else {
+ mModeNumber += ValueStep;
+ if (mModeNumber >= Ctx->Graphics->Gop->Mode->MaxMode)
+ mModeNumber = 0;
+ }
+
+ SettingsMenuInit (Ctx);
}
diff --git a/UefiMonitorTest/UefiMonitorTestStrings.uni b/UefiMonitorTest/UefiMonitorTestStrings.uni
index 52ce002..f82e4df 100644
--- a/UefiMonitorTest/UefiMonitorTestStrings.uni
+++ b/UefiMonitorTest/UefiMonitorTestStrings.uni
@@ -49,6 +49,14 @@
"the test or exit from\n"
"application."
+// Settings Menu
+
+#string STR_SM_TITLE #language en-US "SETTINGS MENU"
+
+#string STR_SM_RESOLUTION_TITLE #language en-US "Resolution:"
+
+#string STR_SM_RESOLUTION_OPTION #language en-US "< %4d x %4d%c >"
+
// Test "Solid Colors"
#string STR_SOLID_COLORS_TITLE #language en-US "DEFECTIVE PIXELS ON %s"