*/
/*
* Modifications copyright (c) 2012 Roderick W. Smith
- *
+ *
* Modifications distributed under the terms of the GNU General Public
* License (GPL) version 3 (GPLv3), a copy of which must be distributed
* with this source code or binaries made from it.
- *
+ *
*/
#include "global.h"
#include "menu.h"
#include "config.h"
#include "libeg.h"
-#include "refit_call_wrapper.h"
+#include "../include/refit_call_wrapper.h"
-#include "egemb_back_selected_small.h"
-#include "egemb_arrow_left.h"
-#include "egemb_arrow_right.h"
+#include "../include/egemb_back_selected_small.h"
+#include "../include/egemb_arrow_left.h"
+#include "../include/egemb_arrow_right.h"
// other menu definitions
#define MENU_FUNCTION_PAINT_ALL (2)
#define MENU_FUNCTION_PAINT_SELECTION (3)
#define MENU_FUNCTION_PAINT_TIMEOUT (4)
+#define MENU_FUNCTION_PAINT_HINTS (5)
typedef VOID (*MENU_STYLE_FUNC)(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINTN Function, IN CHAR16 *ParamText);
static EG_PIXEL SelectionBackgroundPixel = { 0xff, 0xff, 0xff, 0 };
static EG_IMAGE *TextBuffer = NULL;
-// Used in MainMenuStyle(), but must be persistent....
-UINTN row0PosX = 0, row0PosXRunning = 0, row1PosY = 0, row0Loaders = 0;
-
//
// Graphics helper functions
//
{
UINTN x, y, src_x, src_y;
EG_PIXEL *DestPtr, *SrcPtr;
-
+
if (!AllowGraphicsMode)
return;
if (SelectionImages[0] != NULL)
return;
-
+
// load small selection image
if (GlobalConfig.SelectionSmallFileName != NULL) {
SelectionImages[2] = egLoadImage(SelfDir, GlobalConfig.SelectionSmallFileName, FALSE);
ROW1_TILESIZE, ROW1_TILESIZE, &MenuBackgroundPixel);
if (SelectionImages[2] == NULL)
return;
-
+
// load big selection image
if (GlobalConfig.SelectionBigFileName != NULL) {
SelectionImages[0] = egLoadImage(SelfDir, GlobalConfig.SelectionBigFileName, FALSE);
}
if (SelectionImages[0] == NULL) {
// calculate big selection image from small one
-
+
SelectionImages[0] = egCreateImage(ROW0_TILESIZE, ROW0_TILESIZE, FALSE);
if (SelectionImages[0] == NULL) {
egFreeImage(SelectionImages[2]);
SelectionImages[2] = NULL;
return;
}
-
+
DestPtr = SelectionImages[0]->PixelData;
SrcPtr = SelectionImages[2]->PixelData;
for (y = 0; y < ROW0_TILESIZE; y++) {
src_y = (ROW1_TILESIZE >> 1);
else
src_y = y - (ROW0_TILESIZE - ROW1_TILESIZE);
-
+
for (x = 0; x < ROW0_TILESIZE; x++) {
if (x < (ROW1_TILESIZE >> 1))
src_x = x;
src_x = (ROW1_TILESIZE >> 1);
else
src_x = x - (ROW0_TILESIZE - ROW1_TILESIZE);
-
+
*DestPtr++ = SrcPtr[src_y * ROW1_TILESIZE + src_x];
}
}
}
-
+
// non-selected background images
SelectionImages[1] = egCreateFilledImage(ROW0_TILESIZE, ROW0_TILESIZE, FALSE, &MenuBackgroundPixel);
SelectionImages[3] = egCreateFilledImage(ROW1_TILESIZE, ROW1_TILESIZE, FALSE, &MenuBackgroundPixel);
static VOID InitScroll(OUT SCROLL_STATE *State, IN UINTN ItemCount, IN UINTN VisibleSpace)
{
- State->LastSelection = State->CurrentSelection = 0;
+ State->PreviousSelection = State->CurrentSelection = 0;
State->MaxIndex = (INTN)ItemCount - 1;
State->FirstVisible = 0;
- State->MaxVisible = UGAWidth / (ROW0_TILESIZE + TILE_XSPACING) - 1;
+ if (AllowGraphicsMode) {
+ State->MaxVisible = UGAWidth / (ROW0_TILESIZE + TILE_XSPACING) - 1;
+ } else
+ State->MaxVisible = ConHeight - 4;
if ((VisibleSpace > 0) && (VisibleSpace < State->MaxVisible))
State->MaxVisible = (INTN)VisibleSpace;
State->PaintAll = TRUE;
State->LastVisible = State->FirstVisible + State->MaxVisible - 1;
}
+// Adjust variables relating to the scrolling of tags, for when a selected icon isn't
+// visible given the current scrolling condition....
+static VOID AdjustScrollState(IN SCROLL_STATE *State) {
+ if (State->CurrentSelection > State->LastVisible) {
+ State->LastVisible = State->CurrentSelection;
+ State->FirstVisible = 1 + State->CurrentSelection - State->MaxVisible;
+ if (State->FirstVisible < 0) // shouldn't happen, but just in case....
+ State->FirstVisible = 0;
+ State->PaintAll = TRUE;
+ } // Scroll forward
+ if (State->CurrentSelection < State->FirstVisible) {
+ State->FirstVisible = State->CurrentSelection;
+ State->LastVisible = State->CurrentSelection + State->MaxVisible - 1;
+ State->PaintAll = TRUE;
+ } // Scroll backward
+} // static VOID AdjustScrollState
+
static VOID UpdateScroll(IN OUT SCROLL_STATE *State, IN UINTN Movement)
{
- State->LastSelection = State->CurrentSelection;
-
+ State->PreviousSelection = State->CurrentSelection;
+
switch (Movement) {
- case SCROLL_LINE_UP:
+ case SCROLL_LINE_LEFT:
if (State->CurrentSelection > 0) {
State->CurrentSelection --;
}
break;
-
- case SCROLL_LINE_DOWN:
+
+ case SCROLL_LINE_RIGHT:
if (State->CurrentSelection < State->MaxIndex) {
State->CurrentSelection ++;
}
break;
- // TODO: Better handling of SCROLL_PAGE_UP & SCROLL_PAGE_DOWN
+ case SCROLL_LINE_UP:
+ if (State->ScrollMode == SCROLL_MODE_ICONS) {
+ if (State->CurrentSelection >= State->InitialRow1) {
+ if (State->MaxIndex > State->InitialRow1) { // avoid division by 0!
+ State->CurrentSelection = State->FirstVisible + (State->LastVisible - State->FirstVisible) *
+ (State->CurrentSelection - State->InitialRow1) /
+ (State->MaxIndex - State->InitialRow1);
+ } else {
+ State->CurrentSelection = State->FirstVisible;
+ } // if/else
+ } // if in second row
+ } else {
+ if (State->CurrentSelection > 0)
+ State->CurrentSelection--;
+ } // if/else
+ break;
+
+ case SCROLL_LINE_DOWN:
+ if (State->ScrollMode == SCROLL_MODE_ICONS) {
+ if (State->CurrentSelection <= State->FinalRow0) {
+ if (State->LastVisible > State->FirstVisible) { // avoid division by 0!
+ State->CurrentSelection = State->InitialRow1 + (State->MaxIndex - State->InitialRow1) *
+ (State->CurrentSelection - State->FirstVisible) /
+ (State->LastVisible - State->FirstVisible);
+ } else {
+ State->CurrentSelection = State->InitialRow1;
+ } // if/else
+ } // if in first row
+ } else {
+ if (State->CurrentSelection < State->MaxIndex)
+ State->CurrentSelection++;
+ } // if/else
+ break;
+
case SCROLL_PAGE_UP:
+ if (State->CurrentSelection <= State->FinalRow0)
+ State->CurrentSelection -= State->MaxVisible;
+ else if (State->CurrentSelection == State->InitialRow1)
+ State->CurrentSelection = State->FinalRow0;
+ else
+ State->CurrentSelection = State->InitialRow1;
+ if (State->CurrentSelection < 0)
+ State->CurrentSelection = 0;
+ break;
+
case SCROLL_FIRST:
if (State->CurrentSelection > 0) {
State->PaintAll = TRUE;
break;
case SCROLL_PAGE_DOWN:
+ if (State->CurrentSelection < State->FinalRow0) {
+ State->CurrentSelection += State->MaxVisible;
+ if (State->CurrentSelection > State->FinalRow0)
+ State->CurrentSelection = State->FinalRow0;
+ } else if (State->CurrentSelection == State->FinalRow0) {
+ State->CurrentSelection++;
+ } else {
+ State->CurrentSelection = State->MaxIndex;
+ }
+ if (State->CurrentSelection > State->MaxIndex)
+ State->CurrentSelection = State->MaxIndex;
+ break;
+
case SCROLL_LAST:
if (State->CurrentSelection < State->MaxIndex) {
State->PaintAll = TRUE;
case SCROLL_NONE:
break;
-
+
}
-
- if (!State->PaintAll && State->CurrentSelection != State->LastSelection)
+ if (State->ScrollMode == SCROLL_MODE_TEXT)
+ AdjustScrollState(State);
+
+ if (!State->PaintAll && State->CurrentSelection != State->PreviousSelection)
State->PaintSelection = TRUE;
State->LastVisible = State->FirstVisible + State->MaxVisible - 1;
-}
+} // static VOID UpdateScroll()
//
// menu helper functions
AddListElement((VOID ***) &(Screen->Entries), &(Screen->EntryCount), Entry);
}
-VOID FreeMenu(IN REFIT_MENU_SCREEN *Screen)
-{
- if (Screen->Entries)
- FreePool(Screen->Entries);
-}
static INTN FindMenuShortcutEntry(IN REFIT_MENU_SCREEN *Screen, IN CHAR16 *Shortcut)
{
Shortcut[0] -= ('a' - 'A');
if (Shortcut[0]) {
for (i = 0; i < Screen->EntryCount; i++) {
- if (Screen->Entries[i]->ShortcutDigit == Shortcut[0] ||
- Screen->Entries[i]->ShortcutLetter == Shortcut[0]) {
+ if (Screen->Entries[i]->ShortcutDigit == Shortcut[0] || Screen->Entries[i]->ShortcutLetter == Shortcut[0]) {
return i;
} // if
} // for
return -1;
}
+// Identify the end of row 0 and the beginning of row 1; store the results in the
+// appropriate fields in State. Also reduce MaxVisible if that value is greater
+// than the total number of row-0 tags and if we're in an icon-based screen
+static VOID IdentifyRows(IN SCROLL_STATE *State, IN REFIT_MENU_SCREEN *Screen) {
+ UINTN i;
+
+ State->FinalRow0 = 0;
+ State->InitialRow1 = State->MaxIndex;
+ for (i = 0; i < State->MaxIndex; i++) {
+ if (Screen->Entries[i]->Row == 0) {
+ State->FinalRow0 = i;
+ } else if ((Screen->Entries[i]->Row == 1) && (State->InitialRow1 > i)) {
+ State->InitialRow1 = i;
+ } // if/else
+ } // for
+ if ((State->ScrollMode == SCROLL_MODE_ICONS) && (State->MaxVisible > (State->FinalRow0 + 1)))
+ State->MaxVisible = State->FinalRow0 + 1;
+} // static VOID IdentifyRows()
+
//
// generic menu function
//
-
-static UINTN RunGenericMenu(IN REFIT_MENU_SCREEN *Screen, IN MENU_STYLE_FUNC StyleFunc, IN INTN DefaultEntryIndex, OUT REFIT_MENU_ENTRY **ChosenEntry)
+static UINTN RunGenericMenu(IN REFIT_MENU_SCREEN *Screen, IN MENU_STYLE_FUNC StyleFunc, IN OUT INTN *DefaultEntryIndex,
+ OUT REFIT_MENU_ENTRY **ChosenEntry)
{
SCROLL_STATE State;
EFI_STATUS Status;
INTN ShortcutEntry;
BOOLEAN HaveTimeout = FALSE;
UINTN TimeoutCountdown = 0;
- CHAR16 *TimeoutMessage;
+ CHAR16 TimeoutMessage[256];
CHAR16 KeyAsString[2];
UINTN MenuExit;
-
+
if (Screen->TimeoutSeconds > 0) {
HaveTimeout = TRUE;
TimeoutCountdown = Screen->TimeoutSeconds * 10;
MenuExit = 0;
StyleFunc(Screen, &State, MENU_FUNCTION_INIT, NULL);
+ IdentifyRows(&State, Screen);
// override the starting selection with the default index, if any
- if (DefaultEntryIndex >= 0 && DefaultEntryIndex <= State.MaxIndex) {
- State.CurrentSelection = DefaultEntryIndex;
+ if (*DefaultEntryIndex >= 0 && *DefaultEntryIndex <= State.MaxIndex) {
+ State.CurrentSelection = *DefaultEntryIndex;
UpdateScroll(&State, SCROLL_NONE);
}
-
+ State.PaintAll = TRUE;
+
while (!MenuExit) {
// update the screen
if (State.PaintAll) {
}
if (HaveTimeout) {
- TimeoutMessage = PoolPrint(L"%s in %d seconds", Screen->TimeoutText, (TimeoutCountdown + 5) / 10);
+ SPrint(TimeoutMessage, 255, L"%s in %d seconds", Screen->TimeoutText, (TimeoutCountdown + 5) / 10);
StyleFunc(Screen, &State, MENU_FUNCTION_PAINT_TIMEOUT, TimeoutMessage);
- FreePool(TimeoutMessage);
}
// read key press (and wait for it if applicable)
// react to key press
switch (key.ScanCode) {
case SCAN_UP:
- case SCAN_LEFT:
UpdateScroll(&State, SCROLL_LINE_UP);
break;
+ case SCAN_LEFT:
+ UpdateScroll(&State, SCROLL_LINE_LEFT);
+ break;
case SCAN_DOWN:
- case SCAN_RIGHT:
UpdateScroll(&State, SCROLL_LINE_DOWN);
break;
+ case SCAN_RIGHT:
+ UpdateScroll(&State, SCROLL_LINE_RIGHT);
+ break;
case SCAN_HOME:
UpdateScroll(&State, SCROLL_FIRST);
break;
case SCAN_F10:
egScreenShot();
break;
+ case 0x0016: // F12
+ if (EjectMedia())
+ MenuExit = MENU_EXIT_ESCAPE;
+ break;
}
switch (key.UnicodeChar) {
case CHAR_LINEFEED:
break;
}
}
-
+
StyleFunc(Screen, &State, MENU_FUNCTION_CLEANUP, NULL);
-
+
if (ChosenEntry)
*ChosenEntry = Screen->Entries[State.CurrentSelection];
+ *DefaultEntryIndex = State.CurrentSelection;
return MenuExit;
-} /* static UINTN RunGenericMenu( */
+} /* static UINTN RunGenericMenu() */
//
// text-mode generic style
UINTN MenuWidth, ItemWidth, MenuHeight;
static UINTN MenuPosY;
static CHAR16 **DisplayStrings;
- CHAR16 *TimeoutMessage;
-
+ CHAR16 TimeoutMessage[256];
+
+ State->ScrollMode = SCROLL_MODE_TEXT;
switch (Function) {
-
+
case MENU_FUNCTION_INIT:
// vertical layout
MenuPosY = 4;
if (Screen->InfoLineCount > 0)
MenuPosY += Screen->InfoLineCount + 1;
- MenuHeight = ConHeight - MenuPosY;
+ MenuHeight = ConHeight - MenuPosY - 3;
if (Screen->TimeoutSeconds > 0)
MenuHeight -= 2;
InitScroll(State, Screen->EntryCount, MenuHeight);
-
+
// determine width of the menu
MenuWidth = 20; // minimum
for (i = 0; i <= State->MaxIndex; i++) {
if (MenuWidth < ItemWidth)
MenuWidth = ItemWidth;
}
- if (MenuWidth > ConWidth - 6)
- MenuWidth = ConWidth - 6;
-
+ MenuWidth += 2;
+ if (MenuWidth > ConWidth - 3)
+ MenuWidth = ConWidth - 3;
+
// prepare strings for display
DisplayStrings = AllocatePool(sizeof(CHAR16 *) * Screen->EntryCount);
- for (i = 0; i <= State->MaxIndex; i++)
- DisplayStrings[i] = PoolPrint(L" %-.*s ", MenuWidth, Screen->Entries[i]->Title);
- // TODO: shorten strings that are too long (PoolPrint doesn't do that...)
- // TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
- // TODO: account for double-width characters
-
+ for (i = 0; i <= State->MaxIndex; i++) {
+ // Note: Theoretically, SPrint() is a cleaner way to do this; but the
+ // description of the StrSize parameter to SPrint implies it's measured
+ // in characters, but in practice both TianoCore and GNU-EFI seem to
+ // use bytes instead, resulting in truncated displays. I could just
+ // double the size of the StrSize parameter, but that seems unsafe in
+ // case a future library change starts treating this as characters, so
+ // I'm doing it the hard way in this instance.
+ // TODO: Review the above and possibly change other uses of SPrint()
+ DisplayStrings[i] = AllocateZeroPool(2 * sizeof(CHAR16));
+ DisplayStrings[i][0] = L' ';
+ MergeStrings(&DisplayStrings[i], Screen->Entries[i]->Title, 0);
+ if (StrLen(DisplayStrings[i]) > MenuWidth)
+ DisplayStrings[i][MenuWidth - 1] = 0;
+// DisplayStrings[i] = AllocateZeroPool(256 * sizeof(CHAR16));
+// SPrint(DisplayStrings[i], ((MenuWidth < 255) ? MenuWidth : 255) * sizeof(CHAR16),
+// L" %s ", Screen->Entries[i]->Title);
+ // TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
+ // TODO: account for double-width characters
+ } // for
+
// initial painting
BeginTextScreen(Screen->Title);
if (Screen->InfoLineCount > 0) {
refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, Screen->InfoLines[i]);
}
}
-
+
break;
-
+
case MENU_FUNCTION_CLEANUP:
// release temporary memory
for (i = 0; i <= State->MaxIndex; i++)
- FreePool(DisplayStrings[i]);
- FreePool(DisplayStrings);
+ MyFreePool(DisplayStrings[i]);
+ MyFreePool(DisplayStrings);
break;
-
+
case MENU_FUNCTION_PAINT_ALL:
// paint the whole screen (initially and after scrolling)
for (i = 0; i <= State->MaxIndex; i++) {
refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, ArrowDown);
else
refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, L" ");
+ if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
+ if (Screen->Hint1 != NULL) {
+ refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 2);
+ refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, Screen->Hint1);
+ }
+ if (Screen->Hint2 != NULL) {
+ refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 1);
+ refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, Screen->Hint2);
+ }
+ }
break;
-
+
case MENU_FUNCTION_PAINT_SELECTION:
// redraw selection cursor
- refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 2, MenuPosY + (State->LastSelection - State->FirstVisible));
+ refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 2,
+ MenuPosY + (State->PreviousSelection - State->FirstVisible));
refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_CHOICE_BASIC);
- refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, DisplayStrings[State->LastSelection]);
- refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 2, MenuPosY + (State->CurrentSelection - State->FirstVisible));
+ refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, DisplayStrings[State->PreviousSelection]);
+ refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 2,
+ MenuPosY + (State->CurrentSelection - State->FirstVisible));
refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_CHOICE_CURRENT);
refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, DisplayStrings[State->CurrentSelection]);
break;
-
+
case MENU_FUNCTION_PAINT_TIMEOUT:
if (ParamText[0] == 0) {
// clear message
refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_BASIC);
- refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 1);
+ refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 3);
refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, BlankLine + 1);
} else {
// paint or update message
refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_ERROR);
- refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 3, ConHeight - 1);
- TimeoutMessage = PoolPrint(L"%s ", ParamText);
+ refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 3, ConHeight - 3);
+ SPrint(TimeoutMessage, 255, L"%s ", ParamText);
refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, TimeoutMessage);
- FreePool(TimeoutMessage);
}
break;
static VOID DrawMenuText(IN CHAR16 *Text, IN UINTN SelectedWidth, IN UINTN XPos, IN UINTN YPos)
{
-// Print(L"Entering DrawMenuText(); Text is '%s', SelectedWidth is %d, XPos is %d, YPos is %d\n",
-// Text, SelectedWidth, XPos, YPos);
if (TextBuffer == NULL)
TextBuffer = egCreateImage(LAYOUT_TEXT_WIDTH, TEXT_LINE_HEIGHT, FALSE);
egFillImageArea(TextBuffer, 0, 0, SelectedWidth, TextBuffer->Height,
&SelectionBackgroundPixel);
}
-
+
// render the text
egRenderText(Text, TextBuffer, TEXT_XMARGIN, TEXT_YMARGIN);
BltImage(TextBuffer, XPos, YPos);
UINTN ItemWidth;
static UINTN MenuWidth, EntriesPosX, EntriesPosY, TimeoutPosY;
+ State->ScrollMode = SCROLL_MODE_TEXT;
switch (Function) {
-
+
case MENU_FUNCTION_INIT:
InitScroll(State, Screen->EntryCount, 0);
case MENU_FUNCTION_CLEANUP:
// nothing to do
break;
-
+
case MENU_FUNCTION_PAINT_ALL:
for (i = 0; i <= State->MaxIndex; i++) {
DrawMenuText(Screen->Entries[i]->Title, (i == State->CurrentSelection) ? MenuWidth : 0,
EntriesPosX, EntriesPosY + i * TEXT_LINE_HEIGHT);
}
+ if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
+ if ((Screen->Hint1 != NULL) && (StrLen(Screen->Hint1) > 0)) {
+ DrawMenuText(Screen->Hint1, 0, (UGAWidth - (StrLen(Screen->Hint1) * FONT_CELL_WIDTH)) / 2,
+ UGAHeight - (FONT_CELL_HEIGHT * 3));
+ }
+ if ((Screen->Hint2 != NULL) && (StrLen(Screen->Hint2) > 0)) {
+ DrawMenuText(Screen->Hint2, 0, (UGAWidth - (StrLen(Screen->Hint2) * FONT_CELL_WIDTH)) / 2,
+ UGAHeight - (FONT_CELL_HEIGHT * 2));
+ } // if
+ } // if
break;
-
+
case MENU_FUNCTION_PAINT_SELECTION:
// redraw selection cursor
- DrawMenuText(Screen->Entries[State->LastSelection]->Title, 0,
- EntriesPosX, EntriesPosY + State->LastSelection * TEXT_LINE_HEIGHT);
+ DrawMenuText(Screen->Entries[State->PreviousSelection]->Title, 0,
+ EntriesPosX, EntriesPosY + State->PreviousSelection * TEXT_LINE_HEIGHT);
DrawMenuText(Screen->Entries[State->CurrentSelection]->Title, MenuWidth,
EntriesPosX, EntriesPosY + State->CurrentSelection * TEXT_LINE_HEIGHT);
break;
-
+
case MENU_FUNCTION_PAINT_TIMEOUT:
DrawMenuText(ParamText, 0, EntriesPosX, TimeoutPosY);
break;
-
+
}
-}
+} // static VOID GraphicsMenuStyle()
//
// graphical main menu style
UINTN row0PosY, UINTN row1PosY, UINTN textPosY) {
INTN i;
- if (Screen->Entries[State->CurrentSelection]->Row == 0) {
- if (State->CurrentSelection > State->LastVisible) {
- State->LastVisible = State->CurrentSelection;
- State->FirstVisible = 1 + State->CurrentSelection - State->MaxVisible;
- if (State->FirstVisible < 0) // shouldn't happen, but just in case....
- State->FirstVisible = 0;
- } // Scroll forward
- if (State->CurrentSelection < State->FirstVisible) {
- State->FirstVisible = State->CurrentSelection;
- State->LastVisible = State->CurrentSelection + State->MaxVisible - 1;
- } // Scroll backward
- }
+ if (Screen->Entries[State->CurrentSelection]->Row == 0)
+ AdjustScrollState(State);
for (i = State->FirstVisible; i <= State->MaxIndex; i++) {
if (Screen->Entries[i]->Row == 0) {
if (i <= State->LastVisible) {
itemPosX[i - State->FirstVisible], row0PosY);
} // if
} else {
- DrawMainMenuEntry(Screen->Entries[i], (i == State->CurrentSelection) ? TRUE : FALSE,
- itemPosX[i], row1PosY);
+ DrawMainMenuEntry(Screen->Entries[i], (i == State->CurrentSelection) ? TRUE : FALSE, itemPosX[i], row1PosY);
}
}
if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
DrawMainMenuText(Screen->Entries[State->CurrentSelection]->Title,
(UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY);
+
+ if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
+ DrawMainMenuText(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
+ DrawMainMenuText(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
+ } // if
} // static VOID PaintAll()
// Move the selection to State->CurrentSelection, adjusting icon row if necessary...
static VOID PaintSelection(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN *itemPosX,
UINTN row0PosY, UINTN row1PosY, UINTN textPosY) {
- if ((State->CurrentSelection < State->LastVisible) && (State->CurrentSelection >= State->FirstVisible)) {
- DrawMainMenuEntry(Screen->Entries[State->LastSelection], FALSE,
- itemPosX[State->LastSelection - State->FirstVisible],
- (Screen->Entries[State->LastSelection]->Row == 0) ? row0PosY : row1PosY);
- DrawMainMenuEntry(Screen->Entries[State->CurrentSelection], TRUE,
- itemPosX[State->CurrentSelection - State->FirstVisible],
- (Screen->Entries[State->CurrentSelection]->Row == 0) ? row0PosY : row1PosY);
+ UINTN XSelectPrev, XSelectCur, YPosPrev, YPosCur;
+
+ if (((State->CurrentSelection <= State->LastVisible) && (State->CurrentSelection >= State->FirstVisible)) ||
+ (State->CurrentSelection >= State->InitialRow1) ) {
+ if (Screen->Entries[State->PreviousSelection]->Row == 0) {
+ XSelectPrev = State->PreviousSelection - State->FirstVisible;
+ YPosPrev = row0PosY;
+ } else {
+ XSelectPrev = State->PreviousSelection;
+ YPosPrev = row1PosY;
+ } // if/else
+ if (Screen->Entries[State->CurrentSelection]->Row == 0) {
+ XSelectCur = State->CurrentSelection - State->FirstVisible;
+ YPosCur = row0PosY;
+ } else {
+ XSelectCur = State->CurrentSelection;
+ YPosCur = row1PosY;
+ } // if/else
+ DrawMainMenuEntry(Screen->Entries[State->PreviousSelection], FALSE, itemPosX[XSelectPrev], YPosPrev);
+ DrawMainMenuEntry(Screen->Entries[State->CurrentSelection], TRUE, itemPosX[XSelectCur], YPosCur);
if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
DrawMainMenuText(Screen->Entries[State->CurrentSelection]->Title,
(UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY);
- } else {
+ } else { // Current selection not visible; must redraw the menu....
MainMenuStyle(Screen, State, MENU_FUNCTION_PAINT_ALL, NULL);
}
} // static VOID MoveSelection(VOID)
PosX -= Icon->Width;
BltImageAlpha(Icon, PosX, PosY - (Icon->Height / 2), &MenuBackgroundPixel);
}
-} // static VOID PaintArrow()
+} // static VOID PaintIcon()
// Display main menu in graphics mode
VOID MainMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINTN Function, IN CHAR16 *ParamText)
{
INTN i;
- extern UINTN row0PosX, row0PosXRunning, row1PosY, row0Loaders;
+ static UINTN row0PosX, row0PosXRunning, row1PosY, row0Loaders;
UINTN row0Count, row1Count, row1PosX, row1PosXRunning;
static UINTN *itemPosX;
static UINTN row0PosY, textPosY;
+ CHAR16 FileName[256];
+ State->ScrollMode = SCROLL_MODE_ICONS;
switch (Function) {
-
+
case MENU_FUNCTION_INIT:
InitScroll(State, Screen->EntryCount, GlobalConfig.MaxTags);
-
+
// layout
row0Count = 0;
row1Count = 0;
InitSelection();
SwitchToGraphicsAndClear();
break;
-
+
case MENU_FUNCTION_CLEANUP:
- FreePool(itemPosX);
+ MyFreePool(itemPosX);
break;
-
+
case MENU_FUNCTION_PAINT_ALL:
BltClearScreen(TRUE);
PaintAll(Screen, State, itemPosX, row0PosY, row1PosY, textPosY);
// For PaintIcon() calls, the starting Y position is moved to the midpoint
// of the surrounding row; PaintIcon() adjusts this back up by half the
// icon's height to properly center it.
- if (State->FirstVisible > 0)
- PaintIcon(&egemb_arrow_left, L"icons\\arrow_left.icns", row0PosX - TILE_XSPACING,
+ if ((State->FirstVisible > 0) && (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_ARROWS))) {
+ SPrint(FileName, 255, L"%s\\arrow_left.icns", GlobalConfig.IconsDir ? GlobalConfig.IconsDir : DEFAULT_ICONS_DIR);
+ PaintIcon(&egemb_arrow_left, FileName, row0PosX - TILE_XSPACING,
row0PosY + (ROW0_TILESIZE / 2), ALIGN_RIGHT);
- if (State->LastVisible < (row0Loaders - 1))
- PaintIcon(&egemb_arrow_right, L"icons\\arrow_right.icns",
+ } // if
+ if ((State->LastVisible < (row0Loaders - 1)) && (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_ARROWS))) {
+ SPrint(FileName, 255, L"%s\\arrow_right.icns", GlobalConfig.IconsDir ? GlobalConfig.IconsDir : DEFAULT_ICONS_DIR);
+ PaintIcon(&egemb_arrow_right, FileName,
(UGAWidth + (ROW0_TILESIZE + TILE_XSPACING) * State->MaxVisible) / 2 + TILE_XSPACING,
row0PosY + (ROW0_TILESIZE / 2), ALIGN_LEFT);
+ } // if
break;
case MENU_FUNCTION_PAINT_SELECTION:
PaintSelection(Screen, State, itemPosX, row0PosY, row1PosY, textPosY);
break;
-
+
case MENU_FUNCTION_PAINT_TIMEOUT:
if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
DrawMainMenuText(ParamText, (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY + TEXT_LINE_HEIGHT);
break;
-
+
}
-}
+} // VOID MainMenuStyle()
+
+// Enable the user to edit boot loader options.
+// Returns TRUE if the user exited with edited options; FALSE if the user
+// pressed Esc to terminate the edit.
+static BOOLEAN EditOptions(LOADER_ENTRY *MenuEntry) {
+ UINTN x_max, y_max;
+ CHAR16 *EditedOptions;
+ BOOLEAN retval = FALSE;
+
+ if (GlobalConfig.HideUIFlags & HIDEUI_FLAG_EDITOR) {
+ return FALSE;
+ }
+
+ refit_call4_wrapper(ST->ConOut->QueryMode, ST->ConOut, ST->ConOut->Mode->Mode, &x_max, &y_max);
+
+ if (!GlobalConfig.TextOnly)
+ SwitchToText(TRUE);
+
+ if (line_edit(MenuEntry->LoadOptions, &EditedOptions, x_max)) {
+ MyFreePool(MenuEntry->LoadOptions);
+ MenuEntry->LoadOptions = EditedOptions;
+ retval = TRUE;
+ } // if
+ if (!GlobalConfig.TextOnly)
+ SwitchToGraphics();
+ return retval;
+} // VOID EditOptions()
//
// user-callable dispatcher functions
UINTN RunMenu(IN REFIT_MENU_SCREEN *Screen, OUT REFIT_MENU_ENTRY **ChosenEntry)
{
+ INTN DefaultEntry = -1;
MENU_STYLE_FUNC Style = TextMenuStyle;
-
+
if (AllowGraphicsMode)
Style = GraphicsMenuStyle;
-
- return RunGenericMenu(Screen, Style, -1, ChosenEntry);
+
+ return RunGenericMenu(Screen, Style, &DefaultEntry, ChosenEntry);
}
UINTN RunMainMenu(IN REFIT_MENU_SCREEN *Screen, IN CHAR16* DefaultSelection, OUT REFIT_MENU_ENTRY **ChosenEntry)
MENU_STYLE_FUNC MainStyle = TextMenuStyle;
REFIT_MENU_ENTRY *TempChosenEntry;
UINTN MenuExit = 0;
- UINTN DefaultEntryIndex = -1;
+ INTN DefaultEntryIndex = -1;
+ INTN DefaultSubmenuIndex = -1;
if (DefaultSelection != NULL) {
- // Find a menu entry whose shortcut is the first character of DefaultSelection, or
- // whose
+ // Find a menu entry that includes *DefaultSelection as a substring
DefaultEntryIndex = FindMenuShortcutEntry(Screen, DefaultSelection);
- // If that didn't work, should we scan more characters? For now, no.
}
if (AllowGraphicsMode) {
}
while (!MenuExit) {
- MenuExit = RunGenericMenu(Screen, MainStyle, DefaultEntryIndex, &TempChosenEntry);
+ MenuExit = RunGenericMenu(Screen, MainStyle, &DefaultEntryIndex, &TempChosenEntry);
Screen->TimeoutSeconds = 0;
- if (MenuExit == MENU_EXIT_DETAILS && TempChosenEntry->SubScreen != NULL) {
- MenuExit = RunGenericMenu(TempChosenEntry->SubScreen, Style, -1, &TempChosenEntry);
- if (MenuExit == MENU_EXIT_ESCAPE || TempChosenEntry->Tag == TAG_RETURN)
- MenuExit = 0;
- }
+ if (MenuExit == MENU_EXIT_DETAILS) {
+ if (TempChosenEntry->SubScreen != NULL) {
+ MenuExit = RunGenericMenu(TempChosenEntry->SubScreen, Style, &DefaultSubmenuIndex, &TempChosenEntry);
+ if (MenuExit == MENU_EXIT_ESCAPE || TempChosenEntry->Tag == TAG_RETURN)
+ MenuExit = 0;
+ if (MenuExit == MENU_EXIT_DETAILS) {
+ if (!EditOptions((LOADER_ENTRY *) TempChosenEntry))
+ MenuExit = 0;
+ } // if
+ } else { // no sub-screen; ignore keypress
+ MenuExit = 0;
+ }
+ } // Enter sub-screen
}
if (ChosenEntry)