[FREELDR] Some enhancements for the UI code. (#1763)
[reactos.git] / boot / freeldr / freeldr / ui / minitui.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: FreeLoader
4 * FILE: boot/freeldr/freeldr/ui/minitui.c
5 * PURPOSE: Mini Text UI interface
6 * PROGRAMMERS: Brian Palmer <brianp@sginet.com>
7 * Hervé Poussineau
8 */
9 #ifndef _M_ARM
10 #include <freeldr.h>
11
12 VOID MiniTuiDrawBackdrop(VOID)
13 {
14 //
15 // Fill in a black background
16 //
17 TuiFillArea(0, 0, UiScreenWidth - 1, UiScreenHeight - 1, 0, 0);
18
19 //
20 // Update the screen buffer
21 //
22 VideoCopyOffScreenBufferToVRAM();
23 }
24
25 VOID MiniTuiDrawStatusText(PCSTR StatusText)
26 {
27 //
28 // Minimal UI doesn't have a status bar
29 //
30 }
31
32 VOID MiniTuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
33 {
34 ULONG Left, Top, Right, Bottom;
35 ULONG Width = 50; // Allow for 50 "bars"
36 ULONG Height = 2;
37
38 Width = 80;
39 Left = 0;
40 Right = Left + Width;
41 Top = UiScreenHeight - Height - 4;
42 Bottom = Top + Height + 1;
43
44 MiniTuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range, ProgressText);
45 }
46
47 VOID MiniTuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText)
48 {
49 ULONG i;
50 ULONG ProgressBarWidth = (Right - Left) - 4;
51
52 // First make sure the progress bar text fits
53 UiTruncateStringEllipsis(ProgressText, ProgressBarWidth - 4);
54
55 if (Position > Range)
56 {
57 Position = Range;
58 }
59
60 //
61 // Draw the "Loading..." text
62 //
63 TuiDrawCenteredText(Left + 2, Top + 1, Right - 2, Top + 1, ProgressText, ATTR(7, 0));
64
65 // Draw the percent complete
66 for (i=0; i<(Position*ProgressBarWidth)/Range; i++)
67 {
68 TuiDrawText(Left+2+i, Top+2, "\xDB", ATTR(UiTextColor, UiMenuBgColor));
69 }
70
71 TuiUpdateDateTime();
72 VideoCopyOffScreenBufferToVRAM();
73 }
74
75 VOID
76 MiniTuiDrawMenu(PUI_MENU_INFO MenuInfo)
77 {
78 ULONG i;
79
80 //
81 // Draw the backdrop
82 //
83 UiDrawBackdrop();
84
85 //
86 // No GUI status bar text, just minimal text. Show the menu header.
87 //
88 if (MenuInfo->MenuHeader)
89 {
90 UiVtbl.DrawText(0,
91 MenuInfo->Top - 2,
92 MenuInfo->MenuHeader,
93 ATTR(UiMenuFgColor, UiMenuBgColor));
94 }
95
96 //
97 // Now tell the user how to choose
98 //
99 UiVtbl.DrawText(0,
100 MenuInfo->Bottom + 1,
101 "Use \x18 and \x19 to move the highlight to your choice.",
102 ATTR(UiMenuFgColor, UiMenuBgColor));
103 UiVtbl.DrawText(0,
104 MenuInfo->Bottom + 2,
105 "Press ENTER to choose.",
106 ATTR(UiMenuFgColor, UiMenuBgColor));
107
108 //
109 // And show the menu footer
110 //
111 if (MenuInfo->MenuFooter)
112 {
113 UiVtbl.DrawText(0,
114 UiScreenHeight - 4,
115 MenuInfo->MenuFooter,
116 ATTR(UiMenuFgColor, UiMenuBgColor));
117 }
118
119 //
120 // Draw the menu box
121 //
122 TuiDrawMenuBox(MenuInfo);
123
124 //
125 // Draw each line of the menu
126 //
127 for (i = 0; i < MenuInfo->MenuItemCount; i++)
128 {
129 TuiDrawMenuItem(MenuInfo, i);
130 }
131
132 //
133 // Display the boot options if needed
134 //
135 if (MenuInfo->ShowBootOptions)
136 {
137 DisplayBootTimeOptions();
138 }
139
140 VideoCopyOffScreenBufferToVRAM();
141 }
142
143 const UIVTBL MiniTuiVtbl =
144 {
145 TuiInitialize,
146 TuiUnInitialize,
147 MiniTuiDrawBackdrop,
148 TuiFillArea,
149 TuiDrawShadow,
150 TuiDrawBox,
151 TuiDrawText,
152 TuiDrawText2,
153 TuiDrawCenteredText,
154 MiniTuiDrawStatusText,
155 TuiUpdateDateTime,
156 TuiMessageBox,
157 TuiMessageBoxCritical,
158 MiniTuiDrawProgressBarCenter,
159 MiniTuiDrawProgressBar,
160 TuiEditBox,
161 TuiTextToColor,
162 TuiTextToFillStyle,
163 MiniTuiDrawBackdrop, /* no FadeIn */
164 TuiFadeOut,
165 TuiDisplayMenu,
166 MiniTuiDrawMenu,
167 };
168 #endif