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 CHAR16 TimeoutMessage
[256];
367 CHAR16 KeyAsString
[2];
370 if (Screen
->TimeoutSeconds
> 0) {
372 TimeoutCountdown
= Screen
->TimeoutSeconds
* 10;
376 StyleFunc(Screen
, &State
, MENU_FUNCTION_INIT
, NULL
);
377 IdentifyRows(&State
, Screen
);
378 // override the starting selection with the default index, if any
379 if (*DefaultEntryIndex
>= 0 && *DefaultEntryIndex
<= State
.MaxIndex
) {
380 State
.CurrentSelection
= *DefaultEntryIndex
;
381 UpdateScroll(&State
, SCROLL_NONE
);
383 State
.PaintAll
= TRUE
;
387 if (State
.PaintAll
) {
388 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
389 State
.PaintAll
= FALSE
;
390 } else if (State
.PaintSelection
) {
391 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_SELECTION
, NULL
);
392 State
.PaintSelection
= FALSE
;
396 SPrint(TimeoutMessage
, 255, L
"%s in %d seconds", Screen
->TimeoutText
, (TimeoutCountdown
+ 5) / 10);
397 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, TimeoutMessage
);
400 // read key press (and wait for it if applicable)
401 Status
= refit_call2_wrapper(ST
->ConIn
->ReadKeyStroke
, ST
->ConIn
, &key
);
402 if (Status
== EFI_NOT_READY
) {
403 if (HaveTimeout
&& TimeoutCountdown
== 0) {
405 MenuExit
= MENU_EXIT_TIMEOUT
;
407 } else if (HaveTimeout
) {
408 refit_call1_wrapper(BS
->Stall
, 100000);
411 refit_call3_wrapper(BS
->WaitForEvent
, 1, &ST
->ConIn
->WaitForKey
, &index
);
415 // the user pressed a key, cancel the timeout
416 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, L
"");
420 // react to key press
421 switch (key
.ScanCode
) {
423 UpdateScroll(&State
, SCROLL_LINE_UP
);
426 UpdateScroll(&State
, SCROLL_LINE_LEFT
);
429 UpdateScroll(&State
, SCROLL_LINE_DOWN
);
432 UpdateScroll(&State
, SCROLL_LINE_RIGHT
);
435 UpdateScroll(&State
, SCROLL_FIRST
);
438 UpdateScroll(&State
, SCROLL_LAST
);
441 UpdateScroll(&State
, SCROLL_PAGE_UP
);
444 UpdateScroll(&State
, SCROLL_PAGE_DOWN
);
447 MenuExit
= MENU_EXIT_ESCAPE
;
451 MenuExit
= MENU_EXIT_DETAILS
;
458 MenuExit
= MENU_EXIT_ESCAPE
;
461 switch (key
.UnicodeChar
) {
463 case CHAR_CARRIAGE_RETURN
:
465 MenuExit
= MENU_EXIT_ENTER
;
468 MenuExit
= MENU_EXIT_DETAILS
;
471 KeyAsString
[0] = key
.UnicodeChar
;
473 ShortcutEntry
= FindMenuShortcutEntry(Screen
, KeyAsString
);
474 if (ShortcutEntry
>= 0) {
475 State
.CurrentSelection
= ShortcutEntry
;
476 MenuExit
= MENU_EXIT_ENTER
;
482 StyleFunc(Screen
, &State
, MENU_FUNCTION_CLEANUP
, NULL
);
485 *ChosenEntry
= Screen
->Entries
[State
.CurrentSelection
];
486 *DefaultEntryIndex
= State
.CurrentSelection
;
488 } /* static UINTN RunGenericMenu() */
491 // text-mode generic style
494 static VOID
TextMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
497 UINTN MenuWidth
, ItemWidth
, MenuHeight
;
498 static UINTN MenuPosY
;
499 static CHAR16
**DisplayStrings
;
500 CHAR16 TimeoutMessage
[256];
502 State
->ScrollMode
= SCROLL_MODE_TEXT
;
505 case MENU_FUNCTION_INIT
:
508 if (Screen
->InfoLineCount
> 0)
509 MenuPosY
+= Screen
->InfoLineCount
+ 1;
510 MenuHeight
= ConHeight
- MenuPosY
- 3;
511 if (Screen
->TimeoutSeconds
> 0)
513 InitScroll(State
, Screen
->EntryCount
, MenuHeight
);
515 // determine width of the menu
516 MenuWidth
= 20; // minimum
517 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
518 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
519 if (MenuWidth
< ItemWidth
)
520 MenuWidth
= ItemWidth
;
523 if (MenuWidth
> ConWidth
- 3)
524 MenuWidth
= ConWidth
- 3;
526 // prepare strings for display
527 DisplayStrings
= AllocatePool(sizeof(CHAR16
*) * Screen
->EntryCount
);
528 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
529 // Note: Theoretically, SPrint() is a cleaner way to do this; but the
530 // description of the StrSize parameter to SPrint implies it's measured
531 // in characters, but in practice both TianoCore and GNU-EFI seem to
532 // use bytes instead, resulting in truncated displays. I could just
533 // double the size of the StrSize parameter, but that seems unsafe in
534 // case a future library change starts treating this as characters, so
535 // I'm doing it the hard way in this instance.
536 // TODO: Review the above and possibly change other uses of SPrint()
537 DisplayStrings
[i
] = AllocateZeroPool(2 * sizeof(CHAR16
));
538 DisplayStrings
[i
][0] = L
' ';
539 MergeStrings(&DisplayStrings
[i
], Screen
->Entries
[i
]->Title
, 0);
540 if (StrLen(DisplayStrings
[i
]) > MenuWidth
)
541 DisplayStrings
[i
][MenuWidth
- 1] = 0;
542 // TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
543 // TODO: account for double-width characters
547 BeginTextScreen(Screen
->Title
);
548 if (Screen
->InfoLineCount
> 0) {
549 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
550 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
551 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, 4 + i
);
552 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->InfoLines
[i
]);
558 case MENU_FUNCTION_CLEANUP
:
559 // release temporary memory
560 for (i
= 0; i
<= State
->MaxIndex
; i
++)
561 MyFreePool(DisplayStrings
[i
]);
562 MyFreePool(DisplayStrings
);
565 case MENU_FUNCTION_PAINT_ALL
:
566 // paint the whole screen (initially and after scrolling)
567 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
568 if (i
>= State
->FirstVisible
&& i
<= State
->LastVisible
) {
569 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2, MenuPosY
+ (i
- State
->FirstVisible
));
570 if (i
== State
->CurrentSelection
)
571 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
573 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
574 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[i
]);
577 // scrolling indicators
578 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_SCROLLARROW
);
579 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
);
580 if (State
->FirstVisible
> 0)
581 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowUp
);
583 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
584 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
+ State
->MaxVisible
);
585 if (State
->LastVisible
< State
->MaxIndex
)
586 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowDown
);
588 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
589 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
590 if (Screen
->Hint1
!= NULL
) {
591 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 2);
592 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint1
);
594 if (Screen
->Hint2
!= NULL
) {
595 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 1);
596 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint2
);
601 case MENU_FUNCTION_PAINT_SELECTION
:
602 // redraw selection cursor
603 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
604 MenuPosY
+ (State
->PreviousSelection
- State
->FirstVisible
));
605 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
606 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->PreviousSelection
]);
607 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
608 MenuPosY
+ (State
->CurrentSelection
- State
->FirstVisible
));
609 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
610 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->CurrentSelection
]);
613 case MENU_FUNCTION_PAINT_TIMEOUT
:
614 if (ParamText
[0] == 0) {
616 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
617 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 3);
618 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, BlankLine
+ 1);
620 // paint or update message
621 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_ERROR
);
622 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, ConHeight
- 3);
623 SPrint(TimeoutMessage
, 255, L
"%s ", ParamText
);
624 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, TimeoutMessage
);
632 // graphical generic style
639 // Display text with a solid background (MenuBackgroundPixel or SelectionBackgroundPixel)
640 static VOID
DrawText(IN CHAR16
*Text
, IN BOOLEAN Selected
, IN UINTN FieldWidth
, IN UINTN XPos
, IN UINTN YPos
)
642 EG_IMAGE
*TextBuffer
;
645 TextBuffer
= egCreateImage(FieldWidth
, TEXT_LINE_HEIGHT
, FALSE
);
647 egFillImage(TextBuffer
, &MenuBackgroundPixel
);
648 Bg
= MenuBackgroundPixel
;
650 // draw selection bar background
651 egFillImageArea(TextBuffer
, 0, 0, FieldWidth
, TextBuffer
->Height
, &SelectionBackgroundPixel
);
652 Bg
= SelectionBackgroundPixel
;
656 egRenderText(Text
, TextBuffer
, TEXT_XMARGIN
, TEXT_YMARGIN
, (Bg
.r
+ Bg
.g
+ Bg
.b
) / 3);
657 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
658 // BltImage(TextBuffer, XPos, YPos);
661 // Finds the average brightness of the input Image.
662 // NOTE: Passing an Image that covers the whole screen can strain the
663 // capacity of a UINTN on a 32-bit system with a very large display.
664 // Using UINT64 instead is unworkable, since the code won't compile
665 // on a 32-bit system. As the intended use for this function is to handle
666 // a single text string's background, this shouldn't be a problem, but it
667 // may need addressing if it's applied more broadly....
668 static UINT8
AverageBrightness(EG_IMAGE
*Image
) {
673 for (i
= 0; i
< (Image
->Width
* Image
->Height
); i
++) {
674 Sum
+= (Image
->PixelData
[i
].r
+ Image
->PixelData
[i
].g
+ Image
->PixelData
[i
].b
);
677 return (UINT8
) (Sum
/ (Image
->Width
* Image
->Height
* 3));
678 } // UINT8 AverageBrightness()
680 // Display text against the screen's background image
681 static VOID
DrawTextWithTransparency(IN CHAR16
*Text
, IN UINTN XPos
, IN UINTN YPos
)
683 UINTN TextWidth
, TextPosX
;
684 EG_IMAGE
*TextBuffer
;
686 TextBuffer
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
, LAYOUT_TEXT_WIDTH
, TEXT_LINE_HEIGHT
);
689 egMeasureText(Text
, &TextWidth
, NULL
);
690 if (TextWidth
> TextBuffer
->Width
)
693 TextPosX
= (TextBuffer
->Width
- TextWidth
) / 2;
694 egRenderText(Text
, TextBuffer
, TextPosX
, 0, AverageBrightness(TextBuffer
));
695 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
698 // Compute the size & position of the window that will hold a subscreen's information.
699 static VOID
ComputeSubScreenWindowSize(REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*XPos
, UINTN
*YPos
, UINTN
*Width
, UINTN
*Height
, UINTN
*LineWidth
) {
700 UINTN i
, ItemWidth
, HintTop
, BannerBottomEdge
, TitleWidth
;
704 TitleWidth
= StrLen(Screen
->Title
);
705 if ((Screen
->TitleImage
) && (TitleWidth
> (Screen
->TitleImage
->Width
/ FONT_CELL_WIDTH
))) {
706 TitleWidth
-= (Screen
->TitleImage
->Width
/ FONT_CELL_WIDTH
);
708 if (TitleWidth
> *Width
) {
711 for (i
= 0; i
< Screen
->InfoLineCount
; i
++) {
712 ItemWidth
= StrLen(Screen
->InfoLines
[i
]);
713 if (*Width
< ItemWidth
) {
718 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
719 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
720 if (*Width
< ItemWidth
) {
725 *Width
= TEXT_XMARGIN
* 2 + *Width
* FONT_CELL_WIDTH
;
727 if (Screen
->TitleImage
)
728 *Width
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
* 2 + FONT_CELL_WIDTH
);
730 *Width
+= FONT_CELL_WIDTH
;
732 // Keep it within the bounds of the screen, or 2/3 of the screen's width
733 // for screens over 800 pixels wide
734 if (*Width
> UGAWidth
)
736 if ((*Width
> (2 * UGAWidth
) / 3) && (UGAWidth
> 800))
737 *Width
= (2 * UGAWidth
) / 3;
739 *XPos
= (UGAWidth
- *Width
) / 2;
741 HintTop
= UGAHeight
- (FONT_CELL_HEIGHT
* 3); // top of hint text
742 *Height
*= TEXT_LINE_HEIGHT
;
743 if (Screen
->TitleImage
&& (*Height
< (Screen
->TitleImage
->Height
+ TEXT_LINE_HEIGHT
* 4)))
744 *Height
= Screen
->TitleImage
->Height
+ TEXT_LINE_HEIGHT
* 4;
746 if (GlobalConfig
.BannerBottomEdge
>= HintTop
) { // probably a full-screen image; treat it as an empty banner
747 BannerBottomEdge
= 0;
749 BannerBottomEdge
= GlobalConfig
.BannerBottomEdge
;
751 if (*Height
> (HintTop
- BannerBottomEdge
- FONT_CELL_HEIGHT
* 2)) {
752 BannerBottomEdge
= 0;
754 if (*Height
> (HintTop
- BannerBottomEdge
- FONT_CELL_HEIGHT
* 2)) {
755 // TODO: Implement scrolling in text screen.
756 *Height
= (HintTop
- BannerBottomEdge
- FONT_CELL_HEIGHT
* 2);
759 *YPos
= ((UGAHeight
- *Height
) / 2);
760 if (*YPos
< BannerBottomEdge
)
761 *YPos
= BannerBottomEdge
+ FONT_CELL_HEIGHT
+ (HintTop
- BannerBottomEdge
- *Height
) / 2;
762 } // VOID ComputeSubScreenWindowSize()
764 // Displays sub-menus
765 static VOID
GraphicsMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
769 static UINTN LineWidth
, MenuWidth
, MenuHeight
, EntriesPosX
, EntriesPosY
, TimeoutPosY
;
771 EG_PIXEL
*BackgroundPixel
= &(GlobalConfig
.ScreenBackground
->PixelData
[0]);
773 State
->ScrollMode
= SCROLL_MODE_TEXT
;
776 case MENU_FUNCTION_INIT
:
777 InitScroll(State
, Screen
->EntryCount
, 0);
778 ComputeSubScreenWindowSize(Screen
, State
, &EntriesPosX
, &EntriesPosY
, &MenuWidth
, &MenuHeight
, &LineWidth
);
779 TimeoutPosY
= EntriesPosY
+ (Screen
->EntryCount
+ 1) * TEXT_LINE_HEIGHT
;
782 SwitchToGraphicsAndClear();
783 Window
= egCreateFilledImage(MenuWidth
, MenuHeight
, FALSE
, BackgroundPixel
);
784 egDrawImage(Window
, EntriesPosX
, EntriesPosY
);
785 egMeasureText(Screen
->Title
, &ItemWidth
, NULL
);
786 DrawText(Screen
->Title
, FALSE
, (StrLen(Screen
->Title
) + 2) * FONT_CELL_WIDTH
,
787 EntriesPosX
+ (MenuWidth
- ItemWidth
) / 2, EntriesPosY
+= TEXT_LINE_HEIGHT
);
788 if (Screen
->TitleImage
) {
789 BltImageAlpha(Screen
->TitleImage
, EntriesPosX
+ TITLEICON_SPACING
, EntriesPosY
+ TEXT_LINE_HEIGHT
* 2,
791 EntriesPosX
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
* 2);
793 EntriesPosY
+= (TEXT_LINE_HEIGHT
* 2);
794 if (Screen
->InfoLineCount
> 0) {
795 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
796 DrawText(Screen
->InfoLines
[i
], FALSE
, LineWidth
, EntriesPosX
, EntriesPosY
);
797 EntriesPosY
+= TEXT_LINE_HEIGHT
;
799 EntriesPosY
+= TEXT_LINE_HEIGHT
; // also add a blank line
804 case MENU_FUNCTION_CLEANUP
:
808 case MENU_FUNCTION_PAINT_ALL
:
809 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
810 DrawText(Screen
->Entries
[i
]->Title
, (i
== State
->CurrentSelection
), LineWidth
, EntriesPosX
,
811 EntriesPosY
+ i
* TEXT_LINE_HEIGHT
);
813 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
814 if ((Screen
->Hint1
!= NULL
) && (StrLen(Screen
->Hint1
) > 0))
815 DrawTextWithTransparency(Screen
->Hint1
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 3));
816 if ((Screen
->Hint2
!= NULL
) && (StrLen(Screen
->Hint2
) > 0))
817 DrawTextWithTransparency(Screen
->Hint2
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 2));
821 case MENU_FUNCTION_PAINT_SELECTION
:
822 // redraw selection cursor
823 DrawText(Screen
->Entries
[State
->PreviousSelection
]->Title
, FALSE
, LineWidth
,
824 EntriesPosX
, EntriesPosY
+ State
->PreviousSelection
* TEXT_LINE_HEIGHT
);
825 DrawText(Screen
->Entries
[State
->CurrentSelection
]->Title
, TRUE
, LineWidth
,
826 EntriesPosX
, EntriesPosY
+ State
->CurrentSelection
* TEXT_LINE_HEIGHT
);
829 case MENU_FUNCTION_PAINT_TIMEOUT
:
830 DrawText(ParamText
, FALSE
, LineWidth
, EntriesPosX
, TimeoutPosY
);
834 } // static VOID GraphicsMenuStyle()
837 // graphical main menu style
840 static VOID
DrawMainMenuEntry(REFIT_MENU_ENTRY
*Entry
, BOOLEAN selected
, UINTN XPos
, UINTN YPos
)
842 EG_IMAGE
*Background
;
844 if (SelectionImages
!= NULL
) {
846 Background
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
,
847 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
848 egComposeImage(Background
, SelectionImages
[Entry
->Row
], 0, 0);
849 BltImageCompositeBadge(Background
, Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
);
850 } else { // Image not selected; copy background
851 egDrawImageWithTransparency(Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
,
852 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
855 } // VOID DrawMainMenuEntry()
857 static VOID
PaintAll(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
858 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
861 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0)
862 AdjustScrollState(State
);
863 for (i
= State
->FirstVisible
; i
<= State
->MaxIndex
; i
++) {
864 if (Screen
->Entries
[i
]->Row
== 0) {
865 if (i
<= State
->LastVisible
) {
866 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
,
867 itemPosX
[i
- State
->FirstVisible
], row0PosY
);
870 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
, itemPosX
[i
], row1PosY
);
873 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
))
874 DrawTextWithTransparency(Screen
->Entries
[State
->CurrentSelection
]->Title
,
875 (UGAWidth
- LAYOUT_TEXT_WIDTH
) >> 1, textPosY
);
877 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
878 DrawTextWithTransparency(Screen
->Hint1
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 3));
879 DrawTextWithTransparency(Screen
->Hint2
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 2));
881 } // static VOID PaintAll()
883 // Move the selection to State->CurrentSelection, adjusting icon row if necessary...
884 static VOID
PaintSelection(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
885 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
886 UINTN XSelectPrev
, XSelectCur
, YPosPrev
, YPosCur
;
888 if (((State
->CurrentSelection
<= State
->LastVisible
) && (State
->CurrentSelection
>= State
->FirstVisible
)) ||
889 (State
->CurrentSelection
>= State
->InitialRow1
) ) {
890 if (Screen
->Entries
[State
->PreviousSelection
]->Row
== 0) {
891 XSelectPrev
= State
->PreviousSelection
- State
->FirstVisible
;
894 XSelectPrev
= State
->PreviousSelection
;
897 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0) {
898 XSelectCur
= State
->CurrentSelection
- State
->FirstVisible
;
901 XSelectCur
= State
->CurrentSelection
;
904 DrawMainMenuEntry(Screen
->Entries
[State
->PreviousSelection
], FALSE
, itemPosX
[XSelectPrev
], YPosPrev
);
905 DrawMainMenuEntry(Screen
->Entries
[State
->CurrentSelection
], TRUE
, itemPosX
[XSelectCur
], YPosCur
);
906 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
))
907 DrawTextWithTransparency(Screen
->Entries
[State
->CurrentSelection
]->Title
,
908 (UGAWidth
- LAYOUT_TEXT_WIDTH
) >> 1, textPosY
);
909 } else { // Current selection not visible; must redraw the menu....
910 MainMenuStyle(Screen
, State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
912 } // static VOID MoveSelection(VOID)
914 // Display an icon at the specified location. Uses the image specified by
915 // ExternalFilename if it's available, or BuiltInImage if it's not. The
916 // Y position is specified as the center value, and so is adjusted by half
917 // the icon's height. The X position is set along the icon's left
918 // edge if Alignment == ALIGN_LEFT, and along the right edge if
919 // Alignment == ALIGN_RIGHT
920 static VOID
PaintIcon(IN EG_EMBEDDED_IMAGE
*BuiltInIcon
, IN CHAR16
*ExternalFilename
, UINTN PosX
, UINTN PosY
, UINTN Alignment
) {
921 EG_IMAGE
*Icon
= NULL
;
923 if (FileExists(SelfDir
, ExternalFilename
))
924 Icon
= egLoadIcon(SelfDir
, ExternalFilename
, 48);
926 Icon
= egPrepareEmbeddedImage(BuiltInIcon
, TRUE
);
928 if (Alignment
== ALIGN_RIGHT
)
930 egDrawImageWithTransparency(Icon
, NULL
, PosX
, PosY
- (Icon
->Height
/ 2), Icon
->Width
, Icon
->Height
);
932 } // static VOID PaintIcon()
934 inline UINTN
ComputeRow0PosX(VOID
) {
935 return ((UGAHeight
/ 2) - ROW0_TILESIZE
/ 2);
936 } // UINTN ComputeRow0PosX()
938 // Display (or erase) the arrow icons to the left and right of an icon's row,
940 static VOID
PaintArrows(SCROLL_STATE
*State
, UINTN PosX
, UINTN PosY
, UINTN row0Loaders
) {
941 CHAR16 FileName
[256];
943 UINTN Width
, Height
, RightX
, AdjPosY
;
945 // NOTE: Assume that left and right arrows are of the same size....
946 Width
= egemb_arrow_left
.Width
;
947 Height
= egemb_arrow_left
.Height
;
948 RightX
= (UGAWidth
+ (ROW0_TILESIZE
+ TILE_XSPACING
) * State
->MaxVisible
) / 2 + TILE_XSPACING
;
949 AdjPosY
= PosY
- (Height
/ 2);
951 // For PaintIcon() calls, the starting Y position is moved to the midpoint
952 // of the surrounding row; PaintIcon() adjusts this back up by half the
953 // icon's height to properly center it.
954 if ((State
->FirstVisible
> 0) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
955 SPrint(FileName
, 255, L
"%s\\arrow_left.icns", GlobalConfig
.IconsDir
? GlobalConfig
.IconsDir
: DEFAULT_ICONS_DIR
);
956 PaintIcon(&egemb_arrow_left
, FileName
, PosX
, PosY
, ALIGN_RIGHT
);
958 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, PosX
- Width
, AdjPosY
, Width
, Height
);
959 BltImage(TempImage
, PosX
- Width
, AdjPosY
);
960 egFreeImage(TempImage
);
963 if ((State
->LastVisible
< (row0Loaders
- 1)) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
964 SPrint(FileName
, 255, L
"%s\\arrow_right.icns", GlobalConfig
.IconsDir
? GlobalConfig
.IconsDir
: DEFAULT_ICONS_DIR
);
965 PaintIcon(&egemb_arrow_right
, FileName
, RightX
, PosY
, ALIGN_LEFT
);
967 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, RightX
, AdjPosY
, Width
, Height
);
968 BltImage(TempImage
, RightX
, AdjPosY
);
969 egFreeImage(TempImage
);
971 } // VOID PaintArrows()
973 // Display main menu in graphics mode
974 VOID
MainMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
977 static UINTN row0PosX
, row0PosXRunning
, row1PosY
, row0Loaders
;
978 UINTN row0Count
, row1Count
, row1PosX
, row1PosXRunning
;
979 static UINTN
*itemPosX
;
980 static UINTN row0PosY
, textPosY
;
982 State
->ScrollMode
= SCROLL_MODE_ICONS
;
985 case MENU_FUNCTION_INIT
:
986 InitScroll(State
, Screen
->EntryCount
, GlobalConfig
.MaxTags
);
992 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
993 if (Screen
->Entries
[i
]->Row
== 1) {
997 if (row0Count
< State
->MaxVisible
)
1001 row0PosX
= (UGAWidth
+ TILE_XSPACING
- (ROW0_TILESIZE
+ TILE_XSPACING
) * row0Count
) >> 1;
1002 row0PosY
= ComputeRow0PosX();
1003 row1PosX
= (UGAWidth
+ TILE_XSPACING
- (ROW1_TILESIZE
+ TILE_XSPACING
) * row1Count
) >> 1;
1004 row1PosY
= row0PosY
+ ROW0_TILESIZE
+ TILE_YSPACING
;
1006 textPosY
= row1PosY
+ ROW1_TILESIZE
+ TILE_YSPACING
;
1008 textPosY
= row1PosY
;
1010 itemPosX
= AllocatePool(sizeof(UINTN
) * Screen
->EntryCount
);
1011 row0PosXRunning
= row0PosX
;
1012 row1PosXRunning
= row1PosX
;
1013 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
1014 if (Screen
->Entries
[i
]->Row
== 0) {
1015 itemPosX
[i
] = row0PosXRunning
;
1016 row0PosXRunning
+= ROW0_TILESIZE
+ TILE_XSPACING
;
1018 itemPosX
[i
] = row1PosXRunning
;
1019 row1PosXRunning
+= ROW1_TILESIZE
+ TILE_XSPACING
;
1024 SwitchToGraphicsAndClear();
1027 case MENU_FUNCTION_CLEANUP
:
1028 MyFreePool(itemPosX
);
1031 case MENU_FUNCTION_PAINT_ALL
:
1032 PaintAll(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1033 // For PaintArrows(), the starting Y position is moved to the midpoint
1034 // of the surrounding row; PaintIcon() adjusts this back up by half the
1035 // icon's height to properly center it.
1036 PaintArrows(State
, row0PosX
- TILE_XSPACING
, row0PosY
+ (ROW0_TILESIZE
/ 2), row0Loaders
);
1039 case MENU_FUNCTION_PAINT_SELECTION
:
1040 PaintSelection(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1043 case MENU_FUNCTION_PAINT_TIMEOUT
:
1044 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
))
1045 DrawTextWithTransparency(ParamText
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) >> 1, textPosY
+ TEXT_LINE_HEIGHT
);
1049 } // VOID MainMenuStyle()
1051 // Enable the user to edit boot loader options.
1052 // Returns TRUE if the user exited with edited options; FALSE if the user
1053 // pressed Esc to terminate the edit.
1054 static BOOLEAN
EditOptions(LOADER_ENTRY
*MenuEntry
) {
1056 CHAR16
*EditedOptions
;
1057 BOOLEAN retval
= FALSE
;
1059 if (GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_EDITOR
) {
1063 refit_call4_wrapper(ST
->ConOut
->QueryMode
, ST
->ConOut
, ST
->ConOut
->Mode
->Mode
, &x_max
, &y_max
);
1065 if (!GlobalConfig
.TextOnly
)
1068 if (line_edit(MenuEntry
->LoadOptions
, &EditedOptions
, x_max
)) {
1069 MyFreePool(MenuEntry
->LoadOptions
);
1070 MenuEntry
->LoadOptions
= EditedOptions
;
1073 if (!GlobalConfig
.TextOnly
)
1076 } // VOID EditOptions()
1079 // user-callable dispatcher functions
1082 UINTN
RunMenu(IN REFIT_MENU_SCREEN
*Screen
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1084 INTN DefaultEntry
= -1;
1085 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1087 if (AllowGraphicsMode
)
1088 Style
= GraphicsMenuStyle
;
1090 return RunGenericMenu(Screen
, Style
, &DefaultEntry
, ChosenEntry
);
1093 UINTN
RunMainMenu(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
* DefaultSelection
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1095 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1096 MENU_STYLE_FUNC MainStyle
= TextMenuStyle
;
1097 REFIT_MENU_ENTRY
*TempChosenEntry
;
1099 INTN DefaultEntryIndex
= -1;
1100 INTN DefaultSubmenuIndex
= -1;
1102 if (DefaultSelection
!= NULL
) {
1103 // Find a menu entry that includes *DefaultSelection as a substring
1104 DefaultEntryIndex
= FindMenuShortcutEntry(Screen
, DefaultSelection
);
1107 if (AllowGraphicsMode
) {
1108 Style
= GraphicsMenuStyle
;
1109 MainStyle
= MainMenuStyle
;
1113 MenuExit
= RunGenericMenu(Screen
, MainStyle
, &DefaultEntryIndex
, &TempChosenEntry
);
1114 Screen
->TimeoutSeconds
= 0;
1116 if (MenuExit
== MENU_EXIT_DETAILS
) {
1117 if (TempChosenEntry
->SubScreen
!= NULL
) {
1118 MenuExit
= RunGenericMenu(TempChosenEntry
->SubScreen
, Style
, &DefaultSubmenuIndex
, &TempChosenEntry
);
1119 if (MenuExit
== MENU_EXIT_ESCAPE
|| TempChosenEntry
->Tag
== TAG_RETURN
)
1121 if (MenuExit
== MENU_EXIT_DETAILS
) {
1122 if (!EditOptions((LOADER_ENTRY
*) TempChosenEntry
))
1125 } else { // no sub-screen; ignore keypress
1128 } // Enter sub-screen
1132 *ChosenEntry
= TempChosenEntry
;
1134 } /* UINTN RunMainMenu() */