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_arrow_left.h"
56 #include "../include/egemb_arrow_right.h"
58 // other menu definitions
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)
67 typedef VOID (*MENU_STYLE_FUNC
)(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
);
69 static CHAR16 ArrowUp
[2] = { ARROW_UP
, 0 };
70 static CHAR16 ArrowDown
[2] = { ARROW_DOWN
, 0 };
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)
78 #define ROW0_TILESIZE (144)
79 #define ROW1_TILESIZE (64)
80 #define TILE_XSPACING (8)
81 #define TILE_YSPACING (16)
83 // Alignment values for PaintIcon()
87 static EG_IMAGE
*SelectionImages
[2] = { NULL
, NULL
};
88 static EG_PIXEL SelectionBackgroundPixel
= { 0xff, 0xff, 0xff, 0 };
91 // Graphics helper functions
94 static VOID
InitSelection(VOID
)
96 UINTN x
, y
, src_x
, src_y
;
97 EG_PIXEL
*DestPtr
, *SrcPtr
;
99 if (!AllowGraphicsMode
)
101 if (SelectionImages
[0] != NULL
)
104 // load small selection image
105 if (GlobalConfig
.SelectionSmallFileName
!= NULL
) {
106 SelectionImages
[1] = egLoadImage(SelfDir
, GlobalConfig
.SelectionSmallFileName
, TRUE
);
108 if (SelectionImages
[1] == NULL
)
109 SelectionImages
[1] = egPrepareEmbeddedImage(&egemb_back_selected_small
, TRUE
);
110 SelectionImages
[1] = egEnsureImageSize(SelectionImages
[1], ROW1_TILESIZE
, ROW1_TILESIZE
, &MenuBackgroundPixel
);
111 if (SelectionImages
[1] == NULL
)
114 // load big selection image
115 if (GlobalConfig
.SelectionBigFileName
!= NULL
) {
116 SelectionImages
[0] = egLoadImage(SelfDir
, GlobalConfig
.SelectionBigFileName
, TRUE
);
117 SelectionImages
[0] = egEnsureImageSize(SelectionImages
[0], ROW0_TILESIZE
, ROW0_TILESIZE
, &MenuBackgroundPixel
);
119 if (SelectionImages
[0] == NULL
) {
120 // calculate big selection image from small one
122 SelectionImages
[0] = egCreateImage(ROW0_TILESIZE
, ROW0_TILESIZE
, TRUE
);
123 if (SelectionImages
[0] == NULL
) {
124 egFreeImage(SelectionImages
[1]);
125 SelectionImages
[1] = NULL
;
129 DestPtr
= SelectionImages
[0]->PixelData
;
130 SrcPtr
= SelectionImages
[1]->PixelData
;
131 for (y
= 0; y
< ROW0_TILESIZE
; y
++) {
132 if (y
< (ROW1_TILESIZE
>> 1))
134 else if (y
< (ROW0_TILESIZE
- (ROW1_TILESIZE
>> 1)))
135 src_y
= (ROW1_TILESIZE
>> 1);
137 src_y
= y
- (ROW0_TILESIZE
- ROW1_TILESIZE
);
139 for (x
= 0; x
< ROW0_TILESIZE
; x
++) {
140 if (x
< (ROW1_TILESIZE
>> 1))
142 else if (x
< (ROW0_TILESIZE
- (ROW1_TILESIZE
>> 1)))
143 src_x
= (ROW1_TILESIZE
>> 1);
145 src_x
= x
- (ROW0_TILESIZE
- ROW1_TILESIZE
);
147 *DestPtr
++ = SrcPtr
[src_y
* ROW1_TILESIZE
+ src_x
];
151 } // VOID InitSelection()
154 // Scrolling functions
157 static VOID
InitScroll(OUT SCROLL_STATE
*State
, IN UINTN ItemCount
, IN UINTN VisibleSpace
)
159 State
->PreviousSelection
= State
->CurrentSelection
= 0;
160 State
->MaxIndex
= (INTN
)ItemCount
- 1;
161 State
->FirstVisible
= 0;
162 if (AllowGraphicsMode
) {
163 State
->MaxVisible
= UGAWidth
/ (ROW0_TILESIZE
+ TILE_XSPACING
) - 1;
165 State
->MaxVisible
= ConHeight
- 4;
166 if ((VisibleSpace
> 0) && (VisibleSpace
< State
->MaxVisible
))
167 State
->MaxVisible
= (INTN
)VisibleSpace
;
168 State
->PaintAll
= TRUE
;
169 State
->PaintSelection
= FALSE
;
171 State
->LastVisible
= State
->FirstVisible
+ State
->MaxVisible
- 1;
174 // Adjust variables relating to the scrolling of tags, for when a selected icon isn't
175 // visible given the current scrolling condition....
176 static VOID
AdjustScrollState(IN SCROLL_STATE
*State
) {
177 if (State
->CurrentSelection
> State
->LastVisible
) {
178 State
->LastVisible
= State
->CurrentSelection
;
179 State
->FirstVisible
= 1 + State
->CurrentSelection
- State
->MaxVisible
;
180 if (State
->FirstVisible
< 0) // shouldn't happen, but just in case....
181 State
->FirstVisible
= 0;
182 State
->PaintAll
= TRUE
;
184 if (State
->CurrentSelection
< State
->FirstVisible
) {
185 State
->FirstVisible
= State
->CurrentSelection
;
186 State
->LastVisible
= State
->CurrentSelection
+ State
->MaxVisible
- 1;
187 State
->PaintAll
= TRUE
;
189 } // static VOID AdjustScrollState
191 static VOID
UpdateScroll(IN OUT SCROLL_STATE
*State
, IN UINTN Movement
)
193 State
->PreviousSelection
= State
->CurrentSelection
;
196 case SCROLL_LINE_LEFT
:
197 if (State
->CurrentSelection
> 0) {
198 State
->CurrentSelection
--;
202 case SCROLL_LINE_RIGHT
:
203 if (State
->CurrentSelection
< State
->MaxIndex
) {
204 State
->CurrentSelection
++;
209 if (State
->ScrollMode
== SCROLL_MODE_ICONS
) {
210 if (State
->CurrentSelection
>= State
->InitialRow1
) {
211 if (State
->MaxIndex
> State
->InitialRow1
) { // avoid division by 0!
212 State
->CurrentSelection
= State
->FirstVisible
+ (State
->LastVisible
- State
->FirstVisible
) *
213 (State
->CurrentSelection
- State
->InitialRow1
) /
214 (State
->MaxIndex
- State
->InitialRow1
);
216 State
->CurrentSelection
= State
->FirstVisible
;
218 } // if in second row
220 if (State
->CurrentSelection
> 0)
221 State
->CurrentSelection
--;
225 case SCROLL_LINE_DOWN
:
226 if (State
->ScrollMode
== SCROLL_MODE_ICONS
) {
227 if (State
->CurrentSelection
<= State
->FinalRow0
) {
228 if (State
->LastVisible
> State
->FirstVisible
) { // avoid division by 0!
229 State
->CurrentSelection
= State
->InitialRow1
+ (State
->MaxIndex
- State
->InitialRow1
) *
230 (State
->CurrentSelection
- State
->FirstVisible
) /
231 (State
->LastVisible
- State
->FirstVisible
);
233 State
->CurrentSelection
= State
->InitialRow1
;
237 if (State
->CurrentSelection
< State
->MaxIndex
)
238 State
->CurrentSelection
++;
243 if (State
->CurrentSelection
<= State
->FinalRow0
)
244 State
->CurrentSelection
-= State
->MaxVisible
;
245 else if (State
->CurrentSelection
== State
->InitialRow1
)
246 State
->CurrentSelection
= State
->FinalRow0
;
248 State
->CurrentSelection
= State
->InitialRow1
;
249 if (State
->CurrentSelection
< 0)
250 State
->CurrentSelection
= 0;
254 if (State
->CurrentSelection
> 0) {
255 State
->PaintAll
= TRUE
;
256 State
->CurrentSelection
= 0;
260 case SCROLL_PAGE_DOWN
:
261 if (State
->CurrentSelection
< State
->FinalRow0
) {
262 State
->CurrentSelection
+= State
->MaxVisible
;
263 if (State
->CurrentSelection
> State
->FinalRow0
)
264 State
->CurrentSelection
= State
->FinalRow0
;
265 } else if (State
->CurrentSelection
== State
->FinalRow0
) {
266 State
->CurrentSelection
++;
268 State
->CurrentSelection
= State
->MaxIndex
;
270 if (State
->CurrentSelection
> State
->MaxIndex
)
271 State
->CurrentSelection
= State
->MaxIndex
;
275 if (State
->CurrentSelection
< State
->MaxIndex
) {
276 State
->PaintAll
= TRUE
;
277 State
->CurrentSelection
= State
->MaxIndex
;
285 if (State
->ScrollMode
== SCROLL_MODE_TEXT
)
286 AdjustScrollState(State
);
288 if (!State
->PaintAll
&& State
->CurrentSelection
!= State
->PreviousSelection
)
289 State
->PaintSelection
= TRUE
;
290 State
->LastVisible
= State
->FirstVisible
+ State
->MaxVisible
- 1;
291 } // static VOID UpdateScroll()
294 // menu helper functions
297 VOID
AddMenuInfoLine(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
*InfoLine
)
299 AddListElement((VOID
***) &(Screen
->InfoLines
), &(Screen
->InfoLineCount
), InfoLine
);
302 VOID
AddMenuEntry(IN REFIT_MENU_SCREEN
*Screen
, IN REFIT_MENU_ENTRY
*Entry
)
304 AddListElement((VOID
***) &(Screen
->Entries
), &(Screen
->EntryCount
), Entry
);
308 static INTN
FindMenuShortcutEntry(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
*Shortcut
)
312 if (Shortcut
== NULL
)
315 if (StrLen(Shortcut
) == 1) {
316 if (Shortcut
[0] >= 'a' && Shortcut
[0] <= 'z')
317 Shortcut
[0] -= ('a' - 'A');
319 for (i
= 0; i
< Screen
->EntryCount
; i
++) {
320 if (Screen
->Entries
[i
]->ShortcutDigit
== Shortcut
[0] || Screen
->Entries
[i
]->ShortcutLetter
== Shortcut
[0]) {
325 } else if (StrLen(Shortcut
) > 1) {
326 for (i
= 0; i
< Screen
->EntryCount
; i
++) {
327 if (StriSubCmp(Shortcut
, Screen
->Entries
[i
]->Title
))
334 // Identify the end of row 0 and the beginning of row 1; store the results in the
335 // appropriate fields in State. Also reduce MaxVisible if that value is greater
336 // than the total number of row-0 tags and if we're in an icon-based screen
337 static VOID
IdentifyRows(IN SCROLL_STATE
*State
, IN REFIT_MENU_SCREEN
*Screen
) {
340 State
->FinalRow0
= 0;
341 State
->InitialRow1
= State
->MaxIndex
;
342 for (i
= 0; i
< State
->MaxIndex
; i
++) {
343 if (Screen
->Entries
[i
]->Row
== 0) {
344 State
->FinalRow0
= i
;
345 } else if ((Screen
->Entries
[i
]->Row
== 1) && (State
->InitialRow1
> i
)) {
346 State
->InitialRow1
= i
;
349 if ((State
->ScrollMode
== SCROLL_MODE_ICONS
) && (State
->MaxVisible
> (State
->FinalRow0
+ 1)))
350 State
->MaxVisible
= State
->FinalRow0
+ 1;
351 } // static VOID IdentifyRows()
354 // generic menu function
356 static UINTN
RunGenericMenu(IN REFIT_MENU_SCREEN
*Screen
, IN MENU_STYLE_FUNC StyleFunc
, IN OUT INTN
*DefaultEntryIndex
,
357 OUT REFIT_MENU_ENTRY
**ChosenEntry
)
364 BOOLEAN HaveTimeout
= FALSE
;
365 UINTN TimeoutCountdown
= 0;
366 INTN PreviousTime
= -1, CurrentTime
;
367 CHAR16 TimeoutMessage
[256];
368 CHAR16 KeyAsString
[2];
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 UpdateScroll(&State
, SCROLL_NONE
);
384 State
.PaintAll
= TRUE
;
388 if (State
.PaintAll
) {
389 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
390 State
.PaintAll
= FALSE
;
391 } else if (State
.PaintSelection
) {
392 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_SELECTION
, NULL
);
393 State
.PaintSelection
= FALSE
;
397 CurrentTime
= (TimeoutCountdown
+ 5) / 10;
398 if (CurrentTime
!= PreviousTime
) {
399 SPrint(TimeoutMessage
, 255, L
"%s in %d seconds", Screen
->TimeoutText
, CurrentTime
);
400 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, TimeoutMessage
);
401 PreviousTime
= CurrentTime
;
405 // read key press (and wait for it if applicable)
406 Status
= refit_call2_wrapper(ST
->ConIn
->ReadKeyStroke
, ST
->ConIn
, &key
);
407 if (Status
!= EFI_SUCCESS
) {
408 if (HaveTimeout
&& TimeoutCountdown
== 0) {
410 MenuExit
= MENU_EXIT_TIMEOUT
;
412 } else if (HaveTimeout
) {
413 refit_call1_wrapper(BS
->Stall
, 100000); // Pause for 100 ms
416 refit_call3_wrapper(BS
->WaitForEvent
, 1, &ST
->ConIn
->WaitForKey
, &index
);
421 // the user pressed a key, cancel the timeout
422 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, L
"");
426 // react to key press
427 switch (key
.ScanCode
) {
429 UpdateScroll(&State
, SCROLL_LINE_UP
);
432 UpdateScroll(&State
, SCROLL_LINE_LEFT
);
435 UpdateScroll(&State
, SCROLL_LINE_DOWN
);
438 UpdateScroll(&State
, SCROLL_LINE_RIGHT
);
441 UpdateScroll(&State
, SCROLL_FIRST
);
444 UpdateScroll(&State
, SCROLL_LAST
);
447 UpdateScroll(&State
, SCROLL_PAGE_UP
);
450 UpdateScroll(&State
, SCROLL_PAGE_DOWN
);
453 MenuExit
= MENU_EXIT_ESCAPE
;
457 MenuExit
= MENU_EXIT_DETAILS
;
464 MenuExit
= MENU_EXIT_ESCAPE
;
467 switch (key
.UnicodeChar
) {
469 case CHAR_CARRIAGE_RETURN
:
471 MenuExit
= MENU_EXIT_ENTER
;
474 MenuExit
= MENU_EXIT_DETAILS
;
477 KeyAsString
[0] = key
.UnicodeChar
;
479 ShortcutEntry
= FindMenuShortcutEntry(Screen
, KeyAsString
);
480 if (ShortcutEntry
>= 0) {
481 State
.CurrentSelection
= ShortcutEntry
;
482 MenuExit
= MENU_EXIT_ENTER
;
488 StyleFunc(Screen
, &State
, MENU_FUNCTION_CLEANUP
, NULL
);
491 *ChosenEntry
= Screen
->Entries
[State
.CurrentSelection
];
492 *DefaultEntryIndex
= State
.CurrentSelection
;
494 } /* static UINTN RunGenericMenu() */
497 // text-mode generic style
500 static VOID
TextMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
503 UINTN MenuWidth
, ItemWidth
, MenuHeight
;
504 static UINTN MenuPosY
;
505 static CHAR16
**DisplayStrings
;
506 CHAR16 TimeoutMessage
[256];
508 State
->ScrollMode
= SCROLL_MODE_TEXT
;
511 case MENU_FUNCTION_INIT
:
514 if (Screen
->InfoLineCount
> 0)
515 MenuPosY
+= Screen
->InfoLineCount
+ 1;
516 MenuHeight
= ConHeight
- MenuPosY
- 3;
517 if (Screen
->TimeoutSeconds
> 0)
519 InitScroll(State
, Screen
->EntryCount
, MenuHeight
);
521 // determine width of the menu
522 MenuWidth
= 20; // minimum
523 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
524 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
525 if (MenuWidth
< ItemWidth
)
526 MenuWidth
= ItemWidth
;
529 if (MenuWidth
> ConWidth
- 3)
530 MenuWidth
= ConWidth
- 3;
532 // prepare strings for display
533 DisplayStrings
= AllocatePool(sizeof(CHAR16
*) * Screen
->EntryCount
);
534 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
535 // Note: Theoretically, SPrint() is a cleaner way to do this; but the
536 // description of the StrSize parameter to SPrint implies it's measured
537 // in characters, but in practice both TianoCore and GNU-EFI seem to
538 // use bytes instead, resulting in truncated displays. I could just
539 // double the size of the StrSize parameter, but that seems unsafe in
540 // case a future library change starts treating this as characters, so
541 // I'm doing it the hard way in this instance.
542 // TODO: Review the above and possibly change other uses of SPrint()
543 DisplayStrings
[i
] = AllocateZeroPool(2 * sizeof(CHAR16
));
544 DisplayStrings
[i
][0] = L
' ';
545 MergeStrings(&DisplayStrings
[i
], Screen
->Entries
[i
]->Title
, 0);
546 if (StrLen(DisplayStrings
[i
]) > MenuWidth
)
547 DisplayStrings
[i
][MenuWidth
- 1] = 0;
548 // TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
549 // TODO: account for double-width characters
553 BeginTextScreen(Screen
->Title
);
554 if (Screen
->InfoLineCount
> 0) {
555 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
556 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
557 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, 4 + i
);
558 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->InfoLines
[i
]);
564 case MENU_FUNCTION_CLEANUP
:
565 // release temporary memory
566 for (i
= 0; i
<= State
->MaxIndex
; i
++)
567 MyFreePool(DisplayStrings
[i
]);
568 MyFreePool(DisplayStrings
);
571 case MENU_FUNCTION_PAINT_ALL
:
572 // paint the whole screen (initially and after scrolling)
573 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
574 if (i
>= State
->FirstVisible
&& i
<= State
->LastVisible
) {
575 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2, MenuPosY
+ (i
- State
->FirstVisible
));
576 if (i
== State
->CurrentSelection
)
577 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
579 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
580 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[i
]);
583 // scrolling indicators
584 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_SCROLLARROW
);
585 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
);
586 if (State
->FirstVisible
> 0)
587 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowUp
);
589 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
590 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
+ State
->MaxVisible
);
591 if (State
->LastVisible
< State
->MaxIndex
)
592 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowDown
);
594 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
595 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
596 if (Screen
->Hint1
!= NULL
) {
597 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 2);
598 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint1
);
600 if (Screen
->Hint2
!= NULL
) {
601 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 1);
602 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint2
);
607 case MENU_FUNCTION_PAINT_SELECTION
:
608 // redraw selection cursor
609 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
610 MenuPosY
+ (State
->PreviousSelection
- State
->FirstVisible
));
611 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
612 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->PreviousSelection
]);
613 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
614 MenuPosY
+ (State
->CurrentSelection
- State
->FirstVisible
));
615 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
616 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->CurrentSelection
]);
619 case MENU_FUNCTION_PAINT_TIMEOUT
:
620 if (ParamText
[0] == 0) {
622 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
623 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 3);
624 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, BlankLine
+ 1);
626 // paint or update message
627 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_ERROR
);
628 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, ConHeight
- 3);
629 SPrint(TimeoutMessage
, 255, L
"%s ", ParamText
);
630 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, TimeoutMessage
);
638 // graphical generic style
641 inline static UINTN
TextLineHeight(VOID
) {
642 return egGetFontHeight() + TEXT_YMARGIN
* 2;
643 } // UINTN TextLineHeight()
649 // Display text with a solid background (MenuBackgroundPixel or SelectionBackgroundPixel).
650 // Indents text by one character and placed TEXT_YMARGIN pixels down from the
651 // specified XPos and YPos locations.
652 static VOID
DrawText(IN CHAR16
*Text
, IN BOOLEAN Selected
, IN UINTN FieldWidth
, IN UINTN XPos
, IN UINTN YPos
)
654 EG_IMAGE
*TextBuffer
;
657 TextBuffer
= egCreateImage(FieldWidth
, TextLineHeight(), FALSE
);
659 egFillImage(TextBuffer
, &MenuBackgroundPixel
);
660 Bg
= MenuBackgroundPixel
;
662 // draw selection bar background
663 egFillImageArea(TextBuffer
, 0, 0, FieldWidth
, TextBuffer
->Height
, &SelectionBackgroundPixel
);
664 Bg
= SelectionBackgroundPixel
;
668 egRenderText(Text
, TextBuffer
, egGetFontCellWidth(), TEXT_YMARGIN
, (Bg
.r
+ Bg
.g
+ Bg
.b
) / 3);
669 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
670 // BltImage(TextBuffer, XPos, YPos);
673 // Finds the average brightness of the input Image.
674 // NOTE: Passing an Image that covers the whole screen can strain the
675 // capacity of a UINTN on a 32-bit system with a very large display.
676 // Using UINT64 instead is unworkable, since the code won't compile
677 // on a 32-bit system. As the intended use for this function is to handle
678 // a single text string's background, this shouldn't be a problem, but it
679 // may need addressing if it's applied more broadly....
680 static UINT8
AverageBrightness(EG_IMAGE
*Image
) {
685 for (i
= 0; i
< (Image
->Width
* Image
->Height
); i
++) {
686 Sum
+= (Image
->PixelData
[i
].r
+ Image
->PixelData
[i
].g
+ Image
->PixelData
[i
].b
);
689 return (UINT8
) (Sum
/ (Image
->Width
* Image
->Height
* 3));
690 } // UINT8 AverageBrightness()
692 // Display text against the screen's background image. Special case: If Text is NULL
693 // or 0-length, clear the line. Does NOT indent the text or reposition it relative
694 // to the specified XPos and YPos values.
695 static VOID
DrawTextWithTransparency(IN CHAR16
*Text
, IN UINTN XPos
, IN UINTN YPos
)
698 EG_IMAGE
*TextBuffer
= NULL
;
703 egMeasureText(Text
, &TextWidth
, NULL
);
704 if (TextWidth
== 0) {
705 TextWidth
= UGAWidth
;
709 TextBuffer
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
, TextWidth
, TextLineHeight());
710 if (TextBuffer
== NULL
) {
711 Print(L
"Error: NULL TextBuffer in DrawTextWithTransparency()\n");
716 egRenderText(Text
, TextBuffer
, 0, 0, AverageBrightness(TextBuffer
));
717 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
718 egFreeImage(TextBuffer
);
721 // Compute the size & position of the window that will hold a subscreen's information.
722 static VOID
ComputeSubScreenWindowSize(REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*XPos
, UINTN
*YPos
,
723 UINTN
*Width
, UINTN
*Height
, UINTN
*LineWidth
) {
724 UINTN i
, ItemWidth
, HintTop
, BannerBottomEdge
, TitleWidth
;
725 UINTN FontCellWidth
= egGetFontCellWidth();
726 UINTN FontCellHeight
= egGetFontHeight();
730 TitleWidth
= egComputeTextWidth(Screen
->Title
);
732 for (i
= 0; i
< Screen
->InfoLineCount
; i
++) {
733 ItemWidth
= StrLen(Screen
->InfoLines
[i
]);
734 if (*Width
< ItemWidth
) {
739 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
740 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
741 if (*Width
< ItemWidth
) {
746 *Width
= (*Width
+ 2) * FontCellWidth
;
748 if (Screen
->TitleImage
)
749 *Width
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
* 2 + FontCellWidth
);
751 *Width
+= FontCellWidth
;
753 if (*Width
< TitleWidth
)
754 *Width
= TitleWidth
+ 2 * FontCellWidth
;
756 // Keep it within the bounds of the screen, or 2/3 of the screen's width
757 // for screens over 800 pixels wide
758 if (*Width
> UGAWidth
)
761 *XPos
= (UGAWidth
- *Width
) / 2;
763 HintTop
= UGAHeight
- (FontCellHeight
* 3); // top of hint text
764 *Height
*= TextLineHeight();
765 if (Screen
->TitleImage
&& (*Height
< (Screen
->TitleImage
->Height
+ TextLineHeight() * 4)))
766 *Height
= Screen
->TitleImage
->Height
+ TextLineHeight() * 4;
768 if (GlobalConfig
.BannerBottomEdge
>= HintTop
) { // probably a full-screen image; treat it as an empty banner
769 BannerBottomEdge
= 0;
771 BannerBottomEdge
= GlobalConfig
.BannerBottomEdge
;
773 if (*Height
> (HintTop
- BannerBottomEdge
- FontCellHeight
* 2)) {
774 BannerBottomEdge
= 0;
776 if (*Height
> (HintTop
- BannerBottomEdge
- FontCellHeight
* 2)) {
777 // TODO: Implement scrolling in text screen.
778 *Height
= (HintTop
- BannerBottomEdge
- FontCellHeight
* 2);
781 *YPos
= ((UGAHeight
- *Height
) / 2);
782 if (*YPos
< BannerBottomEdge
)
783 *YPos
= BannerBottomEdge
+ FontCellHeight
+ (HintTop
- BannerBottomEdge
- *Height
) / 2;
784 } // VOID ComputeSubScreenWindowSize()
786 // Displays sub-menus
787 static VOID
GraphicsMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
791 static UINTN LineWidth
, MenuWidth
, MenuHeight
, EntriesPosX
, TitlePosX
, EntriesPosY
, TimeoutPosY
, CharWidth
;
793 EG_PIXEL
*BackgroundPixel
= &(GlobalConfig
.ScreenBackground
->PixelData
[0]);
795 CharWidth
= egGetFontCellWidth();
796 State
->ScrollMode
= SCROLL_MODE_TEXT
;
799 case MENU_FUNCTION_INIT
:
800 InitScroll(State
, Screen
->EntryCount
, 0);
801 ComputeSubScreenWindowSize(Screen
, State
, &EntriesPosX
, &EntriesPosY
, &MenuWidth
, &MenuHeight
, &LineWidth
);
802 TimeoutPosY
= EntriesPosY
+ (Screen
->EntryCount
+ 1) * TextLineHeight();
805 SwitchToGraphicsAndClear();
806 Window
= egCreateFilledImage(MenuWidth
, MenuHeight
, FALSE
, BackgroundPixel
);
807 egDrawImage(Window
, EntriesPosX
, EntriesPosY
);
808 ItemWidth
= egComputeTextWidth(Screen
->Title
);
809 if (MenuWidth
> ItemWidth
) {
810 TitlePosX
= EntriesPosX
+ (MenuWidth
- ItemWidth
) / 2 - CharWidth
;
812 TitlePosX
= EntriesPosX
;
814 i
= MenuWidth
/ CharWidth
- 2;
816 Screen
->Title
[i
] = 0;
820 DrawText(Screen
->Title
, FALSE
, (StrLen(Screen
->Title
) + 2) * CharWidth
, TitlePosX
, EntriesPosY
+= TextLineHeight());
821 if (Screen
->TitleImage
) {
822 BltImageAlpha(Screen
->TitleImage
, EntriesPosX
+ TITLEICON_SPACING
, EntriesPosY
+ TextLineHeight() * 2,
824 EntriesPosX
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
* 2);
826 EntriesPosY
+= (TextLineHeight() * 2);
827 if (Screen
->InfoLineCount
> 0) {
828 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
829 DrawText(Screen
->InfoLines
[i
], FALSE
, LineWidth
, EntriesPosX
, EntriesPosY
);
830 EntriesPosY
+= TextLineHeight();
832 EntriesPosY
+= TextLineHeight(); // also add a blank line
837 case MENU_FUNCTION_CLEANUP
:
841 case MENU_FUNCTION_PAINT_ALL
:
842 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
843 DrawText(Screen
->Entries
[i
]->Title
, (i
== State
->CurrentSelection
), LineWidth
, EntriesPosX
,
844 EntriesPosY
+ i
* TextLineHeight());
846 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
847 if ((Screen
->Hint1
!= NULL
) && (StrLen(Screen
->Hint1
) > 0))
848 DrawTextWithTransparency(Screen
->Hint1
, (UGAWidth
- egComputeTextWidth(Screen
->Hint1
)) / 2,
849 UGAHeight
- (egGetFontHeight() * 3));
850 if ((Screen
->Hint2
!= NULL
) && (StrLen(Screen
->Hint2
) > 0))
851 DrawTextWithTransparency(Screen
->Hint2
, (UGAWidth
- egComputeTextWidth(Screen
->Hint2
)) / 2,
852 UGAHeight
- (egGetFontHeight() * 2));
856 case MENU_FUNCTION_PAINT_SELECTION
:
857 // redraw selection cursor
858 DrawText(Screen
->Entries
[State
->PreviousSelection
]->Title
, FALSE
, LineWidth
,
859 EntriesPosX
, EntriesPosY
+ State
->PreviousSelection
* TextLineHeight());
860 DrawText(Screen
->Entries
[State
->CurrentSelection
]->Title
, TRUE
, LineWidth
,
861 EntriesPosX
, EntriesPosY
+ State
->CurrentSelection
* TextLineHeight());
864 case MENU_FUNCTION_PAINT_TIMEOUT
:
865 DrawText(ParamText
, FALSE
, LineWidth
, EntriesPosX
, TimeoutPosY
);
869 } // static VOID GraphicsMenuStyle()
872 // graphical main menu style
875 static VOID
DrawMainMenuEntry(REFIT_MENU_ENTRY
*Entry
, BOOLEAN selected
, UINTN XPos
, UINTN YPos
)
877 EG_IMAGE
*Background
;
879 if (SelectionImages
!= NULL
) {
881 Background
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
,
882 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
883 egComposeImage(Background
, SelectionImages
[Entry
->Row
], 0, 0);
884 BltImageCompositeBadge(Background
, Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
);
885 } else { // Image not selected; copy background
886 egDrawImageWithTransparency(Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
,
887 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
890 } // VOID DrawMainMenuEntry()
892 static VOID
PaintAll(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
893 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
896 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0)
897 AdjustScrollState(State
);
898 for (i
= State
->FirstVisible
; i
<= State
->MaxIndex
; i
++) {
899 if (Screen
->Entries
[i
]->Row
== 0) {
900 if (i
<= State
->LastVisible
) {
901 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
,
902 itemPosX
[i
- State
->FirstVisible
], row0PosY
);
905 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
, itemPosX
[i
], row1PosY
);
908 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
)) {
909 DrawTextWithTransparency(L
"", 0, textPosY
);
910 DrawTextWithTransparency(Screen
->Entries
[State
->CurrentSelection
]->Title
,
911 (UGAWidth
- egComputeTextWidth(Screen
->Entries
[State
->CurrentSelection
]->Title
)) >> 1,
915 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
916 DrawTextWithTransparency(Screen
->Hint1
, (UGAWidth
- egComputeTextWidth(Screen
->Hint1
)) / 2,
917 UGAHeight
- (egGetFontHeight() * 3));
918 DrawTextWithTransparency(Screen
->Hint2
, (UGAWidth
- egComputeTextWidth(Screen
->Hint2
)) / 2,
919 UGAHeight
- (egGetFontHeight() * 2));
921 } // static VOID PaintAll()
923 // Move the selection to State->CurrentSelection, adjusting icon row if necessary...
924 static VOID
PaintSelection(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
925 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
926 UINTN XSelectPrev
, XSelectCur
, YPosPrev
, YPosCur
;
928 if (((State
->CurrentSelection
<= State
->LastVisible
) && (State
->CurrentSelection
>= State
->FirstVisible
)) ||
929 (State
->CurrentSelection
>= State
->InitialRow1
) ) {
930 if (Screen
->Entries
[State
->PreviousSelection
]->Row
== 0) {
931 XSelectPrev
= State
->PreviousSelection
- State
->FirstVisible
;
934 XSelectPrev
= State
->PreviousSelection
;
937 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0) {
938 XSelectCur
= State
->CurrentSelection
- State
->FirstVisible
;
941 XSelectCur
= State
->CurrentSelection
;
944 DrawMainMenuEntry(Screen
->Entries
[State
->PreviousSelection
], FALSE
, itemPosX
[XSelectPrev
], YPosPrev
);
945 DrawMainMenuEntry(Screen
->Entries
[State
->CurrentSelection
], TRUE
, itemPosX
[XSelectCur
], YPosCur
);
946 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
)) {
947 DrawTextWithTransparency(L
"", 0, textPosY
);
948 DrawTextWithTransparency(Screen
->Entries
[State
->CurrentSelection
]->Title
,
949 (UGAWidth
- egComputeTextWidth(Screen
->Entries
[State
->CurrentSelection
]->Title
)) >> 1,
952 } else { // Current selection not visible; must redraw the menu....
953 MainMenuStyle(Screen
, State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
955 } // static VOID MoveSelection(VOID)
957 // Display a 48x48 icon at the specified location. Uses the image specified by
958 // ExternalFilename if it's available, or BuiltInImage if it's not. The
959 // Y position is specified as the center value, and so is adjusted by half
960 // the icon's height. The X position is set along the icon's left
961 // edge if Alignment == ALIGN_LEFT, and along the right edge if
962 // Alignment == ALIGN_RIGHT
963 static VOID
PaintIcon(IN EG_EMBEDDED_IMAGE
*BuiltInIcon
, IN CHAR16
*ExternalFilename
, UINTN PosX
, UINTN PosY
, UINTN Alignment
) {
964 EG_IMAGE
*Icon
= NULL
;
966 Icon
= egFindIcon(ExternalFilename
, 48);
968 Icon
= egPrepareEmbeddedImage(BuiltInIcon
, TRUE
);
970 if (Alignment
== ALIGN_RIGHT
)
972 egDrawImageWithTransparency(Icon
, NULL
, PosX
, PosY
- (Icon
->Height
/ 2), Icon
->Width
, Icon
->Height
);
976 inline UINTN
ComputeRow0PosY(VOID
) {
977 return ((UGAHeight
/ 2) - ROW0_TILESIZE
/ 2);
978 } // UINTN ComputeRow0PosY()
980 // Display (or erase) the arrow icons to the left and right of an icon's row,
982 static VOID
PaintArrows(SCROLL_STATE
*State
, UINTN PosX
, UINTN PosY
, UINTN row0Loaders
) {
984 UINTN Width
, Height
, RightX
, AdjPosY
;
986 // NOTE: Assume that left and right arrows are of the same size....
987 Width
= egemb_arrow_left
.Width
;
988 Height
= egemb_arrow_left
.Height
;
989 RightX
= (UGAWidth
+ (ROW0_TILESIZE
+ TILE_XSPACING
) * State
->MaxVisible
) / 2 + TILE_XSPACING
;
990 AdjPosY
= PosY
- (Height
/ 2);
992 // For PaintIcon() calls, the starting Y position is moved to the midpoint
993 // of the surrounding row; PaintIcon() adjusts this back up by half the
994 // icon's height to properly center it.
995 if ((State
->FirstVisible
> 0) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
996 PaintIcon(&egemb_arrow_left
, L
"arrow_left", PosX
, PosY
, ALIGN_RIGHT
);
998 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, PosX
- Width
, AdjPosY
, Width
, Height
);
999 BltImage(TempImage
, PosX
- Width
, AdjPosY
);
1000 egFreeImage(TempImage
);
1003 if ((State
->LastVisible
< (row0Loaders
- 1)) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
1004 PaintIcon(&egemb_arrow_right
, L
"arrow_right", RightX
, PosY
, ALIGN_LEFT
);
1006 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, RightX
, AdjPosY
, Width
, Height
);
1007 BltImage(TempImage
, RightX
, AdjPosY
);
1008 egFreeImage(TempImage
);
1010 } // VOID PaintArrows()
1012 // Display main menu in graphics mode
1013 VOID
MainMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
1016 static UINTN row0PosX
, row0PosXRunning
, row1PosY
, row0Loaders
;
1017 UINTN row0Count
, row1Count
, row1PosX
, row1PosXRunning
;
1018 static UINTN
*itemPosX
;
1019 static UINTN row0PosY
, textPosY
;
1021 State
->ScrollMode
= SCROLL_MODE_ICONS
;
1024 case MENU_FUNCTION_INIT
:
1025 InitScroll(State
, Screen
->EntryCount
, GlobalConfig
.MaxTags
);
1031 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
1032 if (Screen
->Entries
[i
]->Row
== 1) {
1036 if (row0Count
< State
->MaxVisible
)
1040 row0PosX
= (UGAWidth
+ TILE_XSPACING
- (ROW0_TILESIZE
+ TILE_XSPACING
) * row0Count
) >> 1;
1041 row0PosY
= ComputeRow0PosY();
1042 row1PosX
= (UGAWidth
+ TILE_XSPACING
- (ROW1_TILESIZE
+ TILE_XSPACING
) * row1Count
) >> 1;
1043 row1PosY
= row0PosY
+ ROW0_TILESIZE
+ TILE_YSPACING
;
1045 textPosY
= row1PosY
+ ROW1_TILESIZE
+ TILE_YSPACING
;
1047 textPosY
= row1PosY
;
1049 itemPosX
= AllocatePool(sizeof(UINTN
) * Screen
->EntryCount
);
1050 row0PosXRunning
= row0PosX
;
1051 row1PosXRunning
= row1PosX
;
1052 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
1053 if (Screen
->Entries
[i
]->Row
== 0) {
1054 itemPosX
[i
] = row0PosXRunning
;
1055 row0PosXRunning
+= ROW0_TILESIZE
+ TILE_XSPACING
;
1057 itemPosX
[i
] = row1PosXRunning
;
1058 row1PosXRunning
+= ROW1_TILESIZE
+ TILE_XSPACING
;
1063 SwitchToGraphicsAndClear();
1066 case MENU_FUNCTION_CLEANUP
:
1067 MyFreePool(itemPosX
);
1070 case MENU_FUNCTION_PAINT_ALL
:
1071 PaintAll(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1072 // For PaintArrows(), the starting Y position is moved to the midpoint
1073 // of the surrounding row; PaintIcon() adjusts this back up by half the
1074 // icon's height to properly center it.
1075 PaintArrows(State
, row0PosX
- TILE_XSPACING
, row0PosY
+ (ROW0_TILESIZE
/ 2), row0Loaders
);
1078 case MENU_FUNCTION_PAINT_SELECTION
:
1079 PaintSelection(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1082 case MENU_FUNCTION_PAINT_TIMEOUT
:
1083 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
)) {
1084 DrawTextWithTransparency(L
"", 0, textPosY
+ TextLineHeight());
1085 DrawTextWithTransparency(ParamText
, (UGAWidth
- egComputeTextWidth(ParamText
)) >> 1, textPosY
+ TextLineHeight());
1090 } // VOID MainMenuStyle()
1092 // Enable the user to edit boot loader options.
1093 // Returns TRUE if the user exited with edited options; FALSE if the user
1094 // pressed Esc to terminate the edit.
1095 static BOOLEAN
EditOptions(LOADER_ENTRY
*MenuEntry
) {
1097 CHAR16
*EditedOptions
;
1098 BOOLEAN retval
= FALSE
;
1100 if (GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_EDITOR
) {
1104 refit_call4_wrapper(ST
->ConOut
->QueryMode
, ST
->ConOut
, ST
->ConOut
->Mode
->Mode
, &x_max
, &y_max
);
1106 if (!GlobalConfig
.TextOnly
)
1109 if (line_edit(MenuEntry
->LoadOptions
, &EditedOptions
, x_max
)) {
1110 MyFreePool(MenuEntry
->LoadOptions
);
1111 MenuEntry
->LoadOptions
= EditedOptions
;
1114 if (!GlobalConfig
.TextOnly
)
1117 } // VOID EditOptions()
1120 // user-callable dispatcher functions
1123 UINTN
RunMenu(IN REFIT_MENU_SCREEN
*Screen
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1125 INTN DefaultEntry
= -1;
1126 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1128 if (AllowGraphicsMode
)
1129 Style
= GraphicsMenuStyle
;
1131 return RunGenericMenu(Screen
, Style
, &DefaultEntry
, ChosenEntry
);
1134 UINTN
RunMainMenu(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
* DefaultSelection
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1136 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1137 MENU_STYLE_FUNC MainStyle
= TextMenuStyle
;
1138 REFIT_MENU_ENTRY
*TempChosenEntry
;
1140 INTN DefaultEntryIndex
= -1;
1141 INTN DefaultSubmenuIndex
= -1;
1143 if (DefaultSelection
!= NULL
) {
1144 // Find a menu entry that includes *DefaultSelection as a substring
1145 DefaultEntryIndex
= FindMenuShortcutEntry(Screen
, DefaultSelection
);
1148 if (AllowGraphicsMode
) {
1149 Style
= GraphicsMenuStyle
;
1150 MainStyle
= MainMenuStyle
;
1154 MenuExit
= RunGenericMenu(Screen
, MainStyle
, &DefaultEntryIndex
, &TempChosenEntry
);
1155 Screen
->TimeoutSeconds
= 0;
1157 if (MenuExit
== MENU_EXIT_DETAILS
) {
1158 if (TempChosenEntry
->SubScreen
!= NULL
) {
1159 MenuExit
= RunGenericMenu(TempChosenEntry
->SubScreen
, Style
, &DefaultSubmenuIndex
, &TempChosenEntry
);
1160 if (MenuExit
== MENU_EXIT_ESCAPE
|| TempChosenEntry
->Tag
== TAG_RETURN
)
1162 if (MenuExit
== MENU_EXIT_DETAILS
) {
1163 if (!EditOptions((LOADER_ENTRY
*) TempChosenEntry
))
1166 } else { // no sub-screen; ignore keypress
1169 } // Enter sub-screen
1173 *ChosenEntry
= TempChosenEntry
;
1175 } /* UINTN RunMainMenu() */