]> code.delx.au - refind/blob - refind/menu.c
Improved submenu and information menu appearance over a full-screen
[refind] / refind / menu.c
1 /*
2 * refit/menu.c
3 * Menu functions
4 *
5 * Copyright (c) 2006 Christoph Pfisterer
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
18 * distribution.
19 *
20 * * Neither the name of Christoph Pfisterer nor the names of the
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36 /*
37 * Modifications copyright (c) 2012 Roderick W. Smith
38 *
39 * Modifications distributed under the terms of the GNU General Public
40 * License (GPL) version 3 (GPLv3), a copy of which must be distributed
41 * with this source code or binaries made from it.
42 *
43 */
44
45 #include "global.h"
46 #include "screen.h"
47 #include "lib.h"
48 #include "menu.h"
49 #include "config.h"
50 #include "libeg.h"
51 #include "libegint.h"
52 #include "../include/refit_call_wrapper.h"
53
54 #include "../include/egemb_back_selected_small.h"
55 #include "../include/egemb_arrow_left.h"
56 #include "../include/egemb_arrow_right.h"
57
58 // other menu definitions
59
60 #define MENU_FUNCTION_INIT (0)
61 #define MENU_FUNCTION_CLEANUP (1)
62 #define MENU_FUNCTION_PAINT_ALL (2)
63 #define MENU_FUNCTION_PAINT_SELECTION (3)
64 #define MENU_FUNCTION_PAINT_TIMEOUT (4)
65 #define MENU_FUNCTION_PAINT_HINTS (5)
66
67 typedef VOID (*MENU_STYLE_FUNC)(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINTN Function, IN CHAR16 *ParamText);
68
69 static CHAR16 ArrowUp[2] = { ARROW_UP, 0 };
70 static CHAR16 ArrowDown[2] = { ARROW_DOWN, 0 };
71
72 // Text and icon spacing constants....
73 #define TEXT_YMARGIN (2)
74 #define TEXT_XMARGIN (8)
75 #define TEXT_LINE_HEIGHT (FONT_CELL_HEIGHT + TEXT_YMARGIN * 2)
76 #define TITLEICON_SPACING (16)
77
78 #define ROW0_TILESIZE (144)
79 #define ROW1_TILESIZE (64)
80 #define TILE_XSPACING (8)
81 #define TILE_YSPACING (16)
82
83 // Alignment values for PaintIcon()
84 #define ALIGN_RIGHT 1
85 #define ALIGN_LEFT 0
86
87 static EG_IMAGE *SelectionImages[2] = { NULL, NULL };
88 static EG_PIXEL SelectionBackgroundPixel = { 0xff, 0xff, 0xff, 0 };
89
90 //
91 // Graphics helper functions
92 //
93
94 static VOID InitSelection(VOID)
95 {
96 UINTN x, y, src_x, src_y;
97 EG_PIXEL *DestPtr, *SrcPtr;
98
99 if (!AllowGraphicsMode)
100 return;
101 if (SelectionImages[0] != NULL)
102 return;
103
104 // load small selection image
105 if (GlobalConfig.SelectionSmallFileName != NULL) {
106 SelectionImages[1] = egLoadImage(SelfDir, GlobalConfig.SelectionSmallFileName, TRUE);
107 }
108 if (SelectionImages[1] == NULL)
109 SelectionImages[1] = egPrepareEmbeddedImage(&egemb_back_selected_small, TRUE);
110 SelectionImages[1] = egEnsureImageSize(SelectionImages[1],
111 ROW1_TILESIZE, ROW1_TILESIZE, &MenuBackgroundPixel);
112 if (SelectionImages[1] == NULL)
113 return;
114
115 // load big selection image
116 if (GlobalConfig.SelectionBigFileName != NULL) {
117 SelectionImages[0] = egLoadImage(SelfDir, GlobalConfig.SelectionBigFileName, TRUE);
118 SelectionImages[0] = egEnsureImageSize(SelectionImages[0],
119 ROW0_TILESIZE, ROW0_TILESIZE, &MenuBackgroundPixel);
120 }
121 if (SelectionImages[0] == NULL) {
122 // calculate big selection image from small one
123
124 SelectionImages[0] = egCreateImage(ROW0_TILESIZE, ROW0_TILESIZE, TRUE);
125 if (SelectionImages[0] == NULL) {
126 egFreeImage(SelectionImages[1]);
127 SelectionImages[1] = NULL;
128 return;
129 }
130
131 DestPtr = SelectionImages[0]->PixelData;
132 SrcPtr = SelectionImages[1]->PixelData;
133 for (y = 0; y < ROW0_TILESIZE; y++) {
134 if (y < (ROW1_TILESIZE >> 1))
135 src_y = y;
136 else if (y < (ROW0_TILESIZE - (ROW1_TILESIZE >> 1)))
137 src_y = (ROW1_TILESIZE >> 1);
138 else
139 src_y = y - (ROW0_TILESIZE - ROW1_TILESIZE);
140
141 for (x = 0; x < ROW0_TILESIZE; x++) {
142 if (x < (ROW1_TILESIZE >> 1))
143 src_x = x;
144 else if (x < (ROW0_TILESIZE - (ROW1_TILESIZE >> 1)))
145 src_x = (ROW1_TILESIZE >> 1);
146 else
147 src_x = x - (ROW0_TILESIZE - ROW1_TILESIZE);
148
149 *DestPtr++ = SrcPtr[src_y * ROW1_TILESIZE + src_x];
150 }
151 }
152 }
153 } // VOID InitSelection()
154
155 //
156 // Scrolling functions
157 //
158
159 static VOID InitScroll(OUT SCROLL_STATE *State, IN UINTN ItemCount, IN UINTN VisibleSpace)
160 {
161 State->PreviousSelection = State->CurrentSelection = 0;
162 State->MaxIndex = (INTN)ItemCount - 1;
163 State->FirstVisible = 0;
164 if (AllowGraphicsMode) {
165 State->MaxVisible = UGAWidth / (ROW0_TILESIZE + TILE_XSPACING) - 1;
166 } else
167 State->MaxVisible = ConHeight - 4;
168 if ((VisibleSpace > 0) && (VisibleSpace < State->MaxVisible))
169 State->MaxVisible = (INTN)VisibleSpace;
170 State->PaintAll = TRUE;
171 State->PaintSelection = FALSE;
172
173 State->LastVisible = State->FirstVisible + State->MaxVisible - 1;
174 }
175
176 // Adjust variables relating to the scrolling of tags, for when a selected icon isn't
177 // visible given the current scrolling condition....
178 static VOID AdjustScrollState(IN SCROLL_STATE *State) {
179 if (State->CurrentSelection > State->LastVisible) {
180 State->LastVisible = State->CurrentSelection;
181 State->FirstVisible = 1 + State->CurrentSelection - State->MaxVisible;
182 if (State->FirstVisible < 0) // shouldn't happen, but just in case....
183 State->FirstVisible = 0;
184 State->PaintAll = TRUE;
185 } // Scroll forward
186 if (State->CurrentSelection < State->FirstVisible) {
187 State->FirstVisible = State->CurrentSelection;
188 State->LastVisible = State->CurrentSelection + State->MaxVisible - 1;
189 State->PaintAll = TRUE;
190 } // Scroll backward
191 } // static VOID AdjustScrollState
192
193 static VOID UpdateScroll(IN OUT SCROLL_STATE *State, IN UINTN Movement)
194 {
195 State->PreviousSelection = State->CurrentSelection;
196
197 switch (Movement) {
198 case SCROLL_LINE_LEFT:
199 if (State->CurrentSelection > 0) {
200 State->CurrentSelection --;
201 }
202 break;
203
204 case SCROLL_LINE_RIGHT:
205 if (State->CurrentSelection < State->MaxIndex) {
206 State->CurrentSelection ++;
207 }
208 break;
209
210 case SCROLL_LINE_UP:
211 if (State->ScrollMode == SCROLL_MODE_ICONS) {
212 if (State->CurrentSelection >= State->InitialRow1) {
213 if (State->MaxIndex > State->InitialRow1) { // avoid division by 0!
214 State->CurrentSelection = State->FirstVisible + (State->LastVisible - State->FirstVisible) *
215 (State->CurrentSelection - State->InitialRow1) /
216 (State->MaxIndex - State->InitialRow1);
217 } else {
218 State->CurrentSelection = State->FirstVisible;
219 } // if/else
220 } // if in second row
221 } else {
222 if (State->CurrentSelection > 0)
223 State->CurrentSelection--;
224 } // if/else
225 break;
226
227 case SCROLL_LINE_DOWN:
228 if (State->ScrollMode == SCROLL_MODE_ICONS) {
229 if (State->CurrentSelection <= State->FinalRow0) {
230 if (State->LastVisible > State->FirstVisible) { // avoid division by 0!
231 State->CurrentSelection = State->InitialRow1 + (State->MaxIndex - State->InitialRow1) *
232 (State->CurrentSelection - State->FirstVisible) /
233 (State->LastVisible - State->FirstVisible);
234 } else {
235 State->CurrentSelection = State->InitialRow1;
236 } // if/else
237 } // if in first row
238 } else {
239 if (State->CurrentSelection < State->MaxIndex)
240 State->CurrentSelection++;
241 } // if/else
242 break;
243
244 case SCROLL_PAGE_UP:
245 if (State->CurrentSelection <= State->FinalRow0)
246 State->CurrentSelection -= State->MaxVisible;
247 else if (State->CurrentSelection == State->InitialRow1)
248 State->CurrentSelection = State->FinalRow0;
249 else
250 State->CurrentSelection = State->InitialRow1;
251 if (State->CurrentSelection < 0)
252 State->CurrentSelection = 0;
253 break;
254
255 case SCROLL_FIRST:
256 if (State->CurrentSelection > 0) {
257 State->PaintAll = TRUE;
258 State->CurrentSelection = 0;
259 }
260 break;
261
262 case SCROLL_PAGE_DOWN:
263 if (State->CurrentSelection < State->FinalRow0) {
264 State->CurrentSelection += State->MaxVisible;
265 if (State->CurrentSelection > State->FinalRow0)
266 State->CurrentSelection = State->FinalRow0;
267 } else if (State->CurrentSelection == State->FinalRow0) {
268 State->CurrentSelection++;
269 } else {
270 State->CurrentSelection = State->MaxIndex;
271 }
272 if (State->CurrentSelection > State->MaxIndex)
273 State->CurrentSelection = State->MaxIndex;
274 break;
275
276 case SCROLL_LAST:
277 if (State->CurrentSelection < State->MaxIndex) {
278 State->PaintAll = TRUE;
279 State->CurrentSelection = State->MaxIndex;
280 }
281 break;
282
283 case SCROLL_NONE:
284 break;
285
286 }
287 if (State->ScrollMode == SCROLL_MODE_TEXT)
288 AdjustScrollState(State);
289
290 if (!State->PaintAll && State->CurrentSelection != State->PreviousSelection)
291 State->PaintSelection = TRUE;
292 State->LastVisible = State->FirstVisible + State->MaxVisible - 1;
293 } // static VOID UpdateScroll()
294
295 //
296 // menu helper functions
297 //
298
299 VOID AddMenuInfoLine(IN REFIT_MENU_SCREEN *Screen, IN CHAR16 *InfoLine)
300 {
301 AddListElement((VOID ***) &(Screen->InfoLines), &(Screen->InfoLineCount), InfoLine);
302 }
303
304 VOID AddMenuEntry(IN REFIT_MENU_SCREEN *Screen, IN REFIT_MENU_ENTRY *Entry)
305 {
306 AddListElement((VOID ***) &(Screen->Entries), &(Screen->EntryCount), Entry);
307 }
308
309
310 static INTN FindMenuShortcutEntry(IN REFIT_MENU_SCREEN *Screen, IN CHAR16 *Shortcut)
311 {
312 UINTN i;
313
314 if (Shortcut == NULL)
315 return (-1);
316
317 if (StrLen(Shortcut) == 1) {
318 if (Shortcut[0] >= 'a' && Shortcut[0] <= 'z')
319 Shortcut[0] -= ('a' - 'A');
320 if (Shortcut[0]) {
321 for (i = 0; i < Screen->EntryCount; i++) {
322 if (Screen->Entries[i]->ShortcutDigit == Shortcut[0] || Screen->Entries[i]->ShortcutLetter == Shortcut[0]) {
323 return i;
324 } // if
325 } // for
326 } // if
327 } else if (StrLen(Shortcut) > 1) {
328 for (i = 0; i < Screen->EntryCount; i++) {
329 if (StriSubCmp(Shortcut, Screen->Entries[i]->Title))
330 return i;
331 } // for
332 }
333 return -1;
334 }
335
336 // Identify the end of row 0 and the beginning of row 1; store the results in the
337 // appropriate fields in State. Also reduce MaxVisible if that value is greater
338 // than the total number of row-0 tags and if we're in an icon-based screen
339 static VOID IdentifyRows(IN SCROLL_STATE *State, IN REFIT_MENU_SCREEN *Screen) {
340 UINTN i;
341
342 State->FinalRow0 = 0;
343 State->InitialRow1 = State->MaxIndex;
344 for (i = 0; i < State->MaxIndex; i++) {
345 if (Screen->Entries[i]->Row == 0) {
346 State->FinalRow0 = i;
347 } else if ((Screen->Entries[i]->Row == 1) && (State->InitialRow1 > i)) {
348 State->InitialRow1 = i;
349 } // if/else
350 } // for
351 if ((State->ScrollMode == SCROLL_MODE_ICONS) && (State->MaxVisible > (State->FinalRow0 + 1)))
352 State->MaxVisible = State->FinalRow0 + 1;
353 } // static VOID IdentifyRows()
354
355 //
356 // generic menu function
357 //
358 static UINTN RunGenericMenu(IN REFIT_MENU_SCREEN *Screen, IN MENU_STYLE_FUNC StyleFunc, IN OUT INTN *DefaultEntryIndex,
359 OUT REFIT_MENU_ENTRY **ChosenEntry)
360 {
361 SCROLL_STATE State;
362 EFI_STATUS Status;
363 EFI_INPUT_KEY key;
364 UINTN index;
365 INTN ShortcutEntry;
366 BOOLEAN HaveTimeout = FALSE;
367 UINTN TimeoutCountdown = 0;
368 CHAR16 TimeoutMessage[256];
369 CHAR16 KeyAsString[2];
370 UINTN MenuExit;
371
372 if (Screen->TimeoutSeconds > 0) {
373 HaveTimeout = TRUE;
374 TimeoutCountdown = Screen->TimeoutSeconds * 10;
375 }
376 MenuExit = 0;
377
378 StyleFunc(Screen, &State, MENU_FUNCTION_INIT, NULL);
379 IdentifyRows(&State, Screen);
380 // override the starting selection with the default index, if any
381 if (*DefaultEntryIndex >= 0 && *DefaultEntryIndex <= State.MaxIndex) {
382 State.CurrentSelection = *DefaultEntryIndex;
383 UpdateScroll(&State, SCROLL_NONE);
384 }
385 State.PaintAll = TRUE;
386
387 while (!MenuExit) {
388 // update the screen
389 if (State.PaintAll) {
390 StyleFunc(Screen, &State, MENU_FUNCTION_PAINT_ALL, NULL);
391 State.PaintAll = FALSE;
392 } else if (State.PaintSelection) {
393 StyleFunc(Screen, &State, MENU_FUNCTION_PAINT_SELECTION, NULL);
394 State.PaintSelection = FALSE;
395 }
396
397 if (HaveTimeout) {
398 SPrint(TimeoutMessage, 255, L"%s in %d seconds", Screen->TimeoutText, (TimeoutCountdown + 5) / 10);
399 StyleFunc(Screen, &State, MENU_FUNCTION_PAINT_TIMEOUT, TimeoutMessage);
400 }
401
402 // read key press (and wait for it if applicable)
403 Status = refit_call2_wrapper(ST->ConIn->ReadKeyStroke, ST->ConIn, &key);
404 if (Status == EFI_NOT_READY) {
405 if (HaveTimeout && TimeoutCountdown == 0) {
406 // timeout expired
407 MenuExit = MENU_EXIT_TIMEOUT;
408 break;
409 } else if (HaveTimeout) {
410 refit_call1_wrapper(BS->Stall, 100000);
411 TimeoutCountdown--;
412 } else
413 refit_call3_wrapper(BS->WaitForEvent, 1, &ST->ConIn->WaitForKey, &index);
414 continue;
415 }
416 if (HaveTimeout) {
417 // the user pressed a key, cancel the timeout
418 StyleFunc(Screen, &State, MENU_FUNCTION_PAINT_TIMEOUT, L"");
419 HaveTimeout = FALSE;
420 }
421
422 // react to key press
423 switch (key.ScanCode) {
424 case SCAN_UP:
425 UpdateScroll(&State, SCROLL_LINE_UP);
426 break;
427 case SCAN_LEFT:
428 UpdateScroll(&State, SCROLL_LINE_LEFT);
429 break;
430 case SCAN_DOWN:
431 UpdateScroll(&State, SCROLL_LINE_DOWN);
432 break;
433 case SCAN_RIGHT:
434 UpdateScroll(&State, SCROLL_LINE_RIGHT);
435 break;
436 case SCAN_HOME:
437 UpdateScroll(&State, SCROLL_FIRST);
438 break;
439 case SCAN_END:
440 UpdateScroll(&State, SCROLL_LAST);
441 break;
442 case SCAN_PAGE_UP:
443 UpdateScroll(&State, SCROLL_PAGE_UP);
444 break;
445 case SCAN_PAGE_DOWN:
446 UpdateScroll(&State, SCROLL_PAGE_DOWN);
447 break;
448 case SCAN_ESC:
449 MenuExit = MENU_EXIT_ESCAPE;
450 break;
451 case SCAN_INSERT:
452 case SCAN_F2:
453 MenuExit = MENU_EXIT_DETAILS;
454 break;
455 case SCAN_F10:
456 egScreenShot();
457 break;
458 case 0x0016: // F12
459 if (EjectMedia())
460 MenuExit = MENU_EXIT_ESCAPE;
461 break;
462 }
463 switch (key.UnicodeChar) {
464 case CHAR_LINEFEED:
465 case CHAR_CARRIAGE_RETURN:
466 case ' ':
467 MenuExit = MENU_EXIT_ENTER;
468 break;
469 case '+':
470 MenuExit = MENU_EXIT_DETAILS;
471 break;
472 default:
473 KeyAsString[0] = key.UnicodeChar;
474 KeyAsString[1] = 0;
475 ShortcutEntry = FindMenuShortcutEntry(Screen, KeyAsString);
476 if (ShortcutEntry >= 0) {
477 State.CurrentSelection = ShortcutEntry;
478 MenuExit = MENU_EXIT_ENTER;
479 }
480 break;
481 }
482 }
483
484 StyleFunc(Screen, &State, MENU_FUNCTION_CLEANUP, NULL);
485
486 if (ChosenEntry)
487 *ChosenEntry = Screen->Entries[State.CurrentSelection];
488 *DefaultEntryIndex = State.CurrentSelection;
489 return MenuExit;
490 } /* static UINTN RunGenericMenu() */
491
492 //
493 // text-mode generic style
494 //
495
496 static VOID TextMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINTN Function, IN CHAR16 *ParamText)
497 {
498 INTN i;
499 UINTN MenuWidth, ItemWidth, MenuHeight;
500 static UINTN MenuPosY;
501 static CHAR16 **DisplayStrings;
502 CHAR16 TimeoutMessage[256];
503
504 State->ScrollMode = SCROLL_MODE_TEXT;
505 switch (Function) {
506
507 case MENU_FUNCTION_INIT:
508 // vertical layout
509 MenuPosY = 4;
510 if (Screen->InfoLineCount > 0)
511 MenuPosY += Screen->InfoLineCount + 1;
512 MenuHeight = ConHeight - MenuPosY - 3;
513 if (Screen->TimeoutSeconds > 0)
514 MenuHeight -= 2;
515 InitScroll(State, Screen->EntryCount, MenuHeight);
516
517 // determine width of the menu
518 MenuWidth = 20; // minimum
519 for (i = 0; i <= State->MaxIndex; i++) {
520 ItemWidth = StrLen(Screen->Entries[i]->Title);
521 if (MenuWidth < ItemWidth)
522 MenuWidth = ItemWidth;
523 }
524 MenuWidth += 2;
525 if (MenuWidth > ConWidth - 3)
526 MenuWidth = ConWidth - 3;
527
528 // prepare strings for display
529 DisplayStrings = AllocatePool(sizeof(CHAR16 *) * Screen->EntryCount);
530 for (i = 0; i <= State->MaxIndex; i++) {
531 // Note: Theoretically, SPrint() is a cleaner way to do this; but the
532 // description of the StrSize parameter to SPrint implies it's measured
533 // in characters, but in practice both TianoCore and GNU-EFI seem to
534 // use bytes instead, resulting in truncated displays. I could just
535 // double the size of the StrSize parameter, but that seems unsafe in
536 // case a future library change starts treating this as characters, so
537 // I'm doing it the hard way in this instance.
538 // TODO: Review the above and possibly change other uses of SPrint()
539 DisplayStrings[i] = AllocateZeroPool(2 * sizeof(CHAR16));
540 DisplayStrings[i][0] = L' ';
541 MergeStrings(&DisplayStrings[i], Screen->Entries[i]->Title, 0);
542 if (StrLen(DisplayStrings[i]) > MenuWidth)
543 DisplayStrings[i][MenuWidth - 1] = 0;
544 // TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
545 // TODO: account for double-width characters
546 } // for
547
548 // initial painting
549 BeginTextScreen(Screen->Title);
550 if (Screen->InfoLineCount > 0) {
551 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_BASIC);
552 for (i = 0; i < (INTN)Screen->InfoLineCount; i++) {
553 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 3, 4 + i);
554 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, Screen->InfoLines[i]);
555 }
556 }
557
558 break;
559
560 case MENU_FUNCTION_CLEANUP:
561 // release temporary memory
562 for (i = 0; i <= State->MaxIndex; i++)
563 MyFreePool(DisplayStrings[i]);
564 MyFreePool(DisplayStrings);
565 break;
566
567 case MENU_FUNCTION_PAINT_ALL:
568 // paint the whole screen (initially and after scrolling)
569 for (i = 0; i <= State->MaxIndex; i++) {
570 if (i >= State->FirstVisible && i <= State->LastVisible) {
571 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 2, MenuPosY + (i - State->FirstVisible));
572 if (i == State->CurrentSelection)
573 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_CHOICE_CURRENT);
574 else
575 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_CHOICE_BASIC);
576 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, DisplayStrings[i]);
577 }
578 }
579 // scrolling indicators
580 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_SCROLLARROW);
581 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, MenuPosY);
582 if (State->FirstVisible > 0)
583 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, ArrowUp);
584 else
585 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, L" ");
586 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, MenuPosY + State->MaxVisible);
587 if (State->LastVisible < State->MaxIndex)
588 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, ArrowDown);
589 else
590 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, L" ");
591 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
592 if (Screen->Hint1 != NULL) {
593 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 2);
594 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, Screen->Hint1);
595 }
596 if (Screen->Hint2 != NULL) {
597 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 1);
598 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, Screen->Hint2);
599 }
600 }
601 break;
602
603 case MENU_FUNCTION_PAINT_SELECTION:
604 // redraw selection cursor
605 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 2,
606 MenuPosY + (State->PreviousSelection - State->FirstVisible));
607 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_CHOICE_BASIC);
608 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, DisplayStrings[State->PreviousSelection]);
609 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 2,
610 MenuPosY + (State->CurrentSelection - State->FirstVisible));
611 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_CHOICE_CURRENT);
612 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, DisplayStrings[State->CurrentSelection]);
613 break;
614
615 case MENU_FUNCTION_PAINT_TIMEOUT:
616 if (ParamText[0] == 0) {
617 // clear message
618 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_BASIC);
619 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 3);
620 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, BlankLine + 1);
621 } else {
622 // paint or update message
623 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_ERROR);
624 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 3, ConHeight - 3);
625 SPrint(TimeoutMessage, 255, L"%s ", ParamText);
626 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, TimeoutMessage);
627 }
628 break;
629
630 }
631 }
632
633 //
634 // graphical generic style
635 //
636
637
638 // Display a submenu
639 static VOID DrawSubmenuText(IN CHAR16 *Text, IN BOOLEAN Selected, IN UINTN FieldWidth, IN UINTN XPos, IN UINTN YPos)
640 {
641 // UINTN TextWidth = TEXT_XMARGIN * 2 + StrLen(Text) * FONT_CELL_WIDTH;
642 EG_IMAGE *TextBuffer;
643
644 TextBuffer = egCreateImage(FieldWidth, TEXT_LINE_HEIGHT, FALSE);
645
646 egFillImage(TextBuffer, &MenuBackgroundPixel);
647 if (Selected) {
648 // draw selection bar background
649 egFillImageArea(TextBuffer, 0, 0, FieldWidth, TextBuffer->Height, &SelectionBackgroundPixel);
650 }
651
652 // render the text
653 egRenderText(Text, TextBuffer, TEXT_XMARGIN, TEXT_YMARGIN);
654 egDrawImageWithTransparency(TextBuffer, NULL, XPos, YPos, TextBuffer->Width, TextBuffer->Height);
655 // BltImage(TextBuffer, XPos, YPos);
656 }
657
658 static VOID DrawMainMenuText(IN CHAR16 *Text, IN UINTN XPos, IN UINTN YPos)
659 {
660 UINTN TextWidth, TextPosX;
661 EG_IMAGE *TextBuffer;
662
663 TextBuffer = egCropImage(GlobalConfig.ScreenBackground, XPos, YPos, LAYOUT_TEXT_WIDTH, TEXT_LINE_HEIGHT);
664
665 // render the text
666 egMeasureText(Text, &TextWidth, NULL);
667 if (TextWidth > TextBuffer->Width)
668 TextPosX = 0;
669 else
670 TextPosX = (TextBuffer->Width - TextWidth) / 2;
671 egRenderText(Text, TextBuffer, TextPosX, 0);
672 egDrawImageWithTransparency(TextBuffer, NULL, XPos, YPos, TextBuffer->Width, TextBuffer->Height);
673 }
674
675 // Compute the size & position of the window that will hold a subscreen's information.
676 static VOID ComputeSubScreenWindowSize(REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN *XPos, UINTN *YPos, UINTN *Width, UINTN *Height, UINTN *LineWidth) {
677 UINTN i, ItemWidth, HintTop, BannerBottomEdge, TitleWidth, CenteredTop;
678
679 *Width = 1;
680 *Height = 5;
681 TitleWidth = StrLen(Screen->Title);
682 if ((Screen->TitleImage) && (TitleWidth > (Screen->TitleImage->Width / FONT_CELL_WIDTH))) {
683 TitleWidth -= (Screen->TitleImage->Width / FONT_CELL_WIDTH);
684 }
685 if (TitleWidth > *Width) {
686 *Width = TitleWidth;
687 }
688 for (i = 0; i < Screen->InfoLineCount; i++) {
689 ItemWidth = StrLen(Screen->InfoLines[i]);
690 if (*Width < ItemWidth) {
691 *Width = ItemWidth;
692 }
693 (*Height)++;
694 }
695 for (i = 0; i <= State->MaxIndex; i++) {
696 ItemWidth = StrLen(Screen->Entries[i]->Title);
697 if (*Width < ItemWidth) {
698 *Width = ItemWidth;
699 }
700 (*Height)++;
701 }
702 *Width = TEXT_XMARGIN * 2 + *Width * FONT_CELL_WIDTH;
703 *LineWidth = *Width;
704 if (Screen->TitleImage)
705 *Width += (Screen->TitleImage->Width + TITLEICON_SPACING + FONT_CELL_WIDTH);
706 else
707 *Width += FONT_CELL_WIDTH;
708
709 // Keep it within the bounds of the screen, or 2/3 of the screen's width
710 // for screens over 800 pixels wide
711 if (*Width > UGAWidth)
712 *Width = UGAWidth;
713 if ((*Width > (2 * UGAWidth) / 3) && (UGAWidth > 800))
714 *Width = (2 * UGAWidth) / 3;
715
716 *XPos = (UGAWidth - *Width) / 2;
717
718 HintTop = UGAHeight - (FONT_CELL_HEIGHT * 3); // top of hint text
719 *Height *= TEXT_LINE_HEIGHT;
720 if (Screen->TitleImage && (*Height < (Screen->TitleImage->Height + TEXT_LINE_HEIGHT * 3)))
721 *Height = Screen->TitleImage->Height + TEXT_LINE_HEIGHT * 3;
722
723 if (GlobalConfig.BannerBottomEdge >= HintTop) { // probably a full-screen image; treat it as an empty banner
724 BannerBottomEdge = 0;
725 } else {
726 BannerBottomEdge = GlobalConfig.BannerBottomEdge;
727 }
728 if (*Height > (HintTop -BannerBottomEdge - FONT_CELL_HEIGHT * 2)) {
729 BannerBottomEdge = 0;
730 }
731 if (*Height > (HintTop -BannerBottomEdge - FONT_CELL_HEIGHT * 2)) {
732 // TODO: Implement scrolling in text screen.
733 *Height = (HintTop - BannerBottomEdge - FONT_CELL_HEIGHT * 2);
734 }
735 *YPos = BannerBottomEdge + FONT_CELL_HEIGHT + (HintTop - BannerBottomEdge - *Height) / 2;
736 // Above often produces a text field that feels bottom-weighted, so adjust
737 // upward a bit, if possible....
738 CenteredTop = ((UGAHeight - *Height) / 2);
739 if ((*YPos > CenteredTop) && (CenteredTop > BannerBottomEdge))
740 *YPos = CenteredTop;
741 } // VOID ComputeSubScreenWindowSize()
742
743 // Displays sub-menus
744 static VOID GraphicsMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINTN Function, IN CHAR16 *ParamText)
745 {
746 INTN i;
747 UINTN ItemWidth;
748 static UINTN LineWidth, MenuWidth, MenuHeight, EntriesPosX, EntriesPosY, TimeoutPosY;
749 EG_IMAGE *Window;
750 EG_PIXEL *BackgroundPixel = &(GlobalConfig.ScreenBackground->PixelData[0]);
751
752 State->ScrollMode = SCROLL_MODE_TEXT;
753 switch (Function) {
754
755 case MENU_FUNCTION_INIT:
756 InitScroll(State, Screen->EntryCount, 0);
757 ComputeSubScreenWindowSize(Screen, State, &EntriesPosX, &EntriesPosY, &MenuWidth, &MenuHeight, &LineWidth);
758 TimeoutPosY = EntriesPosY + (Screen->EntryCount + 1) * TEXT_LINE_HEIGHT;
759
760 // initial painting
761 SwitchToGraphicsAndClear();
762 Window = egCreateFilledImage(MenuWidth, MenuHeight, FALSE, BackgroundPixel);
763 egDrawImage(Window, EntriesPosX, EntriesPosY);
764 egMeasureText(Screen->Title, &ItemWidth, NULL);
765 DrawSubmenuText(Screen->Title, FALSE, (StrLen(Screen->Title) + 2) * FONT_CELL_WIDTH,
766 EntriesPosX + (MenuWidth - ItemWidth) / 2, EntriesPosY += TEXT_LINE_HEIGHT);
767 if (Screen->TitleImage) {
768 BltImageAlpha(Screen->TitleImage, EntriesPosX, EntriesPosY + TEXT_LINE_HEIGHT * 2, BackgroundPixel);
769 EntriesPosX += (Screen->TitleImage->Width + TITLEICON_SPACING);
770 }
771 EntriesPosY += (TEXT_LINE_HEIGHT * 2);
772 if (Screen->InfoLineCount > 0) {
773 for (i = 0; i < (INTN)Screen->InfoLineCount; i++) {
774 DrawSubmenuText(Screen->InfoLines[i], FALSE, LineWidth, EntriesPosX, EntriesPosY);
775 EntriesPosY += TEXT_LINE_HEIGHT;
776 }
777 EntriesPosY += TEXT_LINE_HEIGHT; // also add a blank line
778 }
779
780 break;
781
782 case MENU_FUNCTION_CLEANUP:
783 // nothing to do
784 break;
785
786 case MENU_FUNCTION_PAINT_ALL:
787 for (i = 0; i <= State->MaxIndex; i++) {
788 DrawSubmenuText(Screen->Entries[i]->Title, (i == State->CurrentSelection), LineWidth,
789 EntriesPosX, EntriesPosY + i * TEXT_LINE_HEIGHT);
790 }
791 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
792 if ((Screen->Hint1 != NULL) && (StrLen(Screen->Hint1) > 0))
793 DrawMainMenuText(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
794 if ((Screen->Hint2 != NULL) && (StrLen(Screen->Hint2) > 0))
795 DrawMainMenuText(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
796 } // if
797 break;
798
799 case MENU_FUNCTION_PAINT_SELECTION:
800 // redraw selection cursor
801 DrawSubmenuText(Screen->Entries[State->PreviousSelection]->Title, FALSE, LineWidth,
802 EntriesPosX, EntriesPosY + State->PreviousSelection * TEXT_LINE_HEIGHT);
803 DrawSubmenuText(Screen->Entries[State->CurrentSelection]->Title, TRUE, LineWidth,
804 EntriesPosX, EntriesPosY + State->CurrentSelection * TEXT_LINE_HEIGHT);
805 break;
806
807 case MENU_FUNCTION_PAINT_TIMEOUT:
808 DrawSubmenuText(ParamText, FALSE, LineWidth, EntriesPosX, TimeoutPosY);
809 break;
810
811 }
812 } // static VOID GraphicsMenuStyle()
813
814 //
815 // graphical main menu style
816 //
817
818 static VOID DrawMainMenuEntry(REFIT_MENU_ENTRY *Entry, BOOLEAN selected, UINTN XPos, UINTN YPos)
819 {
820 EG_IMAGE *Background;
821
822 if (SelectionImages != NULL) {
823 if (selected) {
824 Background = egCropImage(GlobalConfig.ScreenBackground, XPos, YPos,
825 SelectionImages[Entry->Row]->Width, SelectionImages[Entry->Row]->Height);
826 egComposeImage(Background, SelectionImages[Entry->Row], 0, 0);
827 BltImageCompositeBadge(Background, Entry->Image, Entry->BadgeImage, XPos, YPos);
828 } else { // Image not selected; copy background
829 egDrawImageWithTransparency(Entry->Image, Entry->BadgeImage, XPos, YPos,
830 SelectionImages[Entry->Row]->Width, SelectionImages[Entry->Row]->Height);
831 } // if/else
832 } // if
833 } // VOID DrawMainMenuEntry()
834
835 static VOID PaintAll(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN *itemPosX,
836 UINTN row0PosY, UINTN row1PosY, UINTN textPosY) {
837 INTN i;
838
839 if (Screen->Entries[State->CurrentSelection]->Row == 0)
840 AdjustScrollState(State);
841 for (i = State->FirstVisible; i <= State->MaxIndex; i++) {
842 if (Screen->Entries[i]->Row == 0) {
843 if (i <= State->LastVisible) {
844 DrawMainMenuEntry(Screen->Entries[i], (i == State->CurrentSelection) ? TRUE : FALSE,
845 itemPosX[i - State->FirstVisible], row0PosY);
846 } // if
847 } else {
848 DrawMainMenuEntry(Screen->Entries[i], (i == State->CurrentSelection) ? TRUE : FALSE, itemPosX[i], row1PosY);
849 }
850 }
851 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
852 DrawMainMenuText(Screen->Entries[State->CurrentSelection]->Title,
853 (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY);
854
855 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
856 DrawMainMenuText(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
857 DrawMainMenuText(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
858 } // if
859 } // static VOID PaintAll()
860
861 // Move the selection to State->CurrentSelection, adjusting icon row if necessary...
862 static VOID PaintSelection(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN *itemPosX,
863 UINTN row0PosY, UINTN row1PosY, UINTN textPosY) {
864 UINTN XSelectPrev, XSelectCur, YPosPrev, YPosCur;
865
866 if (((State->CurrentSelection <= State->LastVisible) && (State->CurrentSelection >= State->FirstVisible)) ||
867 (State->CurrentSelection >= State->InitialRow1) ) {
868 if (Screen->Entries[State->PreviousSelection]->Row == 0) {
869 XSelectPrev = State->PreviousSelection - State->FirstVisible;
870 YPosPrev = row0PosY;
871 } else {
872 XSelectPrev = State->PreviousSelection;
873 YPosPrev = row1PosY;
874 } // if/else
875 if (Screen->Entries[State->CurrentSelection]->Row == 0) {
876 XSelectCur = State->CurrentSelection - State->FirstVisible;
877 YPosCur = row0PosY;
878 } else {
879 XSelectCur = State->CurrentSelection;
880 YPosCur = row1PosY;
881 } // if/else
882 DrawMainMenuEntry(Screen->Entries[State->PreviousSelection], FALSE, itemPosX[XSelectPrev], YPosPrev);
883 DrawMainMenuEntry(Screen->Entries[State->CurrentSelection], TRUE, itemPosX[XSelectCur], YPosCur);
884 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
885 DrawMainMenuText(Screen->Entries[State->CurrentSelection]->Title,
886 (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY);
887 } else { // Current selection not visible; must redraw the menu....
888 MainMenuStyle(Screen, State, MENU_FUNCTION_PAINT_ALL, NULL);
889 }
890 } // static VOID MoveSelection(VOID)
891
892 // Display an icon at the specified location. Uses the image specified by
893 // ExternalFilename if it's available, or BuiltInImage if it's not. The
894 // Y position is specified as the center value, and so is adjusted by half
895 // the icon's height. The X position is set along the icon's left
896 // edge if Alignment == ALIGN_LEFT, and along the right edge if
897 // Alignment == ALIGN_RIGHT
898 static VOID PaintIcon(IN EG_EMBEDDED_IMAGE *BuiltInIcon, IN CHAR16 *ExternalFilename, UINTN PosX, UINTN PosY, UINTN Alignment) {
899 EG_IMAGE *Icon = NULL;
900
901 if (FileExists(SelfDir, ExternalFilename))
902 Icon = egLoadIcon(SelfDir, ExternalFilename, 48);
903 if (Icon == NULL)
904 Icon = egPrepareEmbeddedImage(BuiltInIcon, TRUE);
905 if (Icon != NULL) {
906 if (Alignment == ALIGN_RIGHT)
907 PosX -= Icon->Width;
908 egDrawImageWithTransparency(Icon, NULL, PosX, PosY - (Icon->Height / 2), Icon->Width, Icon->Height);
909 }
910 } // static VOID PaintIcon()
911
912 inline UINTN ComputeRow0PosX(VOID) {
913 // return ((UGAHeight / 2) - (5 * ROW0_TILESIZE / 6));
914 return ((UGAHeight / 2) - ROW0_TILESIZE / 2);
915 } // UINTN ComputeRow0PosX()
916
917 // Display (or erase) the arrow icons to the left and right of an icon's row,
918 // as appropriate.
919 static VOID PaintArrows(SCROLL_STATE *State, UINTN PosX, UINTN PosY, UINTN row0Loaders) {
920 CHAR16 FileName[256];
921 EG_IMAGE *TempImage;
922 UINTN Width, Height, RightX, AdjPosY;
923
924 // NOTE: Assume that left and right arrows are of the same size....
925 Width = egemb_arrow_left.Width;
926 Height = egemb_arrow_left.Height;
927 RightX = (UGAWidth + (ROW0_TILESIZE + TILE_XSPACING) * State->MaxVisible) / 2 + TILE_XSPACING;
928 AdjPosY = PosY - (Height / 2);
929
930 // For PaintIcon() calls, the starting Y position is moved to the midpoint
931 // of the surrounding row; PaintIcon() adjusts this back up by half the
932 // icon's height to properly center it.
933 if ((State->FirstVisible > 0) && (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_ARROWS))) {
934 SPrint(FileName, 255, L"%s\\arrow_left.icns", GlobalConfig.IconsDir ? GlobalConfig.IconsDir : DEFAULT_ICONS_DIR);
935 PaintIcon(&egemb_arrow_left, FileName, PosX, PosY, ALIGN_RIGHT);
936 } else {
937 TempImage = egCropImage(GlobalConfig.ScreenBackground, PosX - Width, AdjPosY, Width, Height);
938 BltImage(TempImage, PosX - Width, AdjPosY);
939 egFreeImage(TempImage);
940 } // if/else
941
942 if ((State->LastVisible < (row0Loaders - 1)) && (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_ARROWS))) {
943 SPrint(FileName, 255, L"%s\\arrow_right.icns", GlobalConfig.IconsDir ? GlobalConfig.IconsDir : DEFAULT_ICONS_DIR);
944 PaintIcon(&egemb_arrow_right, FileName, RightX, PosY, ALIGN_LEFT);
945 } else {
946 TempImage = egCropImage(GlobalConfig.ScreenBackground, RightX, AdjPosY, Width, Height);
947 BltImage(TempImage, RightX, AdjPosY);
948 egFreeImage(TempImage);
949 } // if/else
950 } // VOID PaintArrows()
951
952 // Display main menu in graphics mode
953 VOID MainMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINTN Function, IN CHAR16 *ParamText)
954 {
955 INTN i;
956 static UINTN row0PosX, row0PosXRunning, row1PosY, row0Loaders;
957 UINTN row0Count, row1Count, row1PosX, row1PosXRunning;
958 static UINTN *itemPosX;
959 static UINTN row0PosY, textPosY;
960
961 State->ScrollMode = SCROLL_MODE_ICONS;
962 switch (Function) {
963
964 case MENU_FUNCTION_INIT:
965 InitScroll(State, Screen->EntryCount, GlobalConfig.MaxTags);
966
967 // layout
968 row0Count = 0;
969 row1Count = 0;
970 row0Loaders = 0;
971 for (i = 0; i <= State->MaxIndex; i++) {
972 if (Screen->Entries[i]->Row == 1) {
973 row1Count++;
974 } else {
975 row0Loaders++;
976 if (row0Count < State->MaxVisible)
977 row0Count++;
978 }
979 }
980 row0PosX = (UGAWidth + TILE_XSPACING - (ROW0_TILESIZE + TILE_XSPACING) * row0Count) >> 1;
981 row0PosY = ComputeRow0PosX();
982 row1PosX = (UGAWidth + TILE_XSPACING - (ROW1_TILESIZE + TILE_XSPACING) * row1Count) >> 1;
983 row1PosY = row0PosY + ROW0_TILESIZE + TILE_YSPACING;
984 if (row1Count > 0)
985 textPosY = row1PosY + ROW1_TILESIZE + TILE_YSPACING;
986 else
987 textPosY = row1PosY;
988
989 itemPosX = AllocatePool(sizeof(UINTN) * Screen->EntryCount);
990 row0PosXRunning = row0PosX;
991 row1PosXRunning = row1PosX;
992 for (i = 0; i <= State->MaxIndex; i++) {
993 if (Screen->Entries[i]->Row == 0) {
994 itemPosX[i] = row0PosXRunning;
995 row0PosXRunning += ROW0_TILESIZE + TILE_XSPACING;
996 } else {
997 itemPosX[i] = row1PosXRunning;
998 row1PosXRunning += ROW1_TILESIZE + TILE_XSPACING;
999 }
1000 }
1001 // initial painting
1002 InitSelection();
1003 SwitchToGraphicsAndClear();
1004 break;
1005
1006 case MENU_FUNCTION_CLEANUP:
1007 MyFreePool(itemPosX);
1008 break;
1009
1010 case MENU_FUNCTION_PAINT_ALL:
1011 PaintAll(Screen, State, itemPosX, row0PosY, row1PosY, textPosY);
1012 // For PaintArrows(), the starting Y position is moved to the midpoint
1013 // of the surrounding row; PaintIcon() adjusts this back up by half the
1014 // icon's height to properly center it.
1015 PaintArrows(State, row0PosX - TILE_XSPACING, row0PosY + (ROW0_TILESIZE / 2), row0Loaders);
1016 break;
1017
1018 case MENU_FUNCTION_PAINT_SELECTION:
1019 PaintSelection(Screen, State, itemPosX, row0PosY, row1PosY, textPosY);
1020 break;
1021
1022 case MENU_FUNCTION_PAINT_TIMEOUT:
1023 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
1024 DrawMainMenuText(ParamText, (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY + TEXT_LINE_HEIGHT);
1025 break;
1026
1027 }
1028 } // VOID MainMenuStyle()
1029
1030 // Enable the user to edit boot loader options.
1031 // Returns TRUE if the user exited with edited options; FALSE if the user
1032 // pressed Esc to terminate the edit.
1033 static BOOLEAN EditOptions(LOADER_ENTRY *MenuEntry) {
1034 UINTN x_max, y_max;
1035 CHAR16 *EditedOptions;
1036 BOOLEAN retval = FALSE;
1037
1038 if (GlobalConfig.HideUIFlags & HIDEUI_FLAG_EDITOR) {
1039 return FALSE;
1040 }
1041
1042 refit_call4_wrapper(ST->ConOut->QueryMode, ST->ConOut, ST->ConOut->Mode->Mode, &x_max, &y_max);
1043
1044 if (!GlobalConfig.TextOnly)
1045 SwitchToText(TRUE);
1046
1047 if (line_edit(MenuEntry->LoadOptions, &EditedOptions, x_max)) {
1048 MyFreePool(MenuEntry->LoadOptions);
1049 MenuEntry->LoadOptions = EditedOptions;
1050 retval = TRUE;
1051 } // if
1052 if (!GlobalConfig.TextOnly)
1053 SwitchToGraphics();
1054 return retval;
1055 } // VOID EditOptions()
1056
1057 //
1058 // user-callable dispatcher functions
1059 //
1060
1061 UINTN RunMenu(IN REFIT_MENU_SCREEN *Screen, OUT REFIT_MENU_ENTRY **ChosenEntry)
1062 {
1063 INTN DefaultEntry = -1;
1064 MENU_STYLE_FUNC Style = TextMenuStyle;
1065
1066 if (AllowGraphicsMode)
1067 Style = GraphicsMenuStyle;
1068
1069 return RunGenericMenu(Screen, Style, &DefaultEntry, ChosenEntry);
1070 }
1071
1072 UINTN RunMainMenu(IN REFIT_MENU_SCREEN *Screen, IN CHAR16* DefaultSelection, OUT REFIT_MENU_ENTRY **ChosenEntry)
1073 {
1074 MENU_STYLE_FUNC Style = TextMenuStyle;
1075 MENU_STYLE_FUNC MainStyle = TextMenuStyle;
1076 REFIT_MENU_ENTRY *TempChosenEntry;
1077 UINTN MenuExit = 0;
1078 INTN DefaultEntryIndex = -1;
1079 INTN DefaultSubmenuIndex = -1;
1080
1081 if (DefaultSelection != NULL) {
1082 // Find a menu entry that includes *DefaultSelection as a substring
1083 DefaultEntryIndex = FindMenuShortcutEntry(Screen, DefaultSelection);
1084 }
1085
1086 if (AllowGraphicsMode) {
1087 Style = GraphicsMenuStyle;
1088 MainStyle = MainMenuStyle;
1089 }
1090
1091 while (!MenuExit) {
1092 MenuExit = RunGenericMenu(Screen, MainStyle, &DefaultEntryIndex, &TempChosenEntry);
1093 Screen->TimeoutSeconds = 0;
1094
1095 if (MenuExit == MENU_EXIT_DETAILS) {
1096 if (TempChosenEntry->SubScreen != NULL) {
1097 MenuExit = RunGenericMenu(TempChosenEntry->SubScreen, Style, &DefaultSubmenuIndex, &TempChosenEntry);
1098 if (MenuExit == MENU_EXIT_ESCAPE || TempChosenEntry->Tag == TAG_RETURN)
1099 MenuExit = 0;
1100 if (MenuExit == MENU_EXIT_DETAILS) {
1101 if (!EditOptions((LOADER_ENTRY *) TempChosenEntry))
1102 MenuExit = 0;
1103 } // if
1104 } else { // no sub-screen; ignore keypress
1105 MenuExit = 0;
1106 }
1107 } // Enter sub-screen
1108 }
1109
1110 if (ChosenEntry)
1111 *ChosenEntry = TempChosenEntry;
1112 return MenuExit;
1113 } /* UINTN RunMainMenu() */