5 * Copyright (c) 2006 Christoph Pfisterer
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
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.
37 * Modifications copyright (c) 2012 Roderick W. Smith
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.
52 #include "../include/refit_call_wrapper.h"
54 #include "../include/egemb_back_selected_small.h"
55 #include "../include/egemb_back_selected_big.h"
56 #include "../include/egemb_arrow_left.h"
57 #include "../include/egemb_arrow_right.h"
59 // other menu definitions
61 #define MENU_FUNCTION_INIT (0)
62 #define MENU_FUNCTION_CLEANUP (1)
63 #define MENU_FUNCTION_PAINT_ALL (2)
64 #define MENU_FUNCTION_PAINT_SELECTION (3)
65 #define MENU_FUNCTION_PAINT_TIMEOUT (4)
66 #define MENU_FUNCTION_PAINT_HINTS (5)
68 typedef VOID (*MENU_STYLE_FUNC
)(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
);
70 static CHAR16 ArrowUp
[2] = { ARROW_UP
, 0 };
71 static CHAR16 ArrowDown
[2] = { ARROW_DOWN
, 0 };
72 static UINTN TileSizes
[2] = { 144, 64 };
74 // Text and icon spacing constants....
75 #define TEXT_YMARGIN (2)
76 #define TITLEICON_SPACING (16)
78 #define TILE_XSPACING (8)
79 #define TILE_YSPACING (16)
81 // Alignment values for PaintIcon()
85 static EG_IMAGE
*SelectionImages
[2] = { NULL
, NULL
};
86 static EG_PIXEL SelectionBackgroundPixel
= { 0xff, 0xff, 0xff, 0 };
89 // Graphics helper functions
92 static VOID
InitSelection(VOID
)
94 EG_IMAGE
*TempSmallImage
= NULL
, *TempBigImage
= NULL
;
95 BOOLEAN LoadedSmallImage
= FALSE
;
97 if (!AllowGraphicsMode
)
99 if (SelectionImages
[0] != NULL
)
102 // load small selection image
103 if (GlobalConfig
.SelectionSmallFileName
!= NULL
) {
104 TempSmallImage
= egLoadImage(SelfDir
, GlobalConfig
.SelectionSmallFileName
, TRUE
);
106 if (TempSmallImage
== NULL
)
107 TempSmallImage
= egPrepareEmbeddedImage(&egemb_back_selected_small
, TRUE
);
109 LoadedSmallImage
= TRUE
;
110 SelectionImages
[1] = egScaleImage(TempSmallImage
, TileSizes
[1], TileSizes
[1]);
112 // load big selection image
113 if (GlobalConfig
.SelectionBigFileName
!= NULL
) {
114 TempBigImage
= egLoadImage(SelfDir
, GlobalConfig
.SelectionBigFileName
, TRUE
);
116 if (TempBigImage
== NULL
) {
117 if (LoadedSmallImage
) {
118 // calculate big selection image from small one
119 TempBigImage
= egCopyImage(TempSmallImage
);
121 TempBigImage
= egPrepareEmbeddedImage(&egemb_back_selected_big
, TRUE
);
124 SelectionImages
[0] = egScaleImage(TempBigImage
, TileSizes
[0], TileSizes
[0]);
127 egFreeImage(TempSmallImage
);
129 egFreeImage(TempBigImage
);
130 } // VOID InitSelection()
133 // Scrolling functions
136 static VOID
InitScroll(OUT SCROLL_STATE
*State
, IN UINTN ItemCount
, IN UINTN VisibleSpace
)
138 State
->PreviousSelection
= State
->CurrentSelection
= 0;
139 State
->MaxIndex
= (INTN
)ItemCount
- 1;
140 State
->FirstVisible
= 0;
141 if (AllowGraphicsMode
) {
142 State
->MaxVisible
= UGAWidth
/ (TileSizes
[0] + TILE_XSPACING
) - 1;
144 State
->MaxVisible
= ConHeight
- 4;
145 if ((VisibleSpace
> 0) && (VisibleSpace
< State
->MaxVisible
))
146 State
->MaxVisible
= (INTN
)VisibleSpace
;
147 State
->PaintAll
= TRUE
;
148 State
->PaintSelection
= FALSE
;
150 State
->LastVisible
= State
->FirstVisible
+ State
->MaxVisible
- 1;
153 // Adjust variables relating to the scrolling of tags, for when a selected icon isn't
154 // visible given the current scrolling condition....
155 static VOID
AdjustScrollState(IN SCROLL_STATE
*State
) {
156 if (State
->CurrentSelection
> State
->LastVisible
) {
157 State
->LastVisible
= State
->CurrentSelection
;
158 State
->FirstVisible
= 1 + State
->CurrentSelection
- State
->MaxVisible
;
159 if (State
->FirstVisible
< 0) // shouldn't happen, but just in case....
160 State
->FirstVisible
= 0;
161 State
->PaintAll
= TRUE
;
163 if (State
->CurrentSelection
< State
->FirstVisible
) {
164 State
->FirstVisible
= State
->CurrentSelection
;
165 State
->LastVisible
= State
->CurrentSelection
+ State
->MaxVisible
- 1;
166 State
->PaintAll
= TRUE
;
168 } // static VOID AdjustScrollState
170 static VOID
UpdateScroll(IN OUT SCROLL_STATE
*State
, IN UINTN Movement
)
172 State
->PreviousSelection
= State
->CurrentSelection
;
175 case SCROLL_LINE_LEFT
:
176 if (State
->CurrentSelection
> 0) {
177 State
->CurrentSelection
--;
181 case SCROLL_LINE_RIGHT
:
182 if (State
->CurrentSelection
< State
->MaxIndex
) {
183 State
->CurrentSelection
++;
188 if (State
->ScrollMode
== SCROLL_MODE_ICONS
) {
189 if (State
->CurrentSelection
>= State
->InitialRow1
) {
190 if (State
->MaxIndex
> State
->InitialRow1
) { // avoid division by 0!
191 State
->CurrentSelection
= State
->FirstVisible
+ (State
->LastVisible
- State
->FirstVisible
) *
192 (State
->CurrentSelection
- State
->InitialRow1
) /
193 (State
->MaxIndex
- State
->InitialRow1
);
195 State
->CurrentSelection
= State
->FirstVisible
;
197 } // if in second row
199 if (State
->CurrentSelection
> 0)
200 State
->CurrentSelection
--;
204 case SCROLL_LINE_DOWN
:
205 if (State
->ScrollMode
== SCROLL_MODE_ICONS
) {
206 if (State
->CurrentSelection
<= State
->FinalRow0
) {
207 if (State
->LastVisible
> State
->FirstVisible
) { // avoid division by 0!
208 State
->CurrentSelection
= State
->InitialRow1
+ (State
->MaxIndex
- State
->InitialRow1
) *
209 (State
->CurrentSelection
- State
->FirstVisible
) /
210 (State
->LastVisible
- State
->FirstVisible
);
212 State
->CurrentSelection
= State
->InitialRow1
;
216 if (State
->CurrentSelection
< State
->MaxIndex
)
217 State
->CurrentSelection
++;
222 if (State
->CurrentSelection
<= State
->FinalRow0
)
223 State
->CurrentSelection
-= State
->MaxVisible
;
224 else if (State
->CurrentSelection
== State
->InitialRow1
)
225 State
->CurrentSelection
= State
->FinalRow0
;
227 State
->CurrentSelection
= State
->InitialRow1
;
228 if (State
->CurrentSelection
< 0)
229 State
->CurrentSelection
= 0;
233 if (State
->CurrentSelection
> 0) {
234 State
->PaintAll
= TRUE
;
235 State
->CurrentSelection
= 0;
239 case SCROLL_PAGE_DOWN
:
240 if (State
->CurrentSelection
< State
->FinalRow0
) {
241 State
->CurrentSelection
+= State
->MaxVisible
;
242 if (State
->CurrentSelection
> State
->FinalRow0
)
243 State
->CurrentSelection
= State
->FinalRow0
;
244 } else if (State
->CurrentSelection
== State
->FinalRow0
) {
245 State
->CurrentSelection
++;
247 State
->CurrentSelection
= State
->MaxIndex
;
249 if (State
->CurrentSelection
> State
->MaxIndex
)
250 State
->CurrentSelection
= State
->MaxIndex
;
254 if (State
->CurrentSelection
< State
->MaxIndex
) {
255 State
->PaintAll
= TRUE
;
256 State
->CurrentSelection
= State
->MaxIndex
;
264 if (State
->ScrollMode
== SCROLL_MODE_TEXT
)
265 AdjustScrollState(State
);
267 if (!State
->PaintAll
&& State
->CurrentSelection
!= State
->PreviousSelection
)
268 State
->PaintSelection
= TRUE
;
269 State
->LastVisible
= State
->FirstVisible
+ State
->MaxVisible
- 1;
270 } // static VOID UpdateScroll()
273 // menu helper functions
276 VOID
AddMenuInfoLine(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
*InfoLine
)
278 AddListElement((VOID
***) &(Screen
->InfoLines
), &(Screen
->InfoLineCount
), InfoLine
);
281 VOID
AddMenuEntry(IN REFIT_MENU_SCREEN
*Screen
, IN REFIT_MENU_ENTRY
*Entry
)
283 AddListElement((VOID
***) &(Screen
->Entries
), &(Screen
->EntryCount
), Entry
);
287 static INTN
FindMenuShortcutEntry(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
*Defaults
)
292 while ((Shortcut
= FindCommaDelimited(Defaults
, j
)) != NULL
) {
293 if (StrLen(Shortcut
) == 1) {
294 if (Shortcut
[0] >= 'a' && Shortcut
[0] <= 'z')
295 Shortcut
[0] -= ('a' - 'A');
297 for (i
= 0; i
< Screen
->EntryCount
; i
++) {
298 if (Screen
->Entries
[i
]->ShortcutDigit
== Shortcut
[0] || Screen
->Entries
[i
]->ShortcutLetter
== Shortcut
[0]) {
299 MyFreePool(Shortcut
);
304 } else if (StrLen(Shortcut
) > 1) {
305 for (i
= 0; i
< Screen
->EntryCount
; i
++) {
306 if (StriSubCmp(Shortcut
, Screen
->Entries
[i
]->Title
)) {
307 MyFreePool(Shortcut
);
312 MyFreePool(Shortcut
);
318 // Identify the end of row 0 and the beginning of row 1; store the results in the
319 // appropriate fields in State. Also reduce MaxVisible if that value is greater
320 // than the total number of row-0 tags and if we're in an icon-based screen
321 static VOID
IdentifyRows(IN SCROLL_STATE
*State
, IN REFIT_MENU_SCREEN
*Screen
) {
324 State
->FinalRow0
= 0;
325 State
->InitialRow1
= State
->MaxIndex
;
326 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
327 if (Screen
->Entries
[i
]->Row
== 0) {
328 State
->FinalRow0
= i
;
329 } else if ((Screen
->Entries
[i
]->Row
== 1) && (State
->InitialRow1
> i
)) {
330 State
->InitialRow1
= i
;
333 if ((State
->ScrollMode
== SCROLL_MODE_ICONS
) && (State
->MaxVisible
> (State
->FinalRow0
+ 1)))
334 State
->MaxVisible
= State
->FinalRow0
+ 1;
335 } // static VOID IdentifyRows()
337 // Blank the screen, wait for a keypress, and restore banner/background.
338 // Screen may still require redrawing of text and icons on return.
339 // TODO: Support more sophisticated screen savers, such as power-saving
340 // mode and dynamic images.
341 static VOID
SaveScreen(VOID
) {
343 EG_PIXEL Black
= { 0x0, 0x0, 0x0, 0 };
345 egClearScreen(&Black
);
346 refit_call3_wrapper(BS
->WaitForEvent
, 1, &ST
->ConIn
->WaitForKey
, &index
);
347 if (AllowGraphicsMode
)
348 SwitchToGraphicsAndClear();
350 } // VOID SaveScreen()
353 // generic menu function
355 static UINTN
RunGenericMenu(IN REFIT_MENU_SCREEN
*Screen
, IN MENU_STYLE_FUNC StyleFunc
, IN OUT INTN
*DefaultEntryIndex
,
356 OUT REFIT_MENU_ENTRY
**ChosenEntry
)
363 BOOLEAN HaveTimeout
= FALSE
;
364 UINTN TimeoutCountdown
= 0;
365 INTN PreviousTime
= -1, CurrentTime
, TimeSinceKeystroke
= 0;
366 CHAR16 TimeoutMessage
[256];
367 CHAR16 KeyAsString
[2];
369 // EG_PIXEL Black = { 0x0, 0x0, 0x0, 0 };
371 if (Screen
->TimeoutSeconds
> 0) {
373 TimeoutCountdown
= Screen
->TimeoutSeconds
* 10;
377 StyleFunc(Screen
, &State
, MENU_FUNCTION_INIT
, NULL
);
378 IdentifyRows(&State
, Screen
);
379 // override the starting selection with the default index, if any
380 if (*DefaultEntryIndex
>= 0 && *DefaultEntryIndex
<= State
.MaxIndex
) {
381 State
.CurrentSelection
= *DefaultEntryIndex
;
382 if (GlobalConfig
.ScreensaverTime
!= -1)
383 UpdateScroll(&State
, SCROLL_NONE
);
385 if (GlobalConfig
.ScreensaverTime
!= -1)
386 State
.PaintAll
= TRUE
;
390 if (State
.PaintAll
&& (GlobalConfig
.ScreensaverTime
!= -1)) {
391 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
392 State
.PaintAll
= FALSE
;
393 } else if (State
.PaintSelection
) {
394 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_SELECTION
, NULL
);
395 State
.PaintSelection
= FALSE
;
399 CurrentTime
= (TimeoutCountdown
+ 5) / 10;
400 if (CurrentTime
!= PreviousTime
) {
401 SPrint(TimeoutMessage
, 255, L
"%s in %d seconds", Screen
->TimeoutText
, CurrentTime
);
402 if (GlobalConfig
.ScreensaverTime
!= -1)
403 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, TimeoutMessage
);
404 PreviousTime
= CurrentTime
;
408 // read key press (and wait for it if applicable)
409 Status
= refit_call2_wrapper(ST
->ConIn
->ReadKeyStroke
, ST
->ConIn
, &key
);
410 if (Status
!= EFI_SUCCESS
) {
411 if (HaveTimeout
&& TimeoutCountdown
== 0) {
413 MenuExit
= MENU_EXIT_TIMEOUT
;
415 } else if (HaveTimeout
) {
416 refit_call1_wrapper(BS
->Stall
, 100000); // Pause for 100 ms
418 TimeSinceKeystroke
++;
419 } else if (GlobalConfig
.ScreensaverTime
> 0) {
420 refit_call1_wrapper(BS
->Stall
, 100000); // Pause for 100 ms
421 TimeSinceKeystroke
++;
422 if (TimeSinceKeystroke
> (GlobalConfig
.ScreensaverTime
* 10)) {
424 State
.PaintAll
= TRUE
;
425 TimeSinceKeystroke
= 0;
428 refit_call3_wrapper(BS
->WaitForEvent
, 1, &ST
->ConIn
->WaitForKey
, &index
);
432 TimeSinceKeystroke
= 0;
433 } // if/else !read keystroke
436 // the user pressed a key, cancel the timeout
437 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, L
"");
439 if (GlobalConfig
.ScreensaverTime
== -1) { // cancel start-with-blank-screen coding
440 GlobalConfig
.ScreensaverTime
= 0;
441 if (!GlobalConfig
.TextOnly
)
442 BltClearScreen(TRUE
);
446 // react to key press
447 switch (key
.ScanCode
) {
449 UpdateScroll(&State
, SCROLL_LINE_UP
);
452 UpdateScroll(&State
, SCROLL_LINE_LEFT
);
455 UpdateScroll(&State
, SCROLL_LINE_DOWN
);
458 UpdateScroll(&State
, SCROLL_LINE_RIGHT
);
461 UpdateScroll(&State
, SCROLL_FIRST
);
464 UpdateScroll(&State
, SCROLL_LAST
);
467 UpdateScroll(&State
, SCROLL_PAGE_UP
);
470 UpdateScroll(&State
, SCROLL_PAGE_DOWN
);
473 MenuExit
= MENU_EXIT_ESCAPE
;
477 MenuExit
= MENU_EXIT_DETAILS
;
484 MenuExit
= MENU_EXIT_ESCAPE
;
487 switch (key
.UnicodeChar
) {
489 case CHAR_CARRIAGE_RETURN
:
491 MenuExit
= MENU_EXIT_ENTER
;
494 MenuExit
= MENU_EXIT_DETAILS
;
497 KeyAsString
[0] = key
.UnicodeChar
;
499 ShortcutEntry
= FindMenuShortcutEntry(Screen
, KeyAsString
);
500 if (ShortcutEntry
>= 0) {
501 State
.CurrentSelection
= ShortcutEntry
;
502 MenuExit
= MENU_EXIT_ENTER
;
508 StyleFunc(Screen
, &State
, MENU_FUNCTION_CLEANUP
, NULL
);
511 *ChosenEntry
= Screen
->Entries
[State
.CurrentSelection
];
512 *DefaultEntryIndex
= State
.CurrentSelection
;
514 } /* static UINTN RunGenericMenu() */
517 // text-mode generic style
520 // Show information lines in text mode.
521 static VOID
ShowTextInfoLines(IN REFIT_MENU_SCREEN
*Screen
) {
524 BeginTextScreen(Screen
->Title
);
525 if (Screen
->InfoLineCount
> 0) {
526 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
527 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
528 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, 4 + i
);
529 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->InfoLines
[i
]);
532 } // VOID ShowTextInfoLines()
534 // Do most of the work for text-based menus....
535 static VOID
TextMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
538 UINTN MenuWidth
, ItemWidth
, MenuHeight
;
539 static UINTN MenuPosY
;
540 static CHAR16
**DisplayStrings
;
541 CHAR16 TimeoutMessage
[256];
543 State
->ScrollMode
= SCROLL_MODE_TEXT
;
546 case MENU_FUNCTION_INIT
:
549 if (Screen
->InfoLineCount
> 0)
550 MenuPosY
+= Screen
->InfoLineCount
+ 1;
551 MenuHeight
= ConHeight
- MenuPosY
- 3;
552 if (Screen
->TimeoutSeconds
> 0)
554 InitScroll(State
, Screen
->EntryCount
, MenuHeight
);
556 // determine width of the menu
557 MenuWidth
= 20; // minimum
558 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
559 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
560 if (MenuWidth
< ItemWidth
)
561 MenuWidth
= ItemWidth
;
564 if (MenuWidth
> ConWidth
- 3)
565 MenuWidth
= ConWidth
- 3;
567 // prepare strings for display
568 DisplayStrings
= AllocatePool(sizeof(CHAR16
*) * Screen
->EntryCount
);
569 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
570 // Note: Theoretically, SPrint() is a cleaner way to do this; but the
571 // description of the StrSize parameter to SPrint implies it's measured
572 // in characters, but in practice both TianoCore and GNU-EFI seem to
573 // use bytes instead, resulting in truncated displays. I could just
574 // double the size of the StrSize parameter, but that seems unsafe in
575 // case a future library change starts treating this as characters, so
576 // I'm doing it the hard way in this instance.
577 // TODO: Review the above and possibly change other uses of SPrint()
578 DisplayStrings
[i
] = AllocateZeroPool(2 * sizeof(CHAR16
));
579 DisplayStrings
[i
][0] = L
' ';
580 MergeStrings(&DisplayStrings
[i
], Screen
->Entries
[i
]->Title
, 0);
581 if (StrLen(DisplayStrings
[i
]) > MenuWidth
)
582 DisplayStrings
[i
][MenuWidth
- 1] = 0;
583 // TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
584 // TODO: account for double-width characters
589 case MENU_FUNCTION_CLEANUP
:
590 // release temporary memory
591 for (i
= 0; i
<= State
->MaxIndex
; i
++)
592 MyFreePool(DisplayStrings
[i
]);
593 MyFreePool(DisplayStrings
);
596 case MENU_FUNCTION_PAINT_ALL
:
597 // paint the whole screen (initially and after scrolling)
599 ShowTextInfoLines(Screen
);
600 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
601 if (i
>= State
->FirstVisible
&& i
<= State
->LastVisible
) {
602 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2, MenuPosY
+ (i
- State
->FirstVisible
));
603 if (i
== State
->CurrentSelection
)
604 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
606 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
607 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[i
]);
610 // scrolling indicators
611 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_SCROLLARROW
);
612 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
);
613 if (State
->FirstVisible
> 0)
614 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowUp
);
616 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
617 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
+ State
->MaxVisible
);
618 if (State
->LastVisible
< State
->MaxIndex
)
619 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowDown
);
621 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
622 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
623 if (Screen
->Hint1
!= NULL
) {
624 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 2);
625 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint1
);
627 if (Screen
->Hint2
!= NULL
) {
628 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 1);
629 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint2
);
634 case MENU_FUNCTION_PAINT_SELECTION
:
635 // redraw selection cursor
636 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
637 MenuPosY
+ (State
->PreviousSelection
- State
->FirstVisible
));
638 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
639 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->PreviousSelection
]);
640 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
641 MenuPosY
+ (State
->CurrentSelection
- State
->FirstVisible
));
642 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
643 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->CurrentSelection
]);
646 case MENU_FUNCTION_PAINT_TIMEOUT
:
647 if (ParamText
[0] == 0) {
649 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
650 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 3);
651 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, BlankLine
+ 1);
653 // paint or update message
654 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_ERROR
);
655 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, ConHeight
- 3);
656 SPrint(TimeoutMessage
, 255, L
"%s ", ParamText
);
657 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, TimeoutMessage
);
665 // graphical generic style
668 inline static UINTN
TextLineHeight(VOID
) {
669 return egGetFontHeight() + TEXT_YMARGIN
* 2;
670 } // UINTN TextLineHeight()
676 // Display text with a solid background (MenuBackgroundPixel or SelectionBackgroundPixel).
677 // Indents text by one character and placed TEXT_YMARGIN pixels down from the
678 // specified XPos and YPos locations.
679 static VOID
DrawText(IN CHAR16
*Text
, IN BOOLEAN Selected
, IN UINTN FieldWidth
, IN UINTN XPos
, IN UINTN YPos
)
681 EG_IMAGE
*TextBuffer
;
684 TextBuffer
= egCreateImage(FieldWidth
, TextLineHeight(), FALSE
);
686 egFillImage(TextBuffer
, &MenuBackgroundPixel
);
687 Bg
= MenuBackgroundPixel
;
689 // draw selection bar background
690 egFillImageArea(TextBuffer
, 0, 0, FieldWidth
, TextBuffer
->Height
, &SelectionBackgroundPixel
);
691 Bg
= SelectionBackgroundPixel
;
695 egRenderText(Text
, TextBuffer
, egGetFontCellWidth(), TEXT_YMARGIN
, (Bg
.r
+ Bg
.g
+ Bg
.b
) / 3);
696 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
697 // BltImage(TextBuffer, XPos, YPos);
700 // Finds the average brightness of the input Image.
701 // NOTE: Passing an Image that covers the whole screen can strain the
702 // capacity of a UINTN on a 32-bit system with a very large display.
703 // Using UINT64 instead is unworkable, since the code won't compile
704 // on a 32-bit system. As the intended use for this function is to handle
705 // a single text string's background, this shouldn't be a problem, but it
706 // may need addressing if it's applied more broadly....
707 static UINT8
AverageBrightness(EG_IMAGE
*Image
) {
712 for (i
= 0; i
< (Image
->Width
* Image
->Height
); i
++) {
713 Sum
+= (Image
->PixelData
[i
].r
+ Image
->PixelData
[i
].g
+ Image
->PixelData
[i
].b
);
716 return (UINT8
) (Sum
/ (Image
->Width
* Image
->Height
* 3));
717 } // UINT8 AverageBrightness()
719 // Display text against the screen's background image. Special case: If Text is NULL
720 // or 0-length, clear the line. Does NOT indent the text or reposition it relative
721 // to the specified XPos and YPos values.
722 static VOID
DrawTextWithTransparency(IN CHAR16
*Text
, IN UINTN XPos
, IN UINTN YPos
)
725 EG_IMAGE
*TextBuffer
= NULL
;
730 egMeasureText(Text
, &TextWidth
, NULL
);
731 if (TextWidth
== 0) {
732 TextWidth
= UGAWidth
;
736 TextBuffer
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
, TextWidth
, TextLineHeight());
737 if (TextBuffer
== NULL
)
741 egRenderText(Text
, TextBuffer
, 0, 0, AverageBrightness(TextBuffer
));
742 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
743 egFreeImage(TextBuffer
);
746 // Compute the size & position of the window that will hold a subscreen's information.
747 static VOID
ComputeSubScreenWindowSize(REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*XPos
, UINTN
*YPos
,
748 UINTN
*Width
, UINTN
*Height
, UINTN
*LineWidth
) {
749 UINTN i
, ItemWidth
, HintTop
, BannerBottomEdge
, TitleWidth
;
750 UINTN FontCellWidth
= egGetFontCellWidth();
751 UINTN FontCellHeight
= egGetFontHeight();
755 TitleWidth
= egComputeTextWidth(Screen
->Title
);
757 for (i
= 0; i
< Screen
->InfoLineCount
; i
++) {
758 ItemWidth
= StrLen(Screen
->InfoLines
[i
]);
759 if (*Width
< ItemWidth
) {
764 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
765 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
766 if (*Width
< ItemWidth
) {
771 *Width
= (*Width
+ 2) * FontCellWidth
;
773 if (Screen
->TitleImage
)
774 *Width
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
* 2 + FontCellWidth
);
776 *Width
+= FontCellWidth
;
778 if (*Width
< TitleWidth
)
779 *Width
= TitleWidth
+ 2 * FontCellWidth
;
781 // Keep it within the bounds of the screen, or 2/3 of the screen's width
782 // for screens over 800 pixels wide
783 if (*Width
> UGAWidth
)
786 *XPos
= (UGAWidth
- *Width
) / 2;
788 HintTop
= UGAHeight
- (FontCellHeight
* 3); // top of hint text
789 *Height
*= TextLineHeight();
790 if (Screen
->TitleImage
&& (*Height
< (Screen
->TitleImage
->Height
+ TextLineHeight() * 4)))
791 *Height
= Screen
->TitleImage
->Height
+ TextLineHeight() * 4;
793 if (GlobalConfig
.BannerBottomEdge
>= HintTop
) { // probably a full-screen image; treat it as an empty banner
794 BannerBottomEdge
= 0;
796 BannerBottomEdge
= GlobalConfig
.BannerBottomEdge
;
798 if (*Height
> (HintTop
- BannerBottomEdge
- FontCellHeight
* 2)) {
799 BannerBottomEdge
= 0;
801 if (*Height
> (HintTop
- BannerBottomEdge
- FontCellHeight
* 2)) {
802 // TODO: Implement scrolling in text screen.
803 *Height
= (HintTop
- BannerBottomEdge
- FontCellHeight
* 2);
806 *YPos
= ((UGAHeight
- *Height
) / 2);
807 if (*YPos
< BannerBottomEdge
)
808 *YPos
= BannerBottomEdge
+ FontCellHeight
+ (HintTop
- BannerBottomEdge
- *Height
) / 2;
809 } // VOID ComputeSubScreenWindowSize()
811 // Displays sub-menus
812 static VOID
GraphicsMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
816 static UINTN LineWidth
, MenuWidth
, MenuHeight
, EntriesPosX
, TitlePosX
, EntriesPosY
, TimeoutPosY
, CharWidth
;
818 EG_PIXEL
*BackgroundPixel
= &(GlobalConfig
.ScreenBackground
->PixelData
[0]);
820 CharWidth
= egGetFontCellWidth();
821 State
->ScrollMode
= SCROLL_MODE_TEXT
;
824 case MENU_FUNCTION_INIT
:
825 InitScroll(State
, Screen
->EntryCount
, 0);
826 ComputeSubScreenWindowSize(Screen
, State
, &EntriesPosX
, &EntriesPosY
, &MenuWidth
, &MenuHeight
, &LineWidth
);
827 TimeoutPosY
= EntriesPosY
+ (Screen
->EntryCount
+ 1) * TextLineHeight();
830 SwitchToGraphicsAndClear();
831 Window
= egCreateFilledImage(MenuWidth
, MenuHeight
, FALSE
, BackgroundPixel
);
832 egDrawImage(Window
, EntriesPosX
, EntriesPosY
);
833 ItemWidth
= egComputeTextWidth(Screen
->Title
);
834 if (MenuWidth
> ItemWidth
) {
835 TitlePosX
= EntriesPosX
+ (MenuWidth
- ItemWidth
) / 2 - CharWidth
;
837 TitlePosX
= EntriesPosX
;
839 i
= MenuWidth
/ CharWidth
- 2;
841 Screen
->Title
[i
] = 0;
846 case MENU_FUNCTION_CLEANUP
:
850 case MENU_FUNCTION_PAINT_ALL
:
851 ComputeSubScreenWindowSize(Screen
, State
, &EntriesPosX
, &EntriesPosY
, &MenuWidth
, &MenuHeight
, &LineWidth
);
852 DrawText(Screen
->Title
, FALSE
, (StrLen(Screen
->Title
) + 2) * CharWidth
, TitlePosX
, EntriesPosY
+= TextLineHeight());
853 if (Screen
->TitleImage
) {
854 BltImageAlpha(Screen
->TitleImage
, EntriesPosX
+ TITLEICON_SPACING
, EntriesPosY
+ TextLineHeight() * 2,
856 EntriesPosX
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
* 2);
858 EntriesPosY
+= (TextLineHeight() * 2);
859 if (Screen
->InfoLineCount
> 0) {
860 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
861 DrawText(Screen
->InfoLines
[i
], FALSE
, LineWidth
, EntriesPosX
, EntriesPosY
);
862 EntriesPosY
+= TextLineHeight();
864 EntriesPosY
+= TextLineHeight(); // also add a blank line
867 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
868 DrawText(Screen
->Entries
[i
]->Title
, (i
== State
->CurrentSelection
), LineWidth
, EntriesPosX
,
869 EntriesPosY
+ i
* TextLineHeight());
871 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
872 if ((Screen
->Hint1
!= NULL
) && (StrLen(Screen
->Hint1
) > 0))
873 DrawTextWithTransparency(Screen
->Hint1
, (UGAWidth
- egComputeTextWidth(Screen
->Hint1
)) / 2,
874 UGAHeight
- (egGetFontHeight() * 3));
875 if ((Screen
->Hint2
!= NULL
) && (StrLen(Screen
->Hint2
) > 0))
876 DrawTextWithTransparency(Screen
->Hint2
, (UGAWidth
- egComputeTextWidth(Screen
->Hint2
)) / 2,
877 UGAHeight
- (egGetFontHeight() * 2));
881 case MENU_FUNCTION_PAINT_SELECTION
:
882 // redraw selection cursor
883 DrawText(Screen
->Entries
[State
->PreviousSelection
]->Title
, FALSE
, LineWidth
,
884 EntriesPosX
, EntriesPosY
+ State
->PreviousSelection
* TextLineHeight());
885 DrawText(Screen
->Entries
[State
->CurrentSelection
]->Title
, TRUE
, LineWidth
,
886 EntriesPosX
, EntriesPosY
+ State
->CurrentSelection
* TextLineHeight());
889 case MENU_FUNCTION_PAINT_TIMEOUT
:
890 DrawText(ParamText
, FALSE
, LineWidth
, EntriesPosX
, TimeoutPosY
);
894 } // static VOID GraphicsMenuStyle()
897 // graphical main menu style
900 static VOID
DrawMainMenuEntry(REFIT_MENU_ENTRY
*Entry
, BOOLEAN selected
, UINTN XPos
, UINTN YPos
)
902 EG_IMAGE
*Background
;
904 if (SelectionImages
!= NULL
) {
906 Background
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
,
907 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
908 egComposeImage(Background
, SelectionImages
[Entry
->Row
], 0, 0);
909 BltImageCompositeBadge(Background
, Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
);
910 } else { // Image not selected; copy background
911 egDrawImageWithTransparency(Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
,
912 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
915 } // VOID DrawMainMenuEntry()
917 static VOID
PaintAll(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
918 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
921 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0)
922 AdjustScrollState(State
);
923 for (i
= State
->FirstVisible
; i
<= State
->MaxIndex
; i
++) {
924 if (Screen
->Entries
[i
]->Row
== 0) {
925 if (i
<= State
->LastVisible
) {
926 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
,
927 itemPosX
[i
- State
->FirstVisible
], row0PosY
);
930 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
, itemPosX
[i
], row1PosY
);
933 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
)) {
934 DrawTextWithTransparency(L
"", 0, textPosY
);
935 DrawTextWithTransparency(Screen
->Entries
[State
->CurrentSelection
]->Title
,
936 (UGAWidth
- egComputeTextWidth(Screen
->Entries
[State
->CurrentSelection
]->Title
)) >> 1,
940 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
941 DrawTextWithTransparency(Screen
->Hint1
, (UGAWidth
- egComputeTextWidth(Screen
->Hint1
)) / 2,
942 UGAHeight
- (egGetFontHeight() * 3));
943 DrawTextWithTransparency(Screen
->Hint2
, (UGAWidth
- egComputeTextWidth(Screen
->Hint2
)) / 2,
944 UGAHeight
- (egGetFontHeight() * 2));
946 } // static VOID PaintAll()
948 // Move the selection to State->CurrentSelection, adjusting icon row if necessary...
949 static VOID
PaintSelection(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
950 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
951 UINTN XSelectPrev
, XSelectCur
, YPosPrev
, YPosCur
;
953 if (((State
->CurrentSelection
<= State
->LastVisible
) && (State
->CurrentSelection
>= State
->FirstVisible
)) ||
954 (State
->CurrentSelection
>= State
->InitialRow1
) ) {
955 if (Screen
->Entries
[State
->PreviousSelection
]->Row
== 0) {
956 XSelectPrev
= State
->PreviousSelection
- State
->FirstVisible
;
959 XSelectPrev
= State
->PreviousSelection
;
962 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0) {
963 XSelectCur
= State
->CurrentSelection
- State
->FirstVisible
;
966 XSelectCur
= State
->CurrentSelection
;
969 DrawMainMenuEntry(Screen
->Entries
[State
->PreviousSelection
], FALSE
, itemPosX
[XSelectPrev
], YPosPrev
);
970 DrawMainMenuEntry(Screen
->Entries
[State
->CurrentSelection
], TRUE
, itemPosX
[XSelectCur
], YPosCur
);
971 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
)) {
972 DrawTextWithTransparency(L
"", 0, textPosY
);
973 DrawTextWithTransparency(Screen
->Entries
[State
->CurrentSelection
]->Title
,
974 (UGAWidth
- egComputeTextWidth(Screen
->Entries
[State
->CurrentSelection
]->Title
)) >> 1,
977 } else { // Current selection not visible; must redraw the menu....
978 MainMenuStyle(Screen
, State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
980 } // static VOID MoveSelection(VOID)
982 // Display a 48x48 icon at the specified location. Uses the image specified by
983 // ExternalFilename if it's available, or BuiltInImage if it's not. The
984 // Y position is specified as the center value, and so is adjusted by half
985 // the icon's height. The X position is set along the icon's left
986 // edge if Alignment == ALIGN_LEFT, and along the right edge if
987 // Alignment == ALIGN_RIGHT
988 static VOID
PaintIcon(IN EG_EMBEDDED_IMAGE
*BuiltInIcon
, IN CHAR16
*ExternalFilename
, UINTN PosX
, UINTN PosY
, UINTN Alignment
) {
989 EG_IMAGE
*Icon
= NULL
;
991 Icon
= egFindIcon(ExternalFilename
, GlobalConfig
.IconSizes
[ICON_SIZE_SMALL
]);
993 Icon
= egPrepareEmbeddedImage(BuiltInIcon
, TRUE
);
995 if (Alignment
== ALIGN_RIGHT
)
997 egDrawImageWithTransparency(Icon
, NULL
, PosX
, PosY
- (Icon
->Height
/ 2), Icon
->Width
, Icon
->Height
);
1001 inline UINTN
ComputeRow0PosY(VOID
) {
1002 return ((UGAHeight
/ 2) - TileSizes
[0] / 2);
1003 } // UINTN ComputeRow0PosY()
1005 // Display (or erase) the arrow icons to the left and right of an icon's row,
1007 static VOID
PaintArrows(SCROLL_STATE
*State
, UINTN PosX
, UINTN PosY
, UINTN row0Loaders
) {
1008 EG_IMAGE
*TempImage
;
1009 UINTN Width
, Height
, RightX
, AdjPosY
;
1011 // NOTE: Assume that left and right arrows are of the same size....
1012 Width
= egemb_arrow_left
.Width
;
1013 Height
= egemb_arrow_left
.Height
;
1014 RightX
= (UGAWidth
+ (TileSizes
[0] + TILE_XSPACING
) * State
->MaxVisible
) / 2 + TILE_XSPACING
;
1015 AdjPosY
= PosY
- (Height
/ 2);
1017 // For PaintIcon() calls, the starting Y position is moved to the midpoint
1018 // of the surrounding row; PaintIcon() adjusts this back up by half the
1019 // icon's height to properly center it.
1020 if ((State
->FirstVisible
> 0) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
1021 PaintIcon(&egemb_arrow_left
, L
"arrow_left", PosX
, PosY
, ALIGN_RIGHT
);
1023 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, PosX
- Width
, AdjPosY
, Width
, Height
);
1024 BltImage(TempImage
, PosX
- Width
, AdjPosY
);
1025 egFreeImage(TempImage
);
1028 if ((State
->LastVisible
< (row0Loaders
- 1)) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
1029 PaintIcon(&egemb_arrow_right
, L
"arrow_right", RightX
, PosY
, ALIGN_LEFT
);
1031 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, RightX
, AdjPosY
, Width
, Height
);
1032 BltImage(TempImage
, RightX
, AdjPosY
);
1033 egFreeImage(TempImage
);
1035 } // VOID PaintArrows()
1037 // Display main menu in graphics mode
1038 VOID
MainMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
1041 static UINTN row0PosX
, row0PosXRunning
, row1PosY
, row0Loaders
;
1042 UINTN row0Count
, row1Count
, row1PosX
, row1PosXRunning
;
1043 static UINTN
*itemPosX
;
1044 static UINTN row0PosY
, textPosY
;
1046 State
->ScrollMode
= SCROLL_MODE_ICONS
;
1049 case MENU_FUNCTION_INIT
:
1050 InitScroll(State
, Screen
->EntryCount
, GlobalConfig
.MaxTags
);
1056 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
1057 if (Screen
->Entries
[i
]->Row
== 1) {
1061 if (row0Count
< State
->MaxVisible
)
1065 row0PosX
= (UGAWidth
+ TILE_XSPACING
- (TileSizes
[0] + TILE_XSPACING
) * row0Count
) >> 1;
1066 row0PosY
= ComputeRow0PosY();
1067 row1PosX
= (UGAWidth
+ TILE_XSPACING
- (TileSizes
[1] + TILE_XSPACING
) * row1Count
) >> 1;
1068 row1PosY
= row0PosY
+ TileSizes
[0] + TILE_YSPACING
;
1070 textPosY
= row1PosY
+ TileSizes
[1] + TILE_YSPACING
;
1072 textPosY
= row1PosY
;
1074 itemPosX
= AllocatePool(sizeof(UINTN
) * Screen
->EntryCount
);
1075 row0PosXRunning
= row0PosX
;
1076 row1PosXRunning
= row1PosX
;
1077 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
1078 if (Screen
->Entries
[i
]->Row
== 0) {
1079 itemPosX
[i
] = row0PosXRunning
;
1080 row0PosXRunning
+= TileSizes
[0] + TILE_XSPACING
;
1082 itemPosX
[i
] = row1PosXRunning
;
1083 row1PosXRunning
+= TileSizes
[1] + TILE_XSPACING
;
1088 SwitchToGraphicsAndClear();
1091 case MENU_FUNCTION_CLEANUP
:
1092 MyFreePool(itemPosX
);
1095 case MENU_FUNCTION_PAINT_ALL
:
1096 PaintAll(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1097 // For PaintArrows(), the starting Y position is moved to the midpoint
1098 // of the surrounding row; PaintIcon() adjusts this back up by half the
1099 // icon's height to properly center it.
1100 PaintArrows(State
, row0PosX
- TILE_XSPACING
, row0PosY
+ (TileSizes
[0] / 2), row0Loaders
);
1103 case MENU_FUNCTION_PAINT_SELECTION
:
1104 PaintSelection(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1107 case MENU_FUNCTION_PAINT_TIMEOUT
:
1108 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
)) {
1109 DrawTextWithTransparency(L
"", 0, textPosY
+ TextLineHeight());
1110 DrawTextWithTransparency(ParamText
, (UGAWidth
- egComputeTextWidth(ParamText
)) >> 1, textPosY
+ TextLineHeight());
1115 } // VOID MainMenuStyle()
1117 // Enable the user to edit boot loader options.
1118 // Returns TRUE if the user exited with edited options; FALSE if the user
1119 // pressed Esc to terminate the edit.
1120 static BOOLEAN
EditOptions(LOADER_ENTRY
*MenuEntry
) {
1122 CHAR16
*EditedOptions
;
1123 BOOLEAN retval
= FALSE
;
1125 if (GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_EDITOR
) {
1129 refit_call4_wrapper(ST
->ConOut
->QueryMode
, ST
->ConOut
, ST
->ConOut
->Mode
->Mode
, &x_max
, &y_max
);
1131 if (!GlobalConfig
.TextOnly
)
1134 if (line_edit(MenuEntry
->LoadOptions
, &EditedOptions
, x_max
)) {
1135 MyFreePool(MenuEntry
->LoadOptions
);
1136 MenuEntry
->LoadOptions
= EditedOptions
;
1139 if (!GlobalConfig
.TextOnly
)
1142 } // VOID EditOptions()
1145 // user-callable dispatcher functions
1148 UINTN
RunMenu(IN REFIT_MENU_SCREEN
*Screen
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1150 INTN DefaultEntry
= -1;
1151 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1153 if (AllowGraphicsMode
)
1154 Style
= GraphicsMenuStyle
;
1156 return RunGenericMenu(Screen
, Style
, &DefaultEntry
, ChosenEntry
);
1159 UINTN
RunMainMenu(REFIT_MENU_SCREEN
*Screen
, CHAR16
** DefaultSelection
, REFIT_MENU_ENTRY
**ChosenEntry
)
1161 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1162 MENU_STYLE_FUNC MainStyle
= TextMenuStyle
;
1163 REFIT_MENU_ENTRY
*TempChosenEntry
;
1166 INTN DefaultEntryIndex
= -1;
1167 INTN DefaultSubmenuIndex
= -1;
1169 TileSizes
[0] = (GlobalConfig
.IconSizes
[ICON_SIZE_BIG
] * 9) / 8;
1170 TileSizes
[1] = (GlobalConfig
.IconSizes
[ICON_SIZE_SMALL
] * 4) / 3;
1172 if ((DefaultSelection
!= NULL
) && (*DefaultSelection
!= NULL
)) {
1173 // Find a menu entry that includes *DefaultSelection as a substring
1174 DefaultEntryIndex
= FindMenuShortcutEntry(Screen
, *DefaultSelection
);
1177 if (AllowGraphicsMode
) {
1178 Style
= GraphicsMenuStyle
;
1179 MainStyle
= MainMenuStyle
;
1183 MenuExit
= RunGenericMenu(Screen
, MainStyle
, &DefaultEntryIndex
, &TempChosenEntry
);
1184 Screen
->TimeoutSeconds
= 0;
1186 MenuTitle
= StrDuplicate(TempChosenEntry
->Title
);
1187 if (MenuExit
== MENU_EXIT_DETAILS
) {
1188 if (TempChosenEntry
->SubScreen
!= NULL
) {
1189 MenuExit
= RunGenericMenu(TempChosenEntry
->SubScreen
, Style
, &DefaultSubmenuIndex
, &TempChosenEntry
);
1190 if (MenuExit
== MENU_EXIT_ESCAPE
|| TempChosenEntry
->Tag
== TAG_RETURN
)
1192 if (MenuExit
== MENU_EXIT_DETAILS
) {
1193 if (!EditOptions((LOADER_ENTRY
*) TempChosenEntry
))
1196 } else { // no sub-screen; ignore keypress
1199 } // Enter sub-screen
1203 *ChosenEntry
= TempChosenEntry
;
1204 if (DefaultSelection
) {
1205 MyFreePool(*DefaultSelection
);
1206 *DefaultSelection
= MenuTitle
;
1209 } /* UINTN RunMainMenu() */