xref: /reactos/boot/freeldr/freeldr/include/ui.h (revision 64155019)
1 /*
2  *  FreeLoader
3  *  Copyright (C) 1998-2003  Brian Palmer  <brianp@sginet.com>
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
22 extern ULONG UiScreenWidth;             // Screen Width
23 extern ULONG UiScreenHeight;            // Screen Height
24 
25 extern UCHAR UiStatusBarFgColor;        // Status bar foreground color
26 extern UCHAR UiStatusBarBgColor;        // Status bar background color
27 extern UCHAR UiBackdropFgColor;         // Backdrop foreground color
28 extern UCHAR UiBackdropBgColor;         // Backdrop background color
29 extern UCHAR UiBackdropFillStyle;       // Backdrop fill style
30 extern UCHAR UiTitleBoxFgColor;         // Title box foreground color
31 extern UCHAR UiTitleBoxBgColor;         // Title box background color
32 extern UCHAR UiMessageBoxFgColor;       // Message box foreground color
33 extern UCHAR UiMessageBoxBgColor;       // Message box background color
34 extern UCHAR UiMenuFgColor;             // Menu foreground color
35 extern UCHAR UiMenuBgColor;             // Menu background color
36 extern UCHAR UiTextColor;               // Normal text color
37 extern UCHAR UiSelectedTextColor;       // Selected text color
38 extern UCHAR UiSelectedTextBgColor;     // Selected text background color
39 extern UCHAR UiEditBoxTextColor;        // Edit box text color
40 extern UCHAR UiEditBoxBgColor;          // Edit box text background color
41 
42 extern BOOLEAN UiShowTime;              // Whether to draw the time
43 extern BOOLEAN UiMenuBox;               // Whether to draw a box around the menu
44 extern BOOLEAN UiCenterMenu;            // Whether to use a centered or left-aligned menu
45 extern BOOLEAN UiUseSpecialEffects;     // Whether to use fade effects
46 
47 extern CHAR UiTitleBoxTitleText[260];   // Title box's title text
48 extern CHAR UiTimeText[260];
49 
50 extern const PCSTR UiMonthNames[12];
51 
52 /* User Interface Functions **************************************************/
53 
54 BOOLEAN    UiInitialize(BOOLEAN ShowUi);                                // Initialize User-Interface
55 VOID    UiUnInitialize(PCSTR BootText);                        // Un-initialize User-Interface
56 VOID    UiDrawBackdrop(VOID);                                    // Fills the entire screen with a backdrop
57 VOID    UiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr /* Color Attributes */);    // Fills the area specified with FillChar and Attr
58 VOID    UiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom);    // Draws a shadow on the bottom and right sides of the area specified
59 VOID    UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr);    // Draws a box around the area specified
60 
61 /* Draws text at coordinates specified */
62 VOID
63 UiDrawText(
64     _In_ ULONG X,
65     _In_ ULONG Y,
66     _In_ PCSTR Text,
67     _In_ UCHAR Attr);
68 
69 /* Draws text at coordinates specified */
70 VOID
71 UiDrawText2(
72     _In_ ULONG X,
73     _In_ ULONG Y,
74     _In_opt_ ULONG MaxNumChars,
75     _In_reads_or_z_(MaxNumChars) PCSTR Text,
76     _In_ UCHAR Attr);
77 
78 /* Draws centered text at the coordinates specified and clips the edges */
79 VOID
80 UiDrawCenteredText(
81     _In_ ULONG Left,
82     _In_ ULONG Top,
83     _In_ ULONG Right,
84     _In_ ULONG Bottom,
85     _In_ PCSTR TextString,
86     _In_ UCHAR Attr);
87 
88 VOID    UiDrawStatusText(PCSTR StatusText);                    // Draws text at the very bottom line on the screen
89 VOID    UiUpdateDateTime(VOID);                                    // Updates the date and time
90 
91 /* Displays an info box on the screen */
92 VOID
93 UiInfoBox(
94     _In_ PCSTR MessageText);
95 
96 /* Displays a message box on the screen with an ok button */
97 VOID
98 UiMessageBox(
99     _In_ PCSTR Format, ...);
100 
101 /* Displays a message box on the screen with an ok button using no system resources */
102 VOID
103 UiMessageBoxCritical(
104     _In_ PCSTR MessageText);
105 
106 /* Loading Progress-Bar Functions ********************************************/
107 
108 /*
109  * Loading progress bar, based on the one from NTOS Inbv.
110  * Supports progress within sub-ranges, used when loading
111  * with an unknown number of steps.
112  */
113 typedef struct _UI_PROGRESS_BAR
114 {
115     // UI_PROGRESS_STATE
116     struct
117     {
118         ULONG Floor;
119         // ULONG Ceiling;
120         ULONG Bias;
121     } State;
122 
123     // BT_PROGRESS_INDICATOR
124     struct
125     {
126         ULONG Count;
127         ULONG Expected;
128         ULONG Percentage;
129     } Indicator;
130 
131     ULONG Left;
132     ULONG Top;
133     ULONG Right;
134     ULONG Bottom;
135     // ULONG Width; // == Right - Left + 1;
136     BOOLEAN Show;
137 } UI_PROGRESS_BAR, *PUI_PROGRESS_BAR;
138 
139 extern UI_PROGRESS_BAR UiProgressBar;
140 
141 VOID
142 UiInitProgressBar(
143     _In_ ULONG Left,
144     _In_ ULONG Top,
145     _In_ ULONG Right,
146     _In_ ULONG Bottom,
147     _In_ PCSTR ProgressText);
148 
149 /* Indicate loading progress without any specific number of steps */
150 VOID
151 UiIndicateProgress(VOID);
152 
153 /* Set a progress loading percentage range */
154 VOID
155 UiSetProgressBarSubset(
156     _In_ ULONG Floor,
157     _In_ ULONG Ceiling);
158 
159 /* Update the loading progress percentage within a selected range */
160 VOID
161 UiUpdateProgressBar(
162     _In_ ULONG Percentage,
163     _In_opt_ PCSTR ProgressText);
164 
165 VOID
166 UiSetProgressBarText(
167     _In_ PCSTR ProgressText);
168 
169 /* Draws the progress bar showing nPos percent filled */
170 VOID
171 UiDrawProgressBarCenter(
172     _In_ PCSTR ProgressText);
173 
174 /* Draws the progress bar showing nPos percent filled */
175 VOID
176 UiDrawProgressBar(
177     _In_ ULONG Left,
178     _In_ ULONG Top,
179     _In_ ULONG Right,
180     _In_ ULONG Bottom,
181     _In_ PCSTR ProgressText);
182 
183 
184 // Displays all the message boxes in a given section.
185 VOID
186 UiShowMessageBoxesInSection(
187     IN ULONG_PTR SectionId);
188 
189 VOID
190 UiShowMessageBoxesInArgv(
191     IN ULONG Argc,
192     IN PCHAR Argv[]);
193 
194 BOOLEAN    UiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length);
195 
196 UCHAR    UiTextToColor(PCSTR ColorText);                        // Converts the text color into it's equivalent color value
197 UCHAR    UiTextToFillStyle(PCSTR FillStyleText);                // Converts the text fill into it's equivalent fill value
198 
199 VOID    UiFadeInBackdrop(VOID);                                    // Draws the backdrop and fades the screen in
200 VOID    UiFadeOut(VOID);                                        // Fades the screen out
201 
202 /* Menu Functions ************************************************************/
203 
204 typedef struct tagUI_MENU_INFO
205 {
206     PCSTR   MenuHeader;
207     PCSTR   MenuFooter;
208     BOOLEAN ShowBootOptions;
209 
210     PCSTR*  MenuItemList;
211     ULONG   MenuItemCount;
212     LONG    MenuTimeRemaining;
213     ULONG   SelectedMenuItem;
214     PVOID   Context;
215 
216     ULONG   Left;
217     ULONG   Top;
218     ULONG   Right;
219     ULONG   Bottom;
220 } UI_MENU_INFO, *PUI_MENU_INFO;
221 
222 typedef
223 BOOLEAN
224 (*UiMenuKeyPressFilterCallback)(
225     IN ULONG KeyPress,
226     IN ULONG SelectedMenuItem,
227     IN PVOID Context OPTIONAL);
228 
229 BOOLEAN
230 UiDisplayMenu(
231     IN PCSTR MenuHeader,
232     IN PCSTR MenuFooter OPTIONAL,
233     IN BOOLEAN ShowBootOptions,
234     IN PCSTR MenuItemList[],
235     IN ULONG MenuItemCount,
236     IN ULONG DefaultMenuItem,
237     IN LONG MenuTimeOut,
238     OUT PULONG SelectedMenuItem,
239     IN BOOLEAN CanEscape,
240     IN UiMenuKeyPressFilterCallback KeyPressFilter OPTIONAL,
241     IN PVOID Context OPTIONAL);
242 
243 ///////////////////////////////////////////////////////////////////////////////////////
244 //
245 // UI virtual table
246 //
247 ///////////////////////////////////////////////////////////////////////////////////////
248 typedef struct tagUIVTBL
249 {
250     BOOLEAN (*Initialize)(VOID);
251     VOID (*UnInitialize)(VOID);
252 
253     VOID (*DrawBackdrop)(VOID);
254     VOID (*FillArea)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr);
255     VOID (*DrawShadow)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom);
256     VOID (*DrawBox)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr);
257     VOID (*DrawText)(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr);
258     VOID (*DrawText2)(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr);
259     VOID (*DrawCenteredText)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr);
260     VOID (*DrawStatusText)(PCSTR StatusText);
261     VOID (*UpdateDateTime)(VOID);
262     VOID (*MessageBox)(PCSTR MessageText);
263     VOID (*MessageBoxCritical)(PCSTR MessageText);
264 
265     VOID (*DrawProgressBarCenter)(
266         _In_ PCSTR ProgressText);
267 
268     VOID (*DrawProgressBar)(
269         _In_ ULONG Left,
270         _In_ ULONG Top,
271         _In_ ULONG Right,
272         _In_ ULONG Bottom,
273         _In_ PCSTR ProgressText);
274 
275     VOID (*SetProgressBarText)(
276         _In_ PCSTR ProgressText);
277 
278     VOID (*TickProgressBar)(
279         _In_ ULONG SubPercentTimes100);
280 
281     BOOLEAN (*EditBox)(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length);
282     UCHAR (*TextToColor)(PCSTR ColorText);
283     UCHAR (*TextToFillStyle)(PCSTR FillStyleText);
284     VOID (*FadeInBackdrop)(VOID);
285     VOID (*FadeOut)(VOID);
286 
287     BOOLEAN (*DisplayMenu)(
288         IN PCSTR MenuHeader,
289         IN PCSTR MenuFooter OPTIONAL,
290         IN BOOLEAN ShowBootOptions,
291         IN PCSTR MenuItemList[],
292         IN ULONG MenuItemCount,
293         IN ULONG DefaultMenuItem,
294         IN LONG MenuTimeOut,
295         OUT PULONG SelectedMenuItem,
296         IN BOOLEAN CanEscape,
297         IN UiMenuKeyPressFilterCallback KeyPressFilter OPTIONAL,
298         IN PVOID Context OPTIONAL);
299 
300     VOID (*DrawMenu)(PUI_MENU_INFO MenuInfo);
301 } UIVTBL, *PUIVTBL;
302 
303 VOID UiInit(const char *CmdLine);
304 
305 extern UIVTBL UiVtbl;
306 
307 /*
308  * Fill styles for DrawBackdrop()
309  */
310 #define LIGHT_FILL      0xB0
311 #define MEDIUM_FILL     0xB1
312 #define DARK_FILL       0xB2
313 
314 /*
315  * Combines the foreground and background colors into a single attribute byte
316  */
317 #define ATTR(cFore, cBack)  ((cBack << 4) | cFore)
318 
319 /*
320  * Screen colors
321  */
322 #define COLOR_BLACK         0
323 #define COLOR_BLUE          1
324 #define COLOR_GREEN         2
325 #define COLOR_CYAN          3
326 #define COLOR_RED           4
327 #define COLOR_MAGENTA       5
328 #define COLOR_BROWN         6
329 #define COLOR_GRAY          7
330 
331 #define COLOR_DARKGRAY      8
332 #define COLOR_LIGHTBLUE     9
333 #define COLOR_LIGHTGREEN    10
334 #define COLOR_LIGHTCYAN     11
335 #define COLOR_LIGHTRED      12
336 #define COLOR_LIGHTMAGENTA  13
337 #define COLOR_YELLOW        14
338 #define COLOR_WHITE         15
339 
340 /* Add COLOR_BLINK to a background to cause blinking */
341 // #define COLOR_BLINK         8
342 
343 /*
344  * Defines for IBM box drawing characters
345  */
346 #define HORZ    0xC4    // Single horizontal line
347 #define D_HORZ  0xCD    // Double horizontal line
348 #define VERT    0xB3    // Single vertical line
349 #define D_VERT  0xBA    // Double vertical line
350 
351 
352 /* THEME HEADERS *************************************************************/
353 
354 // #include <ui/gui.h>
355 #include <ui/minitui.h>
356 #include <ui/noui.h>
357 #include <ui/tui.h>
358