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],
111 ROW1_TILESIZE
, ROW1_TILESIZE
, &MenuBackgroundPixel
);
112 if (SelectionImages
[1] == NULL
)
115 // load big selection image
116 if (GlobalConfig
.SelectionBigFileName
!= NULL
) {
117 SelectionImages
[0] = egLoadImage(SelfDir
, GlobalConfig
.SelectionBigFileName
, TRUE
);
118 SelectionImages
[0] = egEnsureImageSize(SelectionImages
[0],
119 ROW0_TILESIZE
, ROW0_TILESIZE
, &MenuBackgroundPixel
);
121 if (SelectionImages
[0] == NULL
) {
122 // calculate big selection image from small one
124 SelectionImages
[0] = egCreateImage(ROW0_TILESIZE
, ROW0_TILESIZE
, TRUE
);
125 if (SelectionImages
[0] == NULL
) {
126 egFreeImage(SelectionImages
[1]);
127 SelectionImages
[1] = NULL
;
131 DestPtr
= SelectionImages
[0]->PixelData
;
132 SrcPtr
= SelectionImages
[1]->PixelData
;
133 for (y
= 0; y
< ROW0_TILESIZE
; y
++) {
134 if (y
< (ROW1_TILESIZE
>> 1))
136 else if (y
< (ROW0_TILESIZE
- (ROW1_TILESIZE
>> 1)))
137 src_y
= (ROW1_TILESIZE
>> 1);
139 src_y
= y
- (ROW0_TILESIZE
- ROW1_TILESIZE
);
141 for (x
= 0; x
< ROW0_TILESIZE
; x
++) {
142 if (x
< (ROW1_TILESIZE
>> 1))
144 else if (x
< (ROW0_TILESIZE
- (ROW1_TILESIZE
>> 1)))
145 src_x
= (ROW1_TILESIZE
>> 1);
147 src_x
= x
- (ROW0_TILESIZE
- ROW1_TILESIZE
);
149 *DestPtr
++ = SrcPtr
[src_y
* ROW1_TILESIZE
+ src_x
];
153 } // VOID InitSelection()
156 // Scrolling functions
159 static VOID
InitScroll(OUT SCROLL_STATE
*State
, IN UINTN ItemCount
, IN UINTN VisibleSpace
)
161 State
->PreviousSelection
= State
->CurrentSelection
= 0;
162 State
->MaxIndex
= (INTN
)ItemCount
- 1;
163 State
->FirstVisible
= 0;
164 if (AllowGraphicsMode
) {
165 State
->MaxVisible
= UGAWidth
/ (ROW0_TILESIZE
+ TILE_XSPACING
) - 1;
167 State
->MaxVisible
= ConHeight
- 4;
168 if ((VisibleSpace
> 0) && (VisibleSpace
< State
->MaxVisible
))
169 State
->MaxVisible
= (INTN
)VisibleSpace
;
170 State
->PaintAll
= TRUE
;
171 State
->PaintSelection
= FALSE
;
173 State
->LastVisible
= State
->FirstVisible
+ State
->MaxVisible
- 1;
176 // Adjust variables relating to the scrolling of tags, for when a selected icon isn't
177 // visible given the current scrolling condition....
178 static VOID
AdjustScrollState(IN SCROLL_STATE
*State
) {
179 if (State
->CurrentSelection
> State
->LastVisible
) {
180 State
->LastVisible
= State
->CurrentSelection
;
181 State
->FirstVisible
= 1 + State
->CurrentSelection
- State
->MaxVisible
;
182 if (State
->FirstVisible
< 0) // shouldn't happen, but just in case....
183 State
->FirstVisible
= 0;
184 State
->PaintAll
= TRUE
;
186 if (State
->CurrentSelection
< State
->FirstVisible
) {
187 State
->FirstVisible
= State
->CurrentSelection
;
188 State
->LastVisible
= State
->CurrentSelection
+ State
->MaxVisible
- 1;
189 State
->PaintAll
= TRUE
;
191 } // static VOID AdjustScrollState
193 static VOID
UpdateScroll(IN OUT SCROLL_STATE
*State
, IN UINTN Movement
)
195 State
->PreviousSelection
= State
->CurrentSelection
;
198 case SCROLL_LINE_LEFT
:
199 if (State
->CurrentSelection
> 0) {
200 State
->CurrentSelection
--;
204 case SCROLL_LINE_RIGHT
:
205 if (State
->CurrentSelection
< State
->MaxIndex
) {
206 State
->CurrentSelection
++;
211 if (State
->ScrollMode
== SCROLL_MODE_ICONS
) {
212 if (State
->CurrentSelection
>= State
->InitialRow1
) {
213 if (State
->MaxIndex
> State
->InitialRow1
) { // avoid division by 0!
214 State
->CurrentSelection
= State
->FirstVisible
+ (State
->LastVisible
- State
->FirstVisible
) *
215 (State
->CurrentSelection
- State
->InitialRow1
) /
216 (State
->MaxIndex
- State
->InitialRow1
);
218 State
->CurrentSelection
= State
->FirstVisible
;
220 } // if in second row
222 if (State
->CurrentSelection
> 0)
223 State
->CurrentSelection
--;
227 case SCROLL_LINE_DOWN
:
228 if (State
->ScrollMode
== SCROLL_MODE_ICONS
) {
229 if (State
->CurrentSelection
<= State
->FinalRow0
) {
230 if (State
->LastVisible
> State
->FirstVisible
) { // avoid division by 0!
231 State
->CurrentSelection
= State
->InitialRow1
+ (State
->MaxIndex
- State
->InitialRow1
) *
232 (State
->CurrentSelection
- State
->FirstVisible
) /
233 (State
->LastVisible
- State
->FirstVisible
);
235 State
->CurrentSelection
= State
->InitialRow1
;
239 if (State
->CurrentSelection
< State
->MaxIndex
)
240 State
->CurrentSelection
++;
245 if (State
->CurrentSelection
<= State
->FinalRow0
)
246 State
->CurrentSelection
-= State
->MaxVisible
;
247 else if (State
->CurrentSelection
== State
->InitialRow1
)
248 State
->CurrentSelection
= State
->FinalRow0
;
250 State
->CurrentSelection
= State
->InitialRow1
;
251 if (State
->CurrentSelection
< 0)
252 State
->CurrentSelection
= 0;
256 if (State
->CurrentSelection
> 0) {
257 State
->PaintAll
= TRUE
;
258 State
->CurrentSelection
= 0;
262 case SCROLL_PAGE_DOWN
:
263 if (State
->CurrentSelection
< State
->FinalRow0
) {
264 State
->CurrentSelection
+= State
->MaxVisible
;
265 if (State
->CurrentSelection
> State
->FinalRow0
)
266 State
->CurrentSelection
= State
->FinalRow0
;
267 } else if (State
->CurrentSelection
== State
->FinalRow0
) {
268 State
->CurrentSelection
++;
270 State
->CurrentSelection
= State
->MaxIndex
;
272 if (State
->CurrentSelection
> State
->MaxIndex
)
273 State
->CurrentSelection
= State
->MaxIndex
;
277 if (State
->CurrentSelection
< State
->MaxIndex
) {
278 State
->PaintAll
= TRUE
;
279 State
->CurrentSelection
= State
->MaxIndex
;
287 if (State
->ScrollMode
== SCROLL_MODE_TEXT
)
288 AdjustScrollState(State
);
290 if (!State
->PaintAll
&& State
->CurrentSelection
!= State
->PreviousSelection
)
291 State
->PaintSelection
= TRUE
;
292 State
->LastVisible
= State
->FirstVisible
+ State
->MaxVisible
- 1;
293 } // static VOID UpdateScroll()
296 // menu helper functions
299 VOID
AddMenuInfoLine(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
*InfoLine
)
301 AddListElement((VOID
***) &(Screen
->InfoLines
), &(Screen
->InfoLineCount
), InfoLine
);
304 VOID
AddMenuEntry(IN REFIT_MENU_SCREEN
*Screen
, IN REFIT_MENU_ENTRY
*Entry
)
306 AddListElement((VOID
***) &(Screen
->Entries
), &(Screen
->EntryCount
), Entry
);
310 static INTN
FindMenuShortcutEntry(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
*Shortcut
)
314 if (Shortcut
== NULL
)
317 if (StrLen(Shortcut
) == 1) {
318 if (Shortcut
[0] >= 'a' && Shortcut
[0] <= 'z')
319 Shortcut
[0] -= ('a' - 'A');
321 for (i
= 0; i
< Screen
->EntryCount
; i
++) {
322 if (Screen
->Entries
[i
]->ShortcutDigit
== Shortcut
[0] || Screen
->Entries
[i
]->ShortcutLetter
== Shortcut
[0]) {
327 } else if (StrLen(Shortcut
) > 1) {
328 for (i
= 0; i
< Screen
->EntryCount
; i
++) {
329 if (StriSubCmp(Shortcut
, Screen
->Entries
[i
]->Title
))
336 // Identify the end of row 0 and the beginning of row 1; store the results in the
337 // appropriate fields in State. Also reduce MaxVisible if that value is greater
338 // than the total number of row-0 tags and if we're in an icon-based screen
339 static VOID
IdentifyRows(IN SCROLL_STATE
*State
, IN REFIT_MENU_SCREEN
*Screen
) {
342 State
->FinalRow0
= 0;
343 State
->InitialRow1
= State
->MaxIndex
;
344 for (i
= 0; i
< State
->MaxIndex
; i
++) {
345 if (Screen
->Entries
[i
]->Row
== 0) {
346 State
->FinalRow0
= i
;
347 } else if ((Screen
->Entries
[i
]->Row
== 1) && (State
->InitialRow1
> i
)) {
348 State
->InitialRow1
= i
;
351 if ((State
->ScrollMode
== SCROLL_MODE_ICONS
) && (State
->MaxVisible
> (State
->FinalRow0
+ 1)))
352 State
->MaxVisible
= State
->FinalRow0
+ 1;
353 } // static VOID IdentifyRows()
356 // generic menu function
358 static UINTN
RunGenericMenu(IN REFIT_MENU_SCREEN
*Screen
, IN MENU_STYLE_FUNC StyleFunc
, IN OUT INTN
*DefaultEntryIndex
,
359 OUT REFIT_MENU_ENTRY
**ChosenEntry
)
366 BOOLEAN HaveTimeout
= FALSE
;
367 UINTN TimeoutCountdown
= 0;
368 CHAR16 TimeoutMessage
[256];
369 CHAR16 KeyAsString
[2];
372 if (Screen
->TimeoutSeconds
> 0) {
374 TimeoutCountdown
= Screen
->TimeoutSeconds
* 10;
378 StyleFunc(Screen
, &State
, MENU_FUNCTION_INIT
, NULL
);
379 IdentifyRows(&State
, Screen
);
380 // override the starting selection with the default index, if any
381 if (*DefaultEntryIndex
>= 0 && *DefaultEntryIndex
<= State
.MaxIndex
) {
382 State
.CurrentSelection
= *DefaultEntryIndex
;
383 UpdateScroll(&State
, SCROLL_NONE
);
385 State
.PaintAll
= TRUE
;
389 if (State
.PaintAll
) {
390 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
391 State
.PaintAll
= FALSE
;
392 } else if (State
.PaintSelection
) {
393 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_SELECTION
, NULL
);
394 State
.PaintSelection
= FALSE
;
398 SPrint(TimeoutMessage
, 255, L
"%s in %d seconds", Screen
->TimeoutText
, (TimeoutCountdown
+ 5) / 10);
399 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, TimeoutMessage
);
402 // read key press (and wait for it if applicable)
403 Status
= refit_call2_wrapper(ST
->ConIn
->ReadKeyStroke
, ST
->ConIn
, &key
);
404 if (Status
== EFI_NOT_READY
) {
405 if (HaveTimeout
&& TimeoutCountdown
== 0) {
407 MenuExit
= MENU_EXIT_TIMEOUT
;
409 } else if (HaveTimeout
) {
410 refit_call1_wrapper(BS
->Stall
, 100000);
413 refit_call3_wrapper(BS
->WaitForEvent
, 1, &ST
->ConIn
->WaitForKey
, &index
);
417 // the user pressed a key, cancel the timeout
418 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, L
"");
422 // react to key press
423 switch (key
.ScanCode
) {
425 UpdateScroll(&State
, SCROLL_LINE_UP
);
428 UpdateScroll(&State
, SCROLL_LINE_LEFT
);
431 UpdateScroll(&State
, SCROLL_LINE_DOWN
);
434 UpdateScroll(&State
, SCROLL_LINE_RIGHT
);
437 UpdateScroll(&State
, SCROLL_FIRST
);
440 UpdateScroll(&State
, SCROLL_LAST
);
443 UpdateScroll(&State
, SCROLL_PAGE_UP
);
446 UpdateScroll(&State
, SCROLL_PAGE_DOWN
);
449 MenuExit
= MENU_EXIT_ESCAPE
;
453 MenuExit
= MENU_EXIT_DETAILS
;
460 MenuExit
= MENU_EXIT_ESCAPE
;
463 switch (key
.UnicodeChar
) {
465 case CHAR_CARRIAGE_RETURN
:
467 MenuExit
= MENU_EXIT_ENTER
;
470 MenuExit
= MENU_EXIT_DETAILS
;
473 KeyAsString
[0] = key
.UnicodeChar
;
475 ShortcutEntry
= FindMenuShortcutEntry(Screen
, KeyAsString
);
476 if (ShortcutEntry
>= 0) {
477 State
.CurrentSelection
= ShortcutEntry
;
478 MenuExit
= MENU_EXIT_ENTER
;
484 StyleFunc(Screen
, &State
, MENU_FUNCTION_CLEANUP
, NULL
);
487 *ChosenEntry
= Screen
->Entries
[State
.CurrentSelection
];
488 *DefaultEntryIndex
= State
.CurrentSelection
;
490 } /* static UINTN RunGenericMenu() */
493 // text-mode generic style
496 static VOID
TextMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
499 UINTN MenuWidth
, ItemWidth
, MenuHeight
;
500 static UINTN MenuPosY
;
501 static CHAR16
**DisplayStrings
;
502 CHAR16 TimeoutMessage
[256];
504 State
->ScrollMode
= SCROLL_MODE_TEXT
;
507 case MENU_FUNCTION_INIT
:
510 if (Screen
->InfoLineCount
> 0)
511 MenuPosY
+= Screen
->InfoLineCount
+ 1;
512 MenuHeight
= ConHeight
- MenuPosY
- 3;
513 if (Screen
->TimeoutSeconds
> 0)
515 InitScroll(State
, Screen
->EntryCount
, MenuHeight
);
517 // determine width of the menu
518 MenuWidth
= 20; // minimum
519 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
520 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
521 if (MenuWidth
< ItemWidth
)
522 MenuWidth
= ItemWidth
;
525 if (MenuWidth
> ConWidth
- 3)
526 MenuWidth
= ConWidth
- 3;
528 // prepare strings for display
529 DisplayStrings
= AllocatePool(sizeof(CHAR16
*) * Screen
->EntryCount
);
530 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
531 // Note: Theoretically, SPrint() is a cleaner way to do this; but the
532 // description of the StrSize parameter to SPrint implies it's measured
533 // in characters, but in practice both TianoCore and GNU-EFI seem to
534 // use bytes instead, resulting in truncated displays. I could just
535 // double the size of the StrSize parameter, but that seems unsafe in
536 // case a future library change starts treating this as characters, so
537 // I'm doing it the hard way in this instance.
538 // TODO: Review the above and possibly change other uses of SPrint()
539 DisplayStrings
[i
] = AllocateZeroPool(2 * sizeof(CHAR16
));
540 DisplayStrings
[i
][0] = L
' ';
541 MergeStrings(&DisplayStrings
[i
], Screen
->Entries
[i
]->Title
, 0);
542 if (StrLen(DisplayStrings
[i
]) > MenuWidth
)
543 DisplayStrings
[i
][MenuWidth
- 1] = 0;
544 // TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
545 // TODO: account for double-width characters
549 BeginTextScreen(Screen
->Title
);
550 if (Screen
->InfoLineCount
> 0) {
551 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
552 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
553 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, 4 + i
);
554 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->InfoLines
[i
]);
560 case MENU_FUNCTION_CLEANUP
:
561 // release temporary memory
562 for (i
= 0; i
<= State
->MaxIndex
; i
++)
563 MyFreePool(DisplayStrings
[i
]);
564 MyFreePool(DisplayStrings
);
567 case MENU_FUNCTION_PAINT_ALL
:
568 // paint the whole screen (initially and after scrolling)
569 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
570 if (i
>= State
->FirstVisible
&& i
<= State
->LastVisible
) {
571 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2, MenuPosY
+ (i
- State
->FirstVisible
));
572 if (i
== State
->CurrentSelection
)
573 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
575 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
576 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[i
]);
579 // scrolling indicators
580 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_SCROLLARROW
);
581 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
);
582 if (State
->FirstVisible
> 0)
583 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowUp
);
585 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
586 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
+ State
->MaxVisible
);
587 if (State
->LastVisible
< State
->MaxIndex
)
588 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowDown
);
590 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
591 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
592 if (Screen
->Hint1
!= NULL
) {
593 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 2);
594 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint1
);
596 if (Screen
->Hint2
!= NULL
) {
597 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 1);
598 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint2
);
603 case MENU_FUNCTION_PAINT_SELECTION
:
604 // redraw selection cursor
605 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
606 MenuPosY
+ (State
->PreviousSelection
- State
->FirstVisible
));
607 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
608 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->PreviousSelection
]);
609 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
610 MenuPosY
+ (State
->CurrentSelection
- State
->FirstVisible
));
611 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
612 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->CurrentSelection
]);
615 case MENU_FUNCTION_PAINT_TIMEOUT
:
616 if (ParamText
[0] == 0) {
618 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
619 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 3);
620 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, BlankLine
+ 1);
622 // paint or update message
623 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_ERROR
);
624 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, ConHeight
- 3);
625 SPrint(TimeoutMessage
, 255, L
"%s ", ParamText
);
626 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, TimeoutMessage
);
634 // graphical generic style
639 static VOID
DrawText(IN CHAR16
*Text
, IN BOOLEAN Selected
, IN UINTN FieldWidth
, IN UINTN XPos
, IN UINTN YPos
)
641 EG_IMAGE
*TextBuffer
;
644 TextBuffer
= egCreateImage(FieldWidth
, TEXT_LINE_HEIGHT
, FALSE
);
646 egFillImage(TextBuffer
, &MenuBackgroundPixel
);
647 Bg
= MenuBackgroundPixel
;
649 // draw selection bar background
650 egFillImageArea(TextBuffer
, 0, 0, FieldWidth
, TextBuffer
->Height
, &SelectionBackgroundPixel
);
651 Bg
= SelectionBackgroundPixel
;
655 egRenderText(Text
, TextBuffer
, TEXT_XMARGIN
, TEXT_YMARGIN
, (Bg
.r
+ Bg
.g
+ Bg
.b
) / 3);
656 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
657 // BltImage(TextBuffer, XPos, YPos);
660 // Finds the average brightness of the input Image.
661 // NOTE: Passing an Image that covers the whole screen can strain the
662 // capacity of a UINTN on a 32-bit system with a very large display.
663 // As the intended use for this function is to handle a single text
664 // string's background, this shouldn't be a problem, but it may need
665 // addressing if it's applied more broadly....
666 static UINT8
AverageBrightness(EG_IMAGE
*Image
) {
671 for (i
= 0; i
< (Image
->Width
* Image
->Height
); i
++) {
672 Sum
+= (Image
->PixelData
[i
].r
+ Image
->PixelData
[i
].g
+ Image
->PixelData
[i
].b
);
675 return (UINT8
) (Sum
/ (Image
->Width
* Image
->Height
* 3));
676 } // UINT8 AverageBrightness()
678 static VOID
DrawTextWithTransparency(IN CHAR16
*Text
, IN UINTN XPos
, IN UINTN YPos
)
680 UINTN TextWidth
, TextPosX
;
681 EG_IMAGE
*TextBuffer
;
683 TextBuffer
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
, LAYOUT_TEXT_WIDTH
, TEXT_LINE_HEIGHT
);
686 egMeasureText(Text
, &TextWidth
, NULL
);
687 if (TextWidth
> TextBuffer
->Width
)
690 TextPosX
= (TextBuffer
->Width
- TextWidth
) / 2;
691 egRenderText(Text
, TextBuffer
, TextPosX
, 0, AverageBrightness(TextBuffer
));
692 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
695 // Compute the size & position of the window that will hold a subscreen's information.
696 static VOID
ComputeSubScreenWindowSize(REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*XPos
, UINTN
*YPos
, UINTN
*Width
, UINTN
*Height
, UINTN
*LineWidth
) {
697 UINTN i
, ItemWidth
, HintTop
, BannerBottomEdge
, TitleWidth
, CenteredTop
;
701 TitleWidth
= StrLen(Screen
->Title
);
702 if ((Screen
->TitleImage
) && (TitleWidth
> (Screen
->TitleImage
->Width
/ FONT_CELL_WIDTH
))) {
703 TitleWidth
-= (Screen
->TitleImage
->Width
/ FONT_CELL_WIDTH
);
705 if (TitleWidth
> *Width
) {
708 for (i
= 0; i
< Screen
->InfoLineCount
; i
++) {
709 ItemWidth
= StrLen(Screen
->InfoLines
[i
]);
710 if (*Width
< ItemWidth
) {
715 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
716 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
717 if (*Width
< ItemWidth
) {
722 *Width
= TEXT_XMARGIN
* 2 + *Width
* FONT_CELL_WIDTH
;
724 if (Screen
->TitleImage
)
725 *Width
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
+ FONT_CELL_WIDTH
);
727 *Width
+= FONT_CELL_WIDTH
;
729 // Keep it within the bounds of the screen, or 2/3 of the screen's width
730 // for screens over 800 pixels wide
731 if (*Width
> UGAWidth
)
733 if ((*Width
> (2 * UGAWidth
) / 3) && (UGAWidth
> 800))
734 *Width
= (2 * UGAWidth
) / 3;
736 *XPos
= (UGAWidth
- *Width
) / 2;
738 HintTop
= UGAHeight
- (FONT_CELL_HEIGHT
* 3); // top of hint text
739 *Height
*= TEXT_LINE_HEIGHT
;
740 if (Screen
->TitleImage
&& (*Height
< (Screen
->TitleImage
->Height
+ TEXT_LINE_HEIGHT
* 3)))
741 *Height
= Screen
->TitleImage
->Height
+ TEXT_LINE_HEIGHT
* 3;
743 if (GlobalConfig
.BannerBottomEdge
>= HintTop
) { // probably a full-screen image; treat it as an empty banner
744 BannerBottomEdge
= 0;
746 BannerBottomEdge
= GlobalConfig
.BannerBottomEdge
;
748 if (*Height
> (HintTop
-BannerBottomEdge
- FONT_CELL_HEIGHT
* 2)) {
749 BannerBottomEdge
= 0;
751 if (*Height
> (HintTop
-BannerBottomEdge
- FONT_CELL_HEIGHT
* 2)) {
752 // TODO: Implement scrolling in text screen.
753 *Height
= (HintTop
- BannerBottomEdge
- FONT_CELL_HEIGHT
* 2);
755 *YPos
= BannerBottomEdge
+ FONT_CELL_HEIGHT
+ (HintTop
- BannerBottomEdge
- *Height
) / 2;
756 // Above often produces a text field that feels bottom-weighted, so adjust
757 // upward a bit, if possible....
758 CenteredTop
= ((UGAHeight
- *Height
) / 2);
759 if ((*YPos
> CenteredTop
) && (CenteredTop
> BannerBottomEdge
))
761 } // VOID ComputeSubScreenWindowSize()
763 // Displays sub-menus
764 static VOID
GraphicsMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
768 static UINTN LineWidth
, MenuWidth
, MenuHeight
, EntriesPosX
, EntriesPosY
, TimeoutPosY
;
770 EG_PIXEL
*BackgroundPixel
= &(GlobalConfig
.ScreenBackground
->PixelData
[0]);
772 State
->ScrollMode
= SCROLL_MODE_TEXT
;
775 case MENU_FUNCTION_INIT
:
776 InitScroll(State
, Screen
->EntryCount
, 0);
777 ComputeSubScreenWindowSize(Screen
, State
, &EntriesPosX
, &EntriesPosY
, &MenuWidth
, &MenuHeight
, &LineWidth
);
778 TimeoutPosY
= EntriesPosY
+ (Screen
->EntryCount
+ 1) * TEXT_LINE_HEIGHT
;
781 SwitchToGraphicsAndClear();
782 Window
= egCreateFilledImage(MenuWidth
, MenuHeight
, FALSE
, BackgroundPixel
);
783 egDrawImage(Window
, EntriesPosX
, EntriesPosY
);
784 egMeasureText(Screen
->Title
, &ItemWidth
, NULL
);
785 DrawText(Screen
->Title
, FALSE
, (StrLen(Screen
->Title
) + 2) * FONT_CELL_WIDTH
,
786 EntriesPosX
+ (MenuWidth
- ItemWidth
) / 2, EntriesPosY
+= TEXT_LINE_HEIGHT
);
787 if (Screen
->TitleImage
) {
788 BltImageAlpha(Screen
->TitleImage
, EntriesPosX
, EntriesPosY
+ TEXT_LINE_HEIGHT
* 2, BackgroundPixel
);
789 EntriesPosX
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
);
791 EntriesPosY
+= (TEXT_LINE_HEIGHT
* 2);
792 if (Screen
->InfoLineCount
> 0) {
793 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
794 DrawText(Screen
->InfoLines
[i
], FALSE
, LineWidth
, EntriesPosX
, EntriesPosY
);
795 EntriesPosY
+= TEXT_LINE_HEIGHT
;
797 EntriesPosY
+= TEXT_LINE_HEIGHT
; // also add a blank line
802 case MENU_FUNCTION_CLEANUP
:
806 case MENU_FUNCTION_PAINT_ALL
:
807 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
808 DrawText(Screen
->Entries
[i
]->Title
, (i
== State
->CurrentSelection
), LineWidth
, EntriesPosX
,
809 EntriesPosY
+ i
* TEXT_LINE_HEIGHT
);
811 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
812 if ((Screen
->Hint1
!= NULL
) && (StrLen(Screen
->Hint1
) > 0))
813 DrawTextWithTransparency(Screen
->Hint1
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 3));
814 if ((Screen
->Hint2
!= NULL
) && (StrLen(Screen
->Hint2
) > 0))
815 DrawTextWithTransparency(Screen
->Hint2
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 2));
819 case MENU_FUNCTION_PAINT_SELECTION
:
820 // redraw selection cursor
821 DrawText(Screen
->Entries
[State
->PreviousSelection
]->Title
, FALSE
, LineWidth
,
822 EntriesPosX
, EntriesPosY
+ State
->PreviousSelection
* TEXT_LINE_HEIGHT
);
823 DrawText(Screen
->Entries
[State
->CurrentSelection
]->Title
, TRUE
, LineWidth
,
824 EntriesPosX
, EntriesPosY
+ State
->CurrentSelection
* TEXT_LINE_HEIGHT
);
827 case MENU_FUNCTION_PAINT_TIMEOUT
:
828 DrawText(ParamText
, FALSE
, LineWidth
, EntriesPosX
, TimeoutPosY
);
832 } // static VOID GraphicsMenuStyle()
835 // graphical main menu style
838 static VOID
DrawMainMenuEntry(REFIT_MENU_ENTRY
*Entry
, BOOLEAN selected
, UINTN XPos
, UINTN YPos
)
840 EG_IMAGE
*Background
;
842 if (SelectionImages
!= NULL
) {
844 Background
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
,
845 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
846 egComposeImage(Background
, SelectionImages
[Entry
->Row
], 0, 0);
847 BltImageCompositeBadge(Background
, Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
);
848 } else { // Image not selected; copy background
849 egDrawImageWithTransparency(Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
,
850 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
853 } // VOID DrawMainMenuEntry()
855 static VOID
PaintAll(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
856 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
859 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0)
860 AdjustScrollState(State
);
861 for (i
= State
->FirstVisible
; i
<= State
->MaxIndex
; i
++) {
862 if (Screen
->Entries
[i
]->Row
== 0) {
863 if (i
<= State
->LastVisible
) {
864 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
,
865 itemPosX
[i
- State
->FirstVisible
], row0PosY
);
868 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
, itemPosX
[i
], row1PosY
);
871 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
))
872 DrawTextWithTransparency(Screen
->Entries
[State
->CurrentSelection
]->Title
,
873 (UGAWidth
- LAYOUT_TEXT_WIDTH
) >> 1, textPosY
);
875 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
876 DrawTextWithTransparency(Screen
->Hint1
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 3));
877 DrawTextWithTransparency(Screen
->Hint2
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 2));
879 } // static VOID PaintAll()
881 // Move the selection to State->CurrentSelection, adjusting icon row if necessary...
882 static VOID
PaintSelection(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
883 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
884 UINTN XSelectPrev
, XSelectCur
, YPosPrev
, YPosCur
;
886 if (((State
->CurrentSelection
<= State
->LastVisible
) && (State
->CurrentSelection
>= State
->FirstVisible
)) ||
887 (State
->CurrentSelection
>= State
->InitialRow1
) ) {
888 if (Screen
->Entries
[State
->PreviousSelection
]->Row
== 0) {
889 XSelectPrev
= State
->PreviousSelection
- State
->FirstVisible
;
892 XSelectPrev
= State
->PreviousSelection
;
895 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0) {
896 XSelectCur
= State
->CurrentSelection
- State
->FirstVisible
;
899 XSelectCur
= State
->CurrentSelection
;
902 DrawMainMenuEntry(Screen
->Entries
[State
->PreviousSelection
], FALSE
, itemPosX
[XSelectPrev
], YPosPrev
);
903 DrawMainMenuEntry(Screen
->Entries
[State
->CurrentSelection
], TRUE
, itemPosX
[XSelectCur
], YPosCur
);
904 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
))
905 DrawTextWithTransparency(Screen
->Entries
[State
->CurrentSelection
]->Title
,
906 (UGAWidth
- LAYOUT_TEXT_WIDTH
) >> 1, textPosY
);
907 } else { // Current selection not visible; must redraw the menu....
908 MainMenuStyle(Screen
, State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
910 } // static VOID MoveSelection(VOID)
912 // Display an icon at the specified location. Uses the image specified by
913 // ExternalFilename if it's available, or BuiltInImage if it's not. The
914 // Y position is specified as the center value, and so is adjusted by half
915 // the icon's height. The X position is set along the icon's left
916 // edge if Alignment == ALIGN_LEFT, and along the right edge if
917 // Alignment == ALIGN_RIGHT
918 static VOID
PaintIcon(IN EG_EMBEDDED_IMAGE
*BuiltInIcon
, IN CHAR16
*ExternalFilename
, UINTN PosX
, UINTN PosY
, UINTN Alignment
) {
919 EG_IMAGE
*Icon
= NULL
;
921 if (FileExists(SelfDir
, ExternalFilename
))
922 Icon
= egLoadIcon(SelfDir
, ExternalFilename
, 48);
924 Icon
= egPrepareEmbeddedImage(BuiltInIcon
, TRUE
);
926 if (Alignment
== ALIGN_RIGHT
)
928 egDrawImageWithTransparency(Icon
, NULL
, PosX
, PosY
- (Icon
->Height
/ 2), Icon
->Width
, Icon
->Height
);
930 } // static VOID PaintIcon()
932 inline UINTN
ComputeRow0PosX(VOID
) {
933 // return ((UGAHeight / 2) - (5 * ROW0_TILESIZE / 6));
934 return ((UGAHeight
/ 2) - ROW0_TILESIZE
/ 2);
935 } // UINTN ComputeRow0PosX()
937 // Display (or erase) the arrow icons to the left and right of an icon's row,
939 static VOID
PaintArrows(SCROLL_STATE
*State
, UINTN PosX
, UINTN PosY
, UINTN row0Loaders
) {
940 CHAR16 FileName
[256];
942 UINTN Width
, Height
, RightX
, AdjPosY
;
944 // NOTE: Assume that left and right arrows are of the same size....
945 Width
= egemb_arrow_left
.Width
;
946 Height
= egemb_arrow_left
.Height
;
947 RightX
= (UGAWidth
+ (ROW0_TILESIZE
+ TILE_XSPACING
) * State
->MaxVisible
) / 2 + TILE_XSPACING
;
948 AdjPosY
= PosY
- (Height
/ 2);
950 // For PaintIcon() calls, the starting Y position is moved to the midpoint
951 // of the surrounding row; PaintIcon() adjusts this back up by half the
952 // icon's height to properly center it.
953 if ((State
->FirstVisible
> 0) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
954 SPrint(FileName
, 255, L
"%s\\arrow_left.icns", GlobalConfig
.IconsDir
? GlobalConfig
.IconsDir
: DEFAULT_ICONS_DIR
);
955 PaintIcon(&egemb_arrow_left
, FileName
, PosX
, PosY
, ALIGN_RIGHT
);
957 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, PosX
- Width
, AdjPosY
, Width
, Height
);
958 BltImage(TempImage
, PosX
- Width
, AdjPosY
);
959 egFreeImage(TempImage
);
962 if ((State
->LastVisible
< (row0Loaders
- 1)) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
963 SPrint(FileName
, 255, L
"%s\\arrow_right.icns", GlobalConfig
.IconsDir
? GlobalConfig
.IconsDir
: DEFAULT_ICONS_DIR
);
964 PaintIcon(&egemb_arrow_right
, FileName
, RightX
, PosY
, ALIGN_LEFT
);
966 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, RightX
, AdjPosY
, Width
, Height
);
967 BltImage(TempImage
, RightX
, AdjPosY
);
968 egFreeImage(TempImage
);
970 } // VOID PaintArrows()
972 // Display main menu in graphics mode
973 VOID
MainMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
976 static UINTN row0PosX
, row0PosXRunning
, row1PosY
, row0Loaders
;
977 UINTN row0Count
, row1Count
, row1PosX
, row1PosXRunning
;
978 static UINTN
*itemPosX
;
979 static UINTN row0PosY
, textPosY
;
981 State
->ScrollMode
= SCROLL_MODE_ICONS
;
984 case MENU_FUNCTION_INIT
:
985 InitScroll(State
, Screen
->EntryCount
, GlobalConfig
.MaxTags
);
991 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
992 if (Screen
->Entries
[i
]->Row
== 1) {
996 if (row0Count
< State
->MaxVisible
)
1000 row0PosX
= (UGAWidth
+ TILE_XSPACING
- (ROW0_TILESIZE
+ TILE_XSPACING
) * row0Count
) >> 1;
1001 row0PosY
= ComputeRow0PosX();
1002 row1PosX
= (UGAWidth
+ TILE_XSPACING
- (ROW1_TILESIZE
+ TILE_XSPACING
) * row1Count
) >> 1;
1003 row1PosY
= row0PosY
+ ROW0_TILESIZE
+ TILE_YSPACING
;
1005 textPosY
= row1PosY
+ ROW1_TILESIZE
+ TILE_YSPACING
;
1007 textPosY
= row1PosY
;
1009 itemPosX
= AllocatePool(sizeof(UINTN
) * Screen
->EntryCount
);
1010 row0PosXRunning
= row0PosX
;
1011 row1PosXRunning
= row1PosX
;
1012 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
1013 if (Screen
->Entries
[i
]->Row
== 0) {
1014 itemPosX
[i
] = row0PosXRunning
;
1015 row0PosXRunning
+= ROW0_TILESIZE
+ TILE_XSPACING
;
1017 itemPosX
[i
] = row1PosXRunning
;
1018 row1PosXRunning
+= ROW1_TILESIZE
+ TILE_XSPACING
;
1023 SwitchToGraphicsAndClear();
1026 case MENU_FUNCTION_CLEANUP
:
1027 MyFreePool(itemPosX
);
1030 case MENU_FUNCTION_PAINT_ALL
:
1031 PaintAll(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1032 // For PaintArrows(), the starting Y position is moved to the midpoint
1033 // of the surrounding row; PaintIcon() adjusts this back up by half the
1034 // icon's height to properly center it.
1035 PaintArrows(State
, row0PosX
- TILE_XSPACING
, row0PosY
+ (ROW0_TILESIZE
/ 2), row0Loaders
);
1038 case MENU_FUNCTION_PAINT_SELECTION
:
1039 PaintSelection(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1042 case MENU_FUNCTION_PAINT_TIMEOUT
:
1043 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
))
1044 DrawTextWithTransparency(ParamText
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) >> 1, textPosY
+ TEXT_LINE_HEIGHT
);
1048 } // VOID MainMenuStyle()
1050 // Enable the user to edit boot loader options.
1051 // Returns TRUE if the user exited with edited options; FALSE if the user
1052 // pressed Esc to terminate the edit.
1053 static BOOLEAN
EditOptions(LOADER_ENTRY
*MenuEntry
) {
1055 CHAR16
*EditedOptions
;
1056 BOOLEAN retval
= FALSE
;
1058 if (GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_EDITOR
) {
1062 refit_call4_wrapper(ST
->ConOut
->QueryMode
, ST
->ConOut
, ST
->ConOut
->Mode
->Mode
, &x_max
, &y_max
);
1064 if (!GlobalConfig
.TextOnly
)
1067 if (line_edit(MenuEntry
->LoadOptions
, &EditedOptions
, x_max
)) {
1068 MyFreePool(MenuEntry
->LoadOptions
);
1069 MenuEntry
->LoadOptions
= EditedOptions
;
1072 if (!GlobalConfig
.TextOnly
)
1075 } // VOID EditOptions()
1078 // user-callable dispatcher functions
1081 UINTN
RunMenu(IN REFIT_MENU_SCREEN
*Screen
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1083 INTN DefaultEntry
= -1;
1084 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1086 if (AllowGraphicsMode
)
1087 Style
= GraphicsMenuStyle
;
1089 return RunGenericMenu(Screen
, Style
, &DefaultEntry
, ChosenEntry
);
1092 UINTN
RunMainMenu(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
* DefaultSelection
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1094 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1095 MENU_STYLE_FUNC MainStyle
= TextMenuStyle
;
1096 REFIT_MENU_ENTRY
*TempChosenEntry
;
1098 INTN DefaultEntryIndex
= -1;
1099 INTN DefaultSubmenuIndex
= -1;
1101 if (DefaultSelection
!= NULL
) {
1102 // Find a menu entry that includes *DefaultSelection as a substring
1103 DefaultEntryIndex
= FindMenuShortcutEntry(Screen
, DefaultSelection
);
1106 if (AllowGraphicsMode
) {
1107 Style
= GraphicsMenuStyle
;
1108 MainStyle
= MainMenuStyle
;
1112 MenuExit
= RunGenericMenu(Screen
, MainStyle
, &DefaultEntryIndex
, &TempChosenEntry
);
1113 Screen
->TimeoutSeconds
= 0;
1115 if (MenuExit
== MENU_EXIT_DETAILS
) {
1116 if (TempChosenEntry
->SubScreen
!= NULL
) {
1117 MenuExit
= RunGenericMenu(TempChosenEntry
->SubScreen
, Style
, &DefaultSubmenuIndex
, &TempChosenEntry
);
1118 if (MenuExit
== MENU_EXIT_ESCAPE
|| TempChosenEntry
->Tag
== TAG_RETURN
)
1120 if (MenuExit
== MENU_EXIT_DETAILS
) {
1121 if (!EditOptions((LOADER_ENTRY
*) TempChosenEntry
))
1124 } else { // no sub-screen; ignore keypress
1127 } // Enter sub-screen
1131 *ChosenEntry
= TempChosenEntry
;
1133 } /* UINTN RunMainMenu() */