aboutsummaryrefslogtreecommitdiffstats
path: root/UefiMonitorTest/SettingsMenu.c
blob: 659f397e3c8c58d2d6cb2eed7a321c2237b2ca3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#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
SettingsMenuDoit (
  IN UMT_CONTEXT *Ctx
  )
{

}

VOID
SettingsMenuTip (
  IN UMT_CONTEXT *Ctx
  )
{
  EFI_STATUS Status;

  Status = SetGraphicsMode (Ctx->Graphics, mModeNumber);
  if (EFI_ERROR(Status))
    return;

  SettingsMenuInit (Ctx); 
}

VOID
SettingsChangeParam (
  IN  UMT_CONTEXT *Ctx,
  IN  INT8        ParamStep
  )
{
  
}

VOID
SettingsMenuChangeValue (
  IN  UMT_CONTEXT *Ctx,
  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); 
}