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()
353 // Blank the screen, wait for a keypress, and restore banner/background.
354 // Screen may still require redrawing of text and icons on return.
355 // TODO: Support more sophisticated screen savers, such as power-saving
356 // mode and dynamic images.
357 static VOID
SaveScreen(VOID
) {
359 EG_PIXEL Black
= { 0x0, 0x0, 0x0, 0 };
361 egClearScreen(&Black
);
362 refit_call3_wrapper(BS
->WaitForEvent
, 1, &ST
->ConIn
->WaitForKey
, &index
);
363 if (AllowGraphicsMode
)
364 SwitchToGraphicsAndClear();
366 } // VOID SaveScreen()
369 // generic menu function
371 static UINTN
RunGenericMenu(IN REFIT_MENU_SCREEN
*Screen
, IN MENU_STYLE_FUNC StyleFunc
, IN OUT INTN
*DefaultEntryIndex
,
372 OUT REFIT_MENU_ENTRY
**ChosenEntry
)
379 BOOLEAN HaveTimeout
= FALSE
;
380 UINTN TimeoutCountdown
= 0;
381 INTN PreviousTime
= -1, CurrentTime
, TimeSinceKeystroke
= 0;
382 CHAR16 TimeoutMessage
[256];
383 CHAR16 KeyAsString
[2];
385 // EG_PIXEL Black = { 0x0, 0x0, 0x0, 0 };
387 if (Screen
->TimeoutSeconds
> 0) {
389 TimeoutCountdown
= Screen
->TimeoutSeconds
* 10;
393 StyleFunc(Screen
, &State
, MENU_FUNCTION_INIT
, NULL
);
394 IdentifyRows(&State
, Screen
);
395 // override the starting selection with the default index, if any
396 if (*DefaultEntryIndex
>= 0 && *DefaultEntryIndex
<= State
.MaxIndex
) {
397 State
.CurrentSelection
= *DefaultEntryIndex
;
398 UpdateScroll(&State
, SCROLL_NONE
);
400 State
.PaintAll
= TRUE
;
404 if (State
.PaintAll
) {
405 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
406 State
.PaintAll
= FALSE
;
407 } else if (State
.PaintSelection
) {
408 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_SELECTION
, NULL
);
409 State
.PaintSelection
= FALSE
;
413 CurrentTime
= (TimeoutCountdown
+ 5) / 10;
414 if (CurrentTime
!= PreviousTime
) {
415 SPrint(TimeoutMessage
, 255, L
"%s in %d seconds", Screen
->TimeoutText
, CurrentTime
);
416 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, TimeoutMessage
);
417 PreviousTime
= CurrentTime
;
421 // read key press (and wait for it if applicable)
422 Status
= refit_call2_wrapper(ST
->ConIn
->ReadKeyStroke
, ST
->ConIn
, &key
);
423 if (Status
!= EFI_SUCCESS
) {
424 if (HaveTimeout
&& TimeoutCountdown
== 0) {
426 MenuExit
= MENU_EXIT_TIMEOUT
;
428 } else if (HaveTimeout
) {
429 refit_call1_wrapper(BS
->Stall
, 100000); // Pause for 100 ms
431 TimeSinceKeystroke
++;
432 } else if (GlobalConfig
.ScreensaverTime
> 0) {
433 refit_call1_wrapper(BS
->Stall
, 100000); // Pause for 100 ms
434 TimeSinceKeystroke
++;
435 if (TimeSinceKeystroke
> (GlobalConfig
.ScreensaverTime
* 10)) {
437 State
.PaintAll
= TRUE
;
438 TimeSinceKeystroke
= 0;
441 refit_call3_wrapper(BS
->WaitForEvent
, 1, &ST
->ConIn
->WaitForKey
, &index
);
445 TimeSinceKeystroke
= 0;
446 } // if/else !read keystroke
449 // the user pressed a key, cancel the timeout
450 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, L
"");
454 // react to key press
455 switch (key
.ScanCode
) {
457 UpdateScroll(&State
, SCROLL_LINE_UP
);
460 UpdateScroll(&State
, SCROLL_LINE_LEFT
);
463 UpdateScroll(&State
, SCROLL_LINE_DOWN
);
466 UpdateScroll(&State
, SCROLL_LINE_RIGHT
);
469 UpdateScroll(&State
, SCROLL_FIRST
);
472 UpdateScroll(&State
, SCROLL_LAST
);
475 UpdateScroll(&State
, SCROLL_PAGE_UP
);
478 UpdateScroll(&State
, SCROLL_PAGE_DOWN
);
481 MenuExit
= MENU_EXIT_ESCAPE
;
485 MenuExit
= MENU_EXIT_DETAILS
;
492 MenuExit
= MENU_EXIT_ESCAPE
;
495 switch (key
.UnicodeChar
) {
497 case CHAR_CARRIAGE_RETURN
:
499 MenuExit
= MENU_EXIT_ENTER
;
502 MenuExit
= MENU_EXIT_DETAILS
;
505 KeyAsString
[0] = key
.UnicodeChar
;
507 ShortcutEntry
= FindMenuShortcutEntry(Screen
, KeyAsString
);
508 if (ShortcutEntry
>= 0) {
509 State
.CurrentSelection
= ShortcutEntry
;
510 MenuExit
= MENU_EXIT_ENTER
;
516 StyleFunc(Screen
, &State
, MENU_FUNCTION_CLEANUP
, NULL
);
519 *ChosenEntry
= Screen
->Entries
[State
.CurrentSelection
];
520 *DefaultEntryIndex
= State
.CurrentSelection
;
522 } /* static UINTN RunGenericMenu() */
525 // text-mode generic style
528 // Show information lines in text mode.
529 static VOID
ShowTextInfoLines(IN REFIT_MENU_SCREEN
*Screen
) {
532 BeginTextScreen(Screen
->Title
);
533 if (Screen
->InfoLineCount
> 0) {
534 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
535 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
536 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, 4 + i
);
537 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->InfoLines
[i
]);
540 } // VOID ShowTextInfoLines()
542 // Do most of the work for text-based menus....
543 static VOID
TextMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
546 UINTN MenuWidth
, ItemWidth
, MenuHeight
;
547 static UINTN MenuPosY
;
548 static CHAR16
**DisplayStrings
;
549 CHAR16 TimeoutMessage
[256];
551 State
->ScrollMode
= SCROLL_MODE_TEXT
;
554 case MENU_FUNCTION_INIT
:
557 if (Screen
->InfoLineCount
> 0)
558 MenuPosY
+= Screen
->InfoLineCount
+ 1;
559 MenuHeight
= ConHeight
- MenuPosY
- 3;
560 if (Screen
->TimeoutSeconds
> 0)
562 InitScroll(State
, Screen
->EntryCount
, MenuHeight
);
564 // determine width of the menu
565 MenuWidth
= 20; // minimum
566 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
567 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
568 if (MenuWidth
< ItemWidth
)
569 MenuWidth
= ItemWidth
;
572 if (MenuWidth
> ConWidth
- 3)
573 MenuWidth
= ConWidth
- 3;
575 // prepare strings for display
576 DisplayStrings
= AllocatePool(sizeof(CHAR16
*) * Screen
->EntryCount
);
577 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
578 // Note: Theoretically, SPrint() is a cleaner way to do this; but the
579 // description of the StrSize parameter to SPrint implies it's measured
580 // in characters, but in practice both TianoCore and GNU-EFI seem to
581 // use bytes instead, resulting in truncated displays. I could just
582 // double the size of the StrSize parameter, but that seems unsafe in
583 // case a future library change starts treating this as characters, so
584 // I'm doing it the hard way in this instance.
585 // TODO: Review the above and possibly change other uses of SPrint()
586 DisplayStrings
[i
] = AllocateZeroPool(2 * sizeof(CHAR16
));
587 DisplayStrings
[i
][0] = L
' ';
588 MergeStrings(&DisplayStrings
[i
], Screen
->Entries
[i
]->Title
, 0);
589 if (StrLen(DisplayStrings
[i
]) > MenuWidth
)
590 DisplayStrings
[i
][MenuWidth
- 1] = 0;
591 // TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
592 // TODO: account for double-width characters
597 case MENU_FUNCTION_CLEANUP
:
598 // release temporary memory
599 for (i
= 0; i
<= State
->MaxIndex
; i
++)
600 MyFreePool(DisplayStrings
[i
]);
601 MyFreePool(DisplayStrings
);
604 case MENU_FUNCTION_PAINT_ALL
:
605 // paint the whole screen (initially and after scrolling)
607 ShowTextInfoLines(Screen
);
608 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
609 if (i
>= State
->FirstVisible
&& i
<= State
->LastVisible
) {
610 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2, MenuPosY
+ (i
- State
->FirstVisible
));
611 if (i
== State
->CurrentSelection
)
612 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
614 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
615 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[i
]);
618 // scrolling indicators
619 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_SCROLLARROW
);
620 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
);
621 if (State
->FirstVisible
> 0)
622 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowUp
);
624 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
625 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
+ State
->MaxVisible
);
626 if (State
->LastVisible
< State
->MaxIndex
)
627 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowDown
);
629 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
630 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
631 if (Screen
->Hint1
!= NULL
) {
632 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 2);
633 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint1
);
635 if (Screen
->Hint2
!= NULL
) {
636 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 1);
637 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint2
);
642 case MENU_FUNCTION_PAINT_SELECTION
:
643 // redraw selection cursor
644 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
645 MenuPosY
+ (State
->PreviousSelection
- State
->FirstVisible
));
646 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
647 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->PreviousSelection
]);
648 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
649 MenuPosY
+ (State
->CurrentSelection
- State
->FirstVisible
));
650 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
651 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->CurrentSelection
]);
654 case MENU_FUNCTION_PAINT_TIMEOUT
:
655 if (ParamText
[0] == 0) {
657 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
658 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 3);
659 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, BlankLine
+ 1);
661 // paint or update message
662 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_ERROR
);
663 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, ConHeight
- 3);
664 SPrint(TimeoutMessage
, 255, L
"%s ", ParamText
);
665 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, TimeoutMessage
);
673 // graphical generic style
676 inline static UINTN
TextLineHeight(VOID
) {
677 return egGetFontHeight() + TEXT_YMARGIN
* 2;
678 } // UINTN TextLineHeight()
684 // Display text with a solid background (MenuBackgroundPixel or SelectionBackgroundPixel).
685 // Indents text by one character and placed TEXT_YMARGIN pixels down from the
686 // specified XPos and YPos locations.
687 static VOID
DrawText(IN CHAR16
*Text
, IN BOOLEAN Selected
, IN UINTN FieldWidth
, IN UINTN XPos
, IN UINTN YPos
)
689 EG_IMAGE
*TextBuffer
;
692 TextBuffer
= egCreateImage(FieldWidth
, TextLineHeight(), FALSE
);
694 egFillImage(TextBuffer
, &MenuBackgroundPixel
);
695 Bg
= MenuBackgroundPixel
;
697 // draw selection bar background
698 egFillImageArea(TextBuffer
, 0, 0, FieldWidth
, TextBuffer
->Height
, &SelectionBackgroundPixel
);
699 Bg
= SelectionBackgroundPixel
;
703 egRenderText(Text
, TextBuffer
, egGetFontCellWidth(), TEXT_YMARGIN
, (Bg
.r
+ Bg
.g
+ Bg
.b
) / 3);
704 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
705 // BltImage(TextBuffer, XPos, YPos);
708 // Finds the average brightness of the input Image.
709 // NOTE: Passing an Image that covers the whole screen can strain the
710 // capacity of a UINTN on a 32-bit system with a very large display.
711 // Using UINT64 instead is unworkable, since the code won't compile
712 // on a 32-bit system. As the intended use for this function is to handle
713 // a single text string's background, this shouldn't be a problem, but it
714 // may need addressing if it's applied more broadly....
715 static UINT8
AverageBrightness(EG_IMAGE
*Image
) {
720 for (i
= 0; i
< (Image
->Width
* Image
->Height
); i
++) {
721 Sum
+= (Image
->PixelData
[i
].r
+ Image
->PixelData
[i
].g
+ Image
->PixelData
[i
].b
);
724 return (UINT8
) (Sum
/ (Image
->Width
* Image
->Height
* 3));
725 } // UINT8 AverageBrightness()
727 // Display text against the screen's background image. Special case: If Text is NULL
728 // or 0-length, clear the line. Does NOT indent the text or reposition it relative
729 // to the specified XPos and YPos values.
730 static VOID
DrawTextWithTransparency(IN CHAR16
*Text
, IN UINTN XPos
, IN UINTN YPos
)
733 EG_IMAGE
*TextBuffer
= NULL
;
738 egMeasureText(Text
, &TextWidth
, NULL
);
739 if (TextWidth
== 0) {
740 TextWidth
= UGAWidth
;
744 TextBuffer
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
, TextWidth
, TextLineHeight());
745 if (TextBuffer
== NULL
) {
746 Print(L
"Error: NULL TextBuffer in DrawTextWithTransparency()\n");
751 egRenderText(Text
, TextBuffer
, 0, 0, AverageBrightness(TextBuffer
));
752 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
753 egFreeImage(TextBuffer
);
756 // Compute the size & position of the window that will hold a subscreen's information.
757 static VOID
ComputeSubScreenWindowSize(REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*XPos
, UINTN
*YPos
,
758 UINTN
*Width
, UINTN
*Height
, UINTN
*LineWidth
) {
759 UINTN i
, ItemWidth
, HintTop
, BannerBottomEdge
, TitleWidth
;
760 UINTN FontCellWidth
= egGetFontCellWidth();
761 UINTN FontCellHeight
= egGetFontHeight();
765 TitleWidth
= egComputeTextWidth(Screen
->Title
);
767 for (i
= 0; i
< Screen
->InfoLineCount
; i
++) {
768 ItemWidth
= StrLen(Screen
->InfoLines
[i
]);
769 if (*Width
< ItemWidth
) {
774 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
775 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
776 if (*Width
< ItemWidth
) {
781 *Width
= (*Width
+ 2) * FontCellWidth
;
783 if (Screen
->TitleImage
)
784 *Width
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
* 2 + FontCellWidth
);
786 *Width
+= FontCellWidth
;
788 if (*Width
< TitleWidth
)
789 *Width
= TitleWidth
+ 2 * FontCellWidth
;
791 // Keep it within the bounds of the screen, or 2/3 of the screen's width
792 // for screens over 800 pixels wide
793 if (*Width
> UGAWidth
)
796 *XPos
= (UGAWidth
- *Width
) / 2;
798 HintTop
= UGAHeight
- (FontCellHeight
* 3); // top of hint text
799 *Height
*= TextLineHeight();
800 if (Screen
->TitleImage
&& (*Height
< (Screen
->TitleImage
->Height
+ TextLineHeight() * 4)))
801 *Height
= Screen
->TitleImage
->Height
+ TextLineHeight() * 4;
803 if (GlobalConfig
.BannerBottomEdge
>= HintTop
) { // probably a full-screen image; treat it as an empty banner
804 BannerBottomEdge
= 0;
806 BannerBottomEdge
= GlobalConfig
.BannerBottomEdge
;
808 if (*Height
> (HintTop
- BannerBottomEdge
- FontCellHeight
* 2)) {
809 BannerBottomEdge
= 0;
811 if (*Height
> (HintTop
- BannerBottomEdge
- FontCellHeight
* 2)) {
812 // TODO: Implement scrolling in text screen.
813 *Height
= (HintTop
- BannerBottomEdge
- FontCellHeight
* 2);
816 *YPos
= ((UGAHeight
- *Height
) / 2);
817 if (*YPos
< BannerBottomEdge
)
818 *YPos
= BannerBottomEdge
+ FontCellHeight
+ (HintTop
- BannerBottomEdge
- *Height
) / 2;
819 } // VOID ComputeSubScreenWindowSize()
821 // Displays sub-menus
822 static VOID
GraphicsMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
826 static UINTN LineWidth
, MenuWidth
, MenuHeight
, EntriesPosX
, TitlePosX
, EntriesPosY
, TimeoutPosY
, CharWidth
;
828 EG_PIXEL
*BackgroundPixel
= &(GlobalConfig
.ScreenBackground
->PixelData
[0]);
830 CharWidth
= egGetFontCellWidth();
831 State
->ScrollMode
= SCROLL_MODE_TEXT
;
834 case MENU_FUNCTION_INIT
:
835 InitScroll(State
, Screen
->EntryCount
, 0);
836 ComputeSubScreenWindowSize(Screen
, State
, &EntriesPosX
, &EntriesPosY
, &MenuWidth
, &MenuHeight
, &LineWidth
);
837 TimeoutPosY
= EntriesPosY
+ (Screen
->EntryCount
+ 1) * TextLineHeight();
840 SwitchToGraphicsAndClear();
841 Window
= egCreateFilledImage(MenuWidth
, MenuHeight
, FALSE
, BackgroundPixel
);
842 egDrawImage(Window
, EntriesPosX
, EntriesPosY
);
843 ItemWidth
= egComputeTextWidth(Screen
->Title
);
844 if (MenuWidth
> ItemWidth
) {
845 TitlePosX
= EntriesPosX
+ (MenuWidth
- ItemWidth
) / 2 - CharWidth
;
847 TitlePosX
= EntriesPosX
;
849 i
= MenuWidth
/ CharWidth
- 2;
851 Screen
->Title
[i
] = 0;
856 case MENU_FUNCTION_CLEANUP
:
860 case MENU_FUNCTION_PAINT_ALL
:
861 ComputeSubScreenWindowSize(Screen
, State
, &EntriesPosX
, &EntriesPosY
, &MenuWidth
, &MenuHeight
, &LineWidth
);
862 DrawText(Screen
->Title
, FALSE
, (StrLen(Screen
->Title
) + 2) * CharWidth
, TitlePosX
, EntriesPosY
+= TextLineHeight());
863 if (Screen
->TitleImage
) {
864 BltImageAlpha(Screen
->TitleImage
, EntriesPosX
+ TITLEICON_SPACING
, EntriesPosY
+ TextLineHeight() * 2,
866 EntriesPosX
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
* 2);
868 EntriesPosY
+= (TextLineHeight() * 2);
869 if (Screen
->InfoLineCount
> 0) {
870 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
871 DrawText(Screen
->InfoLines
[i
], FALSE
, LineWidth
, EntriesPosX
, EntriesPosY
);
872 EntriesPosY
+= TextLineHeight();
874 EntriesPosY
+= TextLineHeight(); // also add a blank line
877 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
878 DrawText(Screen
->Entries
[i
]->Title
, (i
== State
->CurrentSelection
), LineWidth
, EntriesPosX
,
879 EntriesPosY
+ i
* TextLineHeight());
881 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
882 if ((Screen
->Hint1
!= NULL
) && (StrLen(Screen
->Hint1
) > 0))
883 DrawTextWithTransparency(Screen
->Hint1
, (UGAWidth
- egComputeTextWidth(Screen
->Hint1
)) / 2,
884 UGAHeight
- (egGetFontHeight() * 3));
885 if ((Screen
->Hint2
!= NULL
) && (StrLen(Screen
->Hint2
) > 0))
886 DrawTextWithTransparency(Screen
->Hint2
, (UGAWidth
- egComputeTextWidth(Screen
->Hint2
)) / 2,
887 UGAHeight
- (egGetFontHeight() * 2));
891 case MENU_FUNCTION_PAINT_SELECTION
:
892 // redraw selection cursor
893 DrawText(Screen
->Entries
[State
->PreviousSelection
]->Title
, FALSE
, LineWidth
,
894 EntriesPosX
, EntriesPosY
+ State
->PreviousSelection
* TextLineHeight());
895 DrawText(Screen
->Entries
[State
->CurrentSelection
]->Title
, TRUE
, LineWidth
,
896 EntriesPosX
, EntriesPosY
+ State
->CurrentSelection
* TextLineHeight());
899 case MENU_FUNCTION_PAINT_TIMEOUT
:
900 DrawText(ParamText
, FALSE
, LineWidth
, EntriesPosX
, TimeoutPosY
);
904 } // static VOID GraphicsMenuStyle()
907 // graphical main menu style
910 static VOID
DrawMainMenuEntry(REFIT_MENU_ENTRY
*Entry
, BOOLEAN selected
, UINTN XPos
, UINTN YPos
)
912 EG_IMAGE
*Background
;
914 if (SelectionImages
!= NULL
) {
916 Background
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
,
917 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
918 egComposeImage(Background
, SelectionImages
[Entry
->Row
], 0, 0);
919 BltImageCompositeBadge(Background
, Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
);
920 } else { // Image not selected; copy background
921 egDrawImageWithTransparency(Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
,
922 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
925 } // VOID DrawMainMenuEntry()
927 static VOID
PaintAll(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
928 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
931 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0)
932 AdjustScrollState(State
);
933 for (i
= State
->FirstVisible
; i
<= State
->MaxIndex
; i
++) {
934 if (Screen
->Entries
[i
]->Row
== 0) {
935 if (i
<= State
->LastVisible
) {
936 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
,
937 itemPosX
[i
- State
->FirstVisible
], row0PosY
);
940 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
, itemPosX
[i
], row1PosY
);
943 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
)) {
944 DrawTextWithTransparency(L
"", 0, textPosY
);
945 DrawTextWithTransparency(Screen
->Entries
[State
->CurrentSelection
]->Title
,
946 (UGAWidth
- egComputeTextWidth(Screen
->Entries
[State
->CurrentSelection
]->Title
)) >> 1,
950 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
951 DrawTextWithTransparency(Screen
->Hint1
, (UGAWidth
- egComputeTextWidth(Screen
->Hint1
)) / 2,
952 UGAHeight
- (egGetFontHeight() * 3));
953 DrawTextWithTransparency(Screen
->Hint2
, (UGAWidth
- egComputeTextWidth(Screen
->Hint2
)) / 2,
954 UGAHeight
- (egGetFontHeight() * 2));
956 } // static VOID PaintAll()
958 // Move the selection to State->CurrentSelection, adjusting icon row if necessary...
959 static VOID
PaintSelection(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
960 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
961 UINTN XSelectPrev
, XSelectCur
, YPosPrev
, YPosCur
;
963 if (((State
->CurrentSelection
<= State
->LastVisible
) && (State
->CurrentSelection
>= State
->FirstVisible
)) ||
964 (State
->CurrentSelection
>= State
->InitialRow1
) ) {
965 if (Screen
->Entries
[State
->PreviousSelection
]->Row
== 0) {
966 XSelectPrev
= State
->PreviousSelection
- State
->FirstVisible
;
969 XSelectPrev
= State
->PreviousSelection
;
972 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0) {
973 XSelectCur
= State
->CurrentSelection
- State
->FirstVisible
;
976 XSelectCur
= State
->CurrentSelection
;
979 DrawMainMenuEntry(Screen
->Entries
[State
->PreviousSelection
], FALSE
, itemPosX
[XSelectPrev
], YPosPrev
);
980 DrawMainMenuEntry(Screen
->Entries
[State
->CurrentSelection
], TRUE
, itemPosX
[XSelectCur
], YPosCur
);
981 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
)) {
982 DrawTextWithTransparency(L
"", 0, textPosY
);
983 DrawTextWithTransparency(Screen
->Entries
[State
->CurrentSelection
]->Title
,
984 (UGAWidth
- egComputeTextWidth(Screen
->Entries
[State
->CurrentSelection
]->Title
)) >> 1,
987 } else { // Current selection not visible; must redraw the menu....
988 MainMenuStyle(Screen
, State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
990 } // static VOID MoveSelection(VOID)
992 // Display a 48x48 icon at the specified location. Uses the image specified by
993 // ExternalFilename if it's available, or BuiltInImage if it's not. The
994 // Y position is specified as the center value, and so is adjusted by half
995 // the icon's height. The X position is set along the icon's left
996 // edge if Alignment == ALIGN_LEFT, and along the right edge if
997 // Alignment == ALIGN_RIGHT
998 static VOID
PaintIcon(IN EG_EMBEDDED_IMAGE
*BuiltInIcon
, IN CHAR16
*ExternalFilename
, UINTN PosX
, UINTN PosY
, UINTN Alignment
) {
999 EG_IMAGE
*Icon
= NULL
;
1001 Icon
= egFindIcon(ExternalFilename
, 48);
1003 Icon
= egPrepareEmbeddedImage(BuiltInIcon
, TRUE
);
1005 if (Alignment
== ALIGN_RIGHT
)
1006 PosX
-= Icon
->Width
;
1007 egDrawImageWithTransparency(Icon
, NULL
, PosX
, PosY
- (Icon
->Height
/ 2), Icon
->Width
, Icon
->Height
);
1011 inline UINTN
ComputeRow0PosY(VOID
) {
1012 return ((UGAHeight
/ 2) - ROW0_TILESIZE
/ 2);
1013 } // UINTN ComputeRow0PosY()
1015 // Display (or erase) the arrow icons to the left and right of an icon's row,
1017 static VOID
PaintArrows(SCROLL_STATE
*State
, UINTN PosX
, UINTN PosY
, UINTN row0Loaders
) {
1018 EG_IMAGE
*TempImage
;
1019 UINTN Width
, Height
, RightX
, AdjPosY
;
1021 // NOTE: Assume that left and right arrows are of the same size....
1022 Width
= egemb_arrow_left
.Width
;
1023 Height
= egemb_arrow_left
.Height
;
1024 RightX
= (UGAWidth
+ (ROW0_TILESIZE
+ TILE_XSPACING
) * State
->MaxVisible
) / 2 + TILE_XSPACING
;
1025 AdjPosY
= PosY
- (Height
/ 2);
1027 // For PaintIcon() calls, the starting Y position is moved to the midpoint
1028 // of the surrounding row; PaintIcon() adjusts this back up by half the
1029 // icon's height to properly center it.
1030 if ((State
->FirstVisible
> 0) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
1031 PaintIcon(&egemb_arrow_left
, L
"arrow_left", PosX
, PosY
, ALIGN_RIGHT
);
1033 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, PosX
- Width
, AdjPosY
, Width
, Height
);
1034 BltImage(TempImage
, PosX
- Width
, AdjPosY
);
1035 egFreeImage(TempImage
);
1038 if ((State
->LastVisible
< (row0Loaders
- 1)) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
1039 PaintIcon(&egemb_arrow_right
, L
"arrow_right", RightX
, PosY
, ALIGN_LEFT
);
1041 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, RightX
, AdjPosY
, Width
, Height
);
1042 BltImage(TempImage
, RightX
, AdjPosY
);
1043 egFreeImage(TempImage
);
1045 } // VOID PaintArrows()
1047 // Display main menu in graphics mode
1048 VOID
MainMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
1051 static UINTN row0PosX
, row0PosXRunning
, row1PosY
, row0Loaders
;
1052 UINTN row0Count
, row1Count
, row1PosX
, row1PosXRunning
;
1053 static UINTN
*itemPosX
;
1054 static UINTN row0PosY
, textPosY
;
1056 State
->ScrollMode
= SCROLL_MODE_ICONS
;
1059 case MENU_FUNCTION_INIT
:
1060 InitScroll(State
, Screen
->EntryCount
, GlobalConfig
.MaxTags
);
1066 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
1067 if (Screen
->Entries
[i
]->Row
== 1) {
1071 if (row0Count
< State
->MaxVisible
)
1075 row0PosX
= (UGAWidth
+ TILE_XSPACING
- (ROW0_TILESIZE
+ TILE_XSPACING
) * row0Count
) >> 1;
1076 row0PosY
= ComputeRow0PosY();
1077 row1PosX
= (UGAWidth
+ TILE_XSPACING
- (ROW1_TILESIZE
+ TILE_XSPACING
) * row1Count
) >> 1;
1078 row1PosY
= row0PosY
+ ROW0_TILESIZE
+ TILE_YSPACING
;
1080 textPosY
= row1PosY
+ ROW1_TILESIZE
+ TILE_YSPACING
;
1082 textPosY
= row1PosY
;
1084 itemPosX
= AllocatePool(sizeof(UINTN
) * Screen
->EntryCount
);
1085 row0PosXRunning
= row0PosX
;
1086 row1PosXRunning
= row1PosX
;
1087 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
1088 if (Screen
->Entries
[i
]->Row
== 0) {
1089 itemPosX
[i
] = row0PosXRunning
;
1090 row0PosXRunning
+= ROW0_TILESIZE
+ TILE_XSPACING
;
1092 itemPosX
[i
] = row1PosXRunning
;
1093 row1PosXRunning
+= ROW1_TILESIZE
+ TILE_XSPACING
;
1098 SwitchToGraphicsAndClear();
1101 case MENU_FUNCTION_CLEANUP
:
1102 MyFreePool(itemPosX
);
1105 case MENU_FUNCTION_PAINT_ALL
:
1106 PaintAll(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1107 // For PaintArrows(), the starting Y position is moved to the midpoint
1108 // of the surrounding row; PaintIcon() adjusts this back up by half the
1109 // icon's height to properly center it.
1110 PaintArrows(State
, row0PosX
- TILE_XSPACING
, row0PosY
+ (ROW0_TILESIZE
/ 2), row0Loaders
);
1113 case MENU_FUNCTION_PAINT_SELECTION
:
1114 PaintSelection(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1117 case MENU_FUNCTION_PAINT_TIMEOUT
:
1118 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
)) {
1119 DrawTextWithTransparency(L
"", 0, textPosY
+ TextLineHeight());
1120 DrawTextWithTransparency(ParamText
, (UGAWidth
- egComputeTextWidth(ParamText
)) >> 1, textPosY
+ TextLineHeight());
1125 } // VOID MainMenuStyle()
1127 // Enable the user to edit boot loader options.
1128 // Returns TRUE if the user exited with edited options; FALSE if the user
1129 // pressed Esc to terminate the edit.
1130 static BOOLEAN
EditOptions(LOADER_ENTRY
*MenuEntry
) {
1132 CHAR16
*EditedOptions
;
1133 BOOLEAN retval
= FALSE
;
1135 if (GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_EDITOR
) {
1139 refit_call4_wrapper(ST
->ConOut
->QueryMode
, ST
->ConOut
, ST
->ConOut
->Mode
->Mode
, &x_max
, &y_max
);
1141 if (!GlobalConfig
.TextOnly
)
1144 if (line_edit(MenuEntry
->LoadOptions
, &EditedOptions
, x_max
)) {
1145 MyFreePool(MenuEntry
->LoadOptions
);
1146 MenuEntry
->LoadOptions
= EditedOptions
;
1149 if (!GlobalConfig
.TextOnly
)
1152 } // VOID EditOptions()
1155 // user-callable dispatcher functions
1158 UINTN
RunMenu(IN REFIT_MENU_SCREEN
*Screen
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1160 INTN DefaultEntry
= -1;
1161 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1163 if (AllowGraphicsMode
)
1164 Style
= GraphicsMenuStyle
;
1166 return RunGenericMenu(Screen
, Style
, &DefaultEntry
, ChosenEntry
);
1169 UINTN
RunMainMenu(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
* DefaultSelection
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1171 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1172 MENU_STYLE_FUNC MainStyle
= TextMenuStyle
;
1173 REFIT_MENU_ENTRY
*TempChosenEntry
;
1175 INTN DefaultEntryIndex
= -1;
1176 INTN DefaultSubmenuIndex
= -1;
1178 if (DefaultSelection
!= NULL
) {
1179 // Find a menu entry that includes *DefaultSelection as a substring
1180 DefaultEntryIndex
= FindMenuShortcutEntry(Screen
, DefaultSelection
);
1183 if (AllowGraphicsMode
) {
1184 Style
= GraphicsMenuStyle
;
1185 MainStyle
= MainMenuStyle
;
1189 MenuExit
= RunGenericMenu(Screen
, MainStyle
, &DefaultEntryIndex
, &TempChosenEntry
);
1190 Screen
->TimeoutSeconds
= 0;
1192 if (MenuExit
== MENU_EXIT_DETAILS
) {
1193 if (TempChosenEntry
->SubScreen
!= NULL
) {
1194 MenuExit
= RunGenericMenu(TempChosenEntry
->SubScreen
, Style
, &DefaultSubmenuIndex
, &TempChosenEntry
);
1195 if (MenuExit
== MENU_EXIT_ESCAPE
|| TempChosenEntry
->Tag
== TAG_RETURN
)
1197 if (MenuExit
== MENU_EXIT_DETAILS
) {
1198 if (!EditOptions((LOADER_ENTRY
*) TempChosenEntry
))
1201 } else { // no sub-screen; ignore keypress
1204 } // Enter sub-screen
1208 *ChosenEntry
= TempChosenEntry
;
1210 } /* UINTN RunMainMenu() */