]> code.delx.au - refind/commitdiff
Improved key bindings, particularly in graphics mode.
authorsrs5694 <srs5694@users.sourceforge.net>
Sun, 6 May 2012 23:54:40 +0000 (19:54 -0400)
committersrs5694 <srs5694@users.sourceforge.net>
Sun, 6 May 2012 23:54:40 +0000 (19:54 -0400)
NEWS.txt
docs/refind/todo.html
refind/main.c
refind/menu.c
refind/menu.h

index 73e7f33a2a7c728e146ef231156452a2adf53a46..4a91f8cb9942deca55ff022fc69c164cbf1153f6 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,6 +1,14 @@
 0.3.3 (?/?/2012):
 -----------------
 
+- Improved menu navigation:
+  - In graphics mode, left & right arrow keys move left & right, while up &
+    down arrows move between rows.
+  - Page Up and Page Down now move through chunks of visible tags (in both
+    text & graphics modes), jumping from one row to another only when at
+    the edge of the row. In text mode, the "rows" are broken down as in
+    graphics mode, but they aren't visibly distinguished on the screen.
+
 - Improved text-mode use: Now displays the proper number of entries when
   first started and scrolling is done sensibly when too many entries exist
   to fit on the screen.
index ed55cc4f1d30b4480dce6b18bfaa7e9b3a764462..fbf250c2633f5786f7a94be66583b9ddc743083f 100644 (file)
@@ -137,10 +137,6 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
     just an example of the inflexibility of certain layout issues within
     rEFInd.</li>
 
-<li>Text mode has a known display glitch: Not all loaders are shown until
-    you use the cursor keys to move down the list, effectively "drawing"
-    the "invisible" tags. This obviously needs to be fixed.</li>
-
 <li>Although the ICNS file format used by rEFInd supports multiple image
     sizes, if a size that rEFInd needs isn't present in the file, rEFInd
     can't use the icon. The ability to scale images to the desired size
index 8ea0fc5d746d60e88660c889cc117536bf212c74..3fd7df7fcb9e2ebd9f6b1455fb97067351b5ea79 100644 (file)
@@ -104,7 +104,7 @@ static VOID AboutrEFInd(VOID)
 {
     if (AboutMenu.EntryCount == 0) {
         AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
-        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.3.2.1");
+        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.3.2.2");
         AddMenuInfoLine(&AboutMenu, L"");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith");
index d2d5c38557f89cb61e7484f88eb0a309dd0d88f9..3ff16b1804cefb1c5a25a9c234bab7a73ab3ffc2 100644 (file)
@@ -163,12 +163,12 @@ static VOID InitSelection(VOID)
 
 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;
-    if (AllowGraphicsMode)
+    if (AllowGraphicsMode) {
        State->MaxVisible = UGAWidth / (ROW0_TILESIZE + TILE_XSPACING) - 1;
-    else
+    else
        State->MaxVisible = ConHeight - 4;
     if ((VisibleSpace > 0) && (VisibleSpace < State->MaxVisible))
         State->MaxVisible = (INTN)VisibleSpace;
@@ -197,23 +197,66 @@ static VOID AdjustScrollState(/* IN REFIT_MENU_SCREEN *Screen, */ IN SCROLL_STAT
 
 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;
@@ -222,6 +265,19 @@ static VOID UpdateScroll(IN OUT SCROLL_STATE *State, IN UINTN Movement)
            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;
@@ -233,10 +289,10 @@ static VOID UpdateScroll(IN OUT SCROLL_STATE *State, IN UINTN Movement)
             break;
 
     }
-    if (!AllowGraphicsMode)
+    if (State->ScrollMode == SCROLL_MODE_TEXT)
        AdjustScrollState(State);
 
-    if (!State->PaintAll && State->CurrentSelection != State->LastSelection)
+    if (!State->PaintAll && State->CurrentSelection != State->PreviousSelection)
         State->PaintSelection = TRUE;
     State->LastVisible = State->FirstVisible + State->MaxVisible - 1;
 }
@@ -287,10 +343,28 @@ static INTN FindMenuShortcutEntry(IN REFIT_MENU_SCREEN *Screen, IN CHAR16 *Short
     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)
 {
     SCROLL_STATE State;
@@ -311,6 +385,7 @@ static UINTN RunGenericMenu(IN REFIT_MENU_SCREEN *Screen, IN MENU_STYLE_FUNC Sty
     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;
@@ -356,13 +431,17 @@ static UINTN RunGenericMenu(IN REFIT_MENU_SCREEN *Screen, IN MENU_STYLE_FUNC Sty
         // 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;
@@ -426,6 +505,7 @@ static VOID TextMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State,
     static CHAR16 **DisplayStrings;
     CHAR16 *TimeoutMessage;
 
+    State->ScrollMode = SCROLL_MODE_TEXT;
     switch (Function) {
 
         case MENU_FUNCTION_INIT:
@@ -503,9 +583,9 @@ static VOID TextMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State,
 
         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_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]);
@@ -537,8 +617,6 @@ static VOID TextMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State,
 
 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);
 
@@ -561,6 +639,7 @@ static VOID GraphicsMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *Sta
     UINTN ItemWidth;
     static UINTN MenuWidth, EntriesPosX, EntriesPosY, TimeoutPosY;
 
+    State->ScrollMode = SCROLL_MODE_TEXT;
     switch (Function) {
 
         case MENU_FUNCTION_INIT:
@@ -620,8 +699,8 @@ static VOID GraphicsMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *Sta
 
         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;
@@ -675,11 +754,14 @@ static VOID PaintAll(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN
       AdjustScrollState(State);
    for (i = State->FirstVisible; i <= State->MaxIndex; i++) {
       if (Screen->Entries[i]->Row == 0) {
+         State->FinalRow0 = i;
          if (i <= State->LastVisible) {
             DrawMainMenuEntry(Screen->Entries[i], (i == State->CurrentSelection) ? TRUE : FALSE,
                               itemPosX[i - State->FirstVisible], row0PosY);
          } // if
       } else {
+         if (State->InitialRow1 > i)
+            State->InitialRow1 = i;
          DrawMainMenuEntry(Screen->Entries[i], (i == State->CurrentSelection) ? TRUE : FALSE,
                            itemPosX[i], row1PosY);
       }
@@ -693,9 +775,9 @@ static VOID PaintAll(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN
 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->PreviousSelection], FALSE,
+                        itemPosX[State->PreviousSelection - State->FirstVisible],
+                        (Screen->Entries[State->PreviousSelection]->Row == 0) ? row0PosY : row1PosY);
       DrawMainMenuEntry(Screen->Entries[State->CurrentSelection], TRUE,
                         itemPosX[State->CurrentSelection - State->FirstVisible],
                         (Screen->Entries[State->CurrentSelection]->Row == 0) ? row0PosY : row1PosY);
@@ -736,6 +818,7 @@ VOID MainMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINT
     static UINTN *itemPosX;
     static UINTN row0PosY, textPosY;
 
+    State->ScrollMode = SCROLL_MODE_ICONS;
     switch (Function) {
 
         case MENU_FUNCTION_INIT:
index b0cb5148cd7374d27b61ad358a24cdcaa56450b9..be906a9af0a4cdcb83e74f6ad85ee76ba3d2ff5d 100644 (file)
 // scrolling definitions
 
 typedef struct {
-   INTN CurrentSelection, LastSelection, MaxIndex;
+   INTN CurrentSelection, PreviousSelection, MaxIndex;
    INTN FirstVisible, LastVisible, MaxVisible;
+   INTN FinalRow0, InitialRow1;
+   INTN ScrollMode;
    BOOLEAN PaintAll, PaintSelection;
 } SCROLL_STATE;
 
@@ -76,6 +78,11 @@ typedef struct {
 #define SCROLL_FIRST      (4)
 #define SCROLL_LAST       (5)
 #define SCROLL_NONE       (6)
+#define SCROLL_LINE_RIGHT (7)
+#define SCROLL_LINE_LEFT  (8)
+
+#define SCROLL_MODE_TEXT  (0) /* Used in text mode & for GUI submenus */
+#define SCROLL_MODE_ICONS (1) /* Used for main GUI menu */
 
 struct _refit_menu_screen;