aboutsummaryrefslogtreecommitdiffstats
path: root/UefiMonitorTest/tests/ChessBoard.c
blob: 7b3b976cb2b38d5404814be712dff7cfc4cc8c12 (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
#include <Library/DebugLib.h>
#include <Library/HiiLib.h>
#include <Library/MemoryAllocationLib.h>

#include "tests/ChessBoard.h"

STATIC UINT32 CurrentSideLength = 1;

VOID
ChessBoardTestInit (
  IN UMT_CONTEXT *Ctx
  )
{
  UINT32 I;
  UINT32 J;
  enum UMT_COLORS ColorSquare;
  enum UMT_COLORS FirstColorSquare;
  enum UMT_COLORS TempColor;
  GRAPHICS_CONTEXT *Graphics = Ctx->Graphics;

  FirstColorSquare = UMT_COLOR_WHITE;
  ColorSquare      = UMT_COLOR_BLACK;

  for (J = 0; J < Graphics->Height; J += CurrentSideLength)
  {
    TempColor = FirstColorSquare;
    FirstColorSquare = ColorSquare;
    ColorSquare = TempColor;

    for (I = 0; I < Graphics->Width; I += CurrentSideLength)
    {
      PutRect (Graphics,
               I,
               J,
               I + CurrentSideLength,
               J + CurrentSideLength,
               &gUmtColors[ColorSquare].Color);

      ColorSquare = ((ColorSquare == UMT_COLOR_WHITE) ? UMT_COLOR_BLACK : UMT_COLOR_WHITE);
    }
  }

  if (Ctx->ShowTip) {
    ChessBoardTestTip (Ctx);
  }
}

VOID
ChessBoardTestDoit (
  IN UMT_CONTEXT *Ctx
  )
{

}

VOID
ChessBoardTestTip (
  IN UMT_CONTEXT *Ctx
  )
{
  GRAPHICS_CONTEXT *Graphics;

  Graphics = Ctx->Graphics;

  if (Ctx->ShowTip == FALSE) {
    // Restore
    ChessBoardTestInit (Ctx);
    return;
  }

  DrawRectWithBorder (Graphics,
                      15,
                      Graphics->Height - 15 - 124,
                      430, Graphics->Height - 15,
                      3,
                      &gUmtColors[UMT_COLOR_WHITE].Color,
                      &gUmtColors[UMT_COLOR_NAVY].Color);

  DrawHiiStringF (Graphics,
                  25,
                  Graphics->Height - 15 - 114,
                  &gUmtColors[UMT_COLOR_NAVY].Color,
                  STRING_TOKEN (STR_CHESSBOARD_TITLE), gUmtHiiHandle);

  DrawHiiStringF (Graphics,
                  25,
                  Graphics->Height - 15 - 94,
                  &gUmtColors[UMT_COLOR_BLACK].Color,
                  STRING_TOKEN (STR_CHESSBOARD_MSG), gUmtHiiHandle,
                  CurrentSideLength);
}

VOID
ChessBoardTestChangeParam (
  IN  UMT_CONTEXT *Ctx,
  IN  INT8        ParamStep
  )
{

}

VOID
ChessBoardTestChangeValue (
  IN  UMT_CONTEXT *Ctx,
  IN  INT8        ValueStep
  )
{
  UINT32 ValueOut;
  UINT32 Height;
  UINT32 Width;

  Height   = Ctx->Graphics->Height;
  Width    = Ctx->Graphics->Width;
  ValueOut = CurrentSideLength + ValueStep;

  if (ValueOut == 0) {
    return;
  }

  while ((((Width / ValueOut) * ValueOut != Width) ||
         ((Height / ValueOut) * ValueOut != Height)) &&
         ((ValueOut < Height) && (ValueOut < Width)) &&
         (ValueOut > 1))
  {
    ValueOut += ValueStep;
  }

  if ((ValueOut >= Height) || (ValueOut >= Width))
  {
    return;
  }

  CurrentSideLength = ValueOut;
  ChessBoardTestInit (Ctx);
}