From ec097428f9fb581bb0842bb840b5713e176dd0f4 Mon Sep 17 00:00:00 2001 From: srs5694 Date: Wed, 19 Dec 2012 00:43:37 -0500 Subject: [PATCH] Refinement to hint function for greater context sensitivity. --- NEWS.txt | 10 ++++++---- libeg/screen.c | 8 ++++++++ libeg/text.c | 6 +++++- refind/global.h | 6 ++++-- refind/lib.c | 8 ++++---- refind/lib.h | 4 ++-- refind/main.c | 31 +++++++++++++++++++++++++++++-- refind/menu.c | 44 +++++++++++++++++++++++--------------------- refind/screen.c | 8 ++++++++ 9 files changed, 89 insertions(+), 36 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index 5561a43..534c400 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,11 +1,13 @@ 0.6.1 (12/??/2012): ------------------- +- Refined hints displays to be more context-sensitive, particularly in text + mode. + - Instead of displaying a blank filesystem label when a filesystem has - none, rEFInd now displays the size of the filesystem, as in "boot - EFI\foo\bar.efi from 200 MiB volume" rather than "boot EFI\foo\bar.efi - from". For some filesystems, the filesystem type is included, as in "boot - EFI\foo\bar.efi from 200 MiB ext3 volume". + none, rEFInd now displays the size and/or type of the filesystem, as in + "boot EFI\foo\bar.efi from 200 MiB ext3 volume" rather than "boot + EFI\foo\bar.efi from". - Fixed a bug that caused the screen to clear after displaying an error message but before displaying the "Hit any key to continue" message when diff --git a/libeg/screen.c b/libeg/screen.c index 8200438..bac1f00 100644 --- a/libeg/screen.c +++ b/libeg/screen.c @@ -33,6 +33,14 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* + * 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 "libegint.h" #include "../refind/screen.h" diff --git a/libeg/text.c b/libeg/text.c index d84eeb7..93551b2 100644 --- a/libeg/text.c +++ b/libeg/text.c @@ -64,7 +64,11 @@ VOID egRenderText(IN CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN UINTN PosX, IN UINTN i, c; // clip the text - TextLength = StrLen(Text); + if (Text) + TextLength = StrLen(Text); + else + TextLength = 0; + if (TextLength * FONT_CELL_WIDTH + PosX > CompImage->Width) TextLength = (CompImage->Width - PosX) / FONT_CELL_WIDTH; diff --git a/refind/global.h b/refind/global.h index 1d4a184..511dcac 100644 --- a/refind/global.h +++ b/refind/global.h @@ -35,11 +35,11 @@ */ /* * 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. - * + * */ #ifndef __GLOBAL_H_ @@ -182,6 +182,8 @@ typedef struct _refit_menu_screen { REFIT_MENU_ENTRY **Entries; UINTN TimeoutSeconds; CHAR16 *TimeoutText; + CHAR16 *Hint1; + CHAR16 *Hint2; } REFIT_MENU_SCREEN; typedef struct { diff --git a/refind/lib.c b/refind/lib.c index 048b301..347a176 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -680,7 +680,7 @@ static CHAR16 *GetVolumeName(IN REFIT_VOLUME *Volume) { CHAR16 *SISize, *TypeName; FileSystemInfoPtr = LibFileSystemInfo(Volume->RootDir); - if (FileSystemInfoPtr != NULL) { + if (FileSystemInfoPtr != NULL) { // we have filesystem information (size, label).... if ((FileSystemInfoPtr->VolumeLabel != NULL) && (StrLen(FileSystemInfoPtr->VolumeLabel) > 0)) { FoundName = StrDuplicate(FileSystemInfoPtr->VolumeLabel); } @@ -692,7 +692,7 @@ static CHAR16 *GetVolumeName(IN REFIT_VOLUME *Volume) { FoundName = NULL; } // if rEFInd HFS+ driver suspected - if (FoundName == NULL) { // filesystem has no name.... + if (FoundName == NULL) { // filesystem has no name, so use fs type and size FoundName = AllocateZeroPool(sizeof(CHAR16) * 256); if (FoundName != NULL) { SISize = SizeInIEEEUnits(FileSystemInfoPtr->VolumeSize); @@ -703,10 +703,10 @@ static CHAR16 *GetVolumeName(IN REFIT_VOLUME *Volume) { FreePool(FileSystemInfoPtr); - } else { + } else { // fs driver not returning info; fall back on our own information.... FoundName = AllocateZeroPool(sizeof(CHAR16) * 256); if (FoundName != NULL) { - TypeName = FSTypeName(Volume->FSType); // NOTE: Don't free TypeName; fn returns constant + TypeName = FSTypeName(Volume->FSType); // NOTE: Don't free TypeName; function returns constant if (StrLen(TypeName) > 0) SPrint(FoundName, 255, L"%s volume", FSTypeName(Volume->FSType)); else diff --git a/refind/lib.h b/refind/lib.h index 7245191..4e936a8 100644 --- a/refind/lib.h +++ b/refind/lib.h @@ -35,11 +35,11 @@ */ /* * 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. - * + * */ #ifndef __LIB_H_ diff --git a/refind/main.c b/refind/main.c index 011489b..15b8771 100644 --- a/refind/main.c +++ b/refind/main.c @@ -87,14 +87,21 @@ // a ".efi" extension to be found when scanning for boot loaders. #define LINUX_MATCH_PATTERNS L"vmlinuz*,bzImage*" +// Default hint text +#define SUBSCREEN_HINT1 L"Use arrow keys to move cursor; Enter to boot;" +#define SUBSCREEN_HINT2 L"Insert or F2 to edit options; Esc to return to main menu" +#define SUBSCREEN_HINT2_NO_EDITOR L"Esc to return to main menu" + static REFIT_MENU_ENTRY MenuEntryAbout = { L"About rEFInd", TAG_ABOUT, 1, 0, 'A', NULL, NULL, NULL }; static REFIT_MENU_ENTRY MenuEntryReset = { L"Reboot Computer", TAG_REBOOT, 1, 0, 'R', NULL, NULL, NULL }; static REFIT_MENU_ENTRY MenuEntryShutdown = { L"Shut Down Computer", TAG_SHUTDOWN, 1, 0, 'U', NULL, NULL, NULL }; static REFIT_MENU_ENTRY MenuEntryReturn = { L"Return to Main Menu", TAG_RETURN, 0, 0, 0, NULL, NULL, NULL }; static REFIT_MENU_ENTRY MenuEntryExit = { L"Exit rEFInd", TAG_EXIT, 1, 0, 0, NULL, NULL, NULL }; -static REFIT_MENU_SCREEN MainMenu = { L"Main Menu", NULL, 0, NULL, 0, NULL, 0, L"Automatic boot" }; -static REFIT_MENU_SCREEN AboutMenu = { L"About", NULL, 0, NULL, 0, NULL, 0, NULL }; +static REFIT_MENU_SCREEN MainMenu = { L"Main Menu", NULL, 0, NULL, 0, NULL, 0, L"Automatic boot", + L"Use arrow keys to move cursor; Enter to boot;", + L"Insert or F2 for more options; Esc to refresh" }; +static REFIT_MENU_SCREEN AboutMenu = { L"About", NULL, 0, NULL, 0, NULL, 0, NULL, L"Press Enter to return to main menu", L"" }; REFIT_CONFIG GlobalConfig = { FALSE, FALSE, 0, 0, 0, 20, 0, 0, GRAPHICS_FOR_OSX, LEGACY_TYPE_MAC, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @@ -395,6 +402,8 @@ static REFIT_MENU_SCREEN* CopyMenuScreen(REFIT_MENU_SCREEN *Entry) { for (i = 0; i < Entry->EntryCount && NewEntry->Entries; i++) { AddMenuEntry(NewEntry, Entry->Entries[i]); } // for + NewEntry->Hint1 = (Entry->Hint1) ? StrDuplicate(Entry->Hint1) : NULL; + NewEntry->Hint2 = (Entry->Hint2) ? StrDuplicate(Entry->Hint2) : NULL; } // if return (NewEntry); } // static REFIT_MENU_SCREEN* CopyMenuScreen() @@ -501,6 +510,12 @@ REFIT_MENU_SCREEN *InitializeSubScreen(IN LOADER_ENTRY *Entry) { MyFreePool(MainOptions); AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry); } // if (SubEntry != NULL) + SubScreen->Hint1 = StrDuplicate(SUBSCREEN_HINT1); + if (GlobalConfig.HideUIFlags & HIDEUI_FLAG_EDITOR) { + SubScreen->Hint2 = StrDuplicate(SUBSCREEN_HINT2_NO_EDITOR); + } else { + SubScreen->Hint2 = StrDuplicate(SUBSCREEN_HINT2); + } // if/else } // if (SubScreen != NULL) } else { // existing subscreen; less initialization, and just add new entry later.... SubScreen = Entry->me.SubScreen; @@ -1270,6 +1285,12 @@ static LEGACY_ENTRY * AddLegacyEntry(IN CHAR16 *LoaderTitle, IN REFIT_VOLUME *Vo SubScreen->Title = AllocateZeroPool(256 * sizeof(CHAR16)); SPrint(SubScreen->Title, 255, L"Boot Options for %s on %s", LoaderTitle, VolDesc); SubScreen->TitleImage = Entry->me.Image; + SubScreen->Hint1 = StrDuplicate(SUBSCREEN_HINT1); + if (GlobalConfig.HideUIFlags & HIDEUI_FLAG_EDITOR) { + SubScreen->Hint2 = StrDuplicate(SUBSCREEN_HINT2_NO_EDITOR); + } else { + SubScreen->Hint2 = StrDuplicate(SUBSCREEN_HINT2); + } // if/else // default entry SubEntry = AllocateZeroPool(sizeof(LEGACY_ENTRY)); @@ -1338,6 +1359,12 @@ static LEGACY_ENTRY * AddLegacyEntryUEFI(BDS_COMMON_OPTION *BdsOption, IN UINT16 SubScreen->Title = AllocateZeroPool(256 * sizeof(CHAR16)); SPrint(SubScreen->Title, 255, L"No boot options for legacy target"); SubScreen->TitleImage = Entry->me.Image; + SubScreen->Hint1 = StrDuplicate(SUBSCREEN_HINT1); + if (GlobalConfig.HideUIFlags & HIDEUI_FLAG_EDITOR) { + SubScreen->Hint2 = StrDuplicate(SUBSCREEN_HINT2_NO_EDITOR); + } else { + SubScreen->Hint2 = StrDuplicate(SUBSCREEN_HINT2); + } // if/else // default entry SubEntry = AllocateZeroPool(sizeof(LEGACY_ENTRY)); diff --git a/refind/menu.c b/refind/menu.c index ec54eb1..7de9d8b 100644 --- a/refind/menu.c +++ b/refind/menu.c @@ -35,11 +35,11 @@ */ /* * 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" @@ -512,7 +512,7 @@ static VOID TextMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, MenuPosY = 4; if (Screen->InfoLineCount > 0) MenuPosY += Screen->InfoLineCount + 1; - MenuHeight = ConHeight - MenuPosY - 2; + MenuHeight = ConHeight - MenuPosY - 3; if (Screen->TimeoutSeconds > 0) MenuHeight -= 2; InitScroll(State, Screen->EntryCount, MenuHeight); @@ -595,9 +595,14 @@ static VOID TextMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, else refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, L" "); if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) { - refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 1); - refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, - L"Use arrow keys to move cursor; Enter to boot; Insert or F2 for more options"); + 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; @@ -617,12 +622,12 @@ static VOID TextMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, 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 - 2); + 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 - 2); + 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); } @@ -717,15 +722,14 @@ static VOID GraphicsMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *Sta EntriesPosX, EntriesPosY + i * TEXT_LINE_HEIGHT); } if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) { - if (GlobalConfig.HideUIFlags & HIDEUI_FLAG_EDITOR) { - DrawMenuText(L"Use arrow keys to move cursor; Enter to boot", 0, - (UGAWidth - (45 * FONT_CELL_WIDTH)) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3)); - } else { - DrawMenuText(L"Use arrow keys to move cursor; Enter to boot;", 0, - (UGAWidth - (45 * FONT_CELL_WIDTH)) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3)); - DrawMenuText(L"Insert or F2 to edit options; Esc to return to main menu", 0, - (UGAWidth - (56 * FONT_CELL_WIDTH)) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2)); - } // if/else + 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; @@ -799,10 +803,8 @@ static VOID PaintAll(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY); if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) { - DrawMainMenuText(L"Use arrow keys to move cursor; Enter to boot;", - (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3)); - DrawMainMenuText(L"Insert or F2 for more options; Esc to refresh", - (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2)); + 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() diff --git a/refind/screen.c b/refind/screen.c index 7f485a4..32711d6 100644 --- a/refind/screen.c +++ b/refind/screen.c @@ -33,6 +33,14 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* + * 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 "screen.h" -- 2.39.2