]> code.delx.au - refind/blobdiff - refind/screen.c
Improved submenu and information menu appearance over a full-screen
[refind] / refind / screen.c
index 32711d60e43df1ef466db8d4e01e0f13770f5a3a..7ee1a1878692156da790ec5e4929010fa54f8994 100644 (file)
@@ -47,6 +47,7 @@
 #include "config.h"
 #include "libegint.h"
 #include "lib.h"
+#include "menu.h"
 #include "../include/refit_call_wrapper.h"
 
 #include "../include/egemb_refind_banner.h"
@@ -100,6 +101,7 @@ VOID InitScreen(VOID)
         AllowGraphicsMode = TRUE;
     } else {
         AllowGraphicsMode = FALSE;
+        egSetTextMode(GlobalConfig.RequestedTextMode);
         egSetGraphicsModeEnabled(FALSE);   // just to be sure we are in text mode
     }
     GraphicsScreenDirty = TRUE;
@@ -116,18 +118,45 @@ VOID InitScreen(VOID)
 
     PrepareBlankLine();
 
-    // show the banner (even when in graphics mode)
-    DrawScreenHeader(L"Initializing...");
+    // show the banner if in text mode
+    if (GlobalConfig.TextOnly)
+       DrawScreenHeader(L"Initializing...");
 }
 
+// Set the screen resolution and mode (text vs. graphics).
 VOID SetupScreen(VOID)
 {
-    GlobalConfig.RequestedTextMode = egSetTextMode(GlobalConfig.RequestedTextMode);
+    UINTN NewWidth, NewHeight;
+
+    // Convert mode number to horizontal & vertical resolution values
+    if ((GlobalConfig.RequestedScreenWidth > 0) && (GlobalConfig.RequestedScreenHeight == 0))
+       egGetResFromMode(&(GlobalConfig.RequestedScreenWidth), &(GlobalConfig.RequestedScreenHeight));
+
+    // Set the believed-to-be current resolution to the LOWER of the current
+    // believed-to-be resolution and the requested resolution. This is done to
+    // enable setting a lower-than-default resolution.
+    if ((GlobalConfig.RequestedScreenWidth > 0) && (GlobalConfig.RequestedScreenHeight > 0)) {
+       UGAWidth = (UGAWidth < GlobalConfig.RequestedScreenWidth) ? UGAWidth : GlobalConfig.RequestedScreenWidth;
+       UGAHeight = (UGAHeight < GlobalConfig.RequestedScreenHeight) ? UGAHeight : GlobalConfig.RequestedScreenHeight;
+    }
+
+    // Set text mode. If this requires increasing the size of the graphics mode, do so.
+    if (egSetTextMode(GlobalConfig.RequestedTextMode)) {
+       egGetScreenSize(&NewWidth, &NewHeight);
+       if ((NewWidth > UGAWidth) || (NewHeight > UGAHeight)) {
+          UGAWidth = NewWidth;
+          UGAHeight = NewHeight;
+       }
+       if ((UGAWidth > GlobalConfig.RequestedScreenWidth) || (UGAHeight > GlobalConfig.RequestedScreenHeight)) {
+           // Requested text mode forces us to use a bigger graphics mode
+           GlobalConfig.RequestedScreenWidth = UGAWidth;
+           GlobalConfig.RequestedScreenHeight = UGAHeight;
+       } // if
+    }
 
-    if ((GlobalConfig.RequestedScreenWidth > 0) &&
-        (egSetScreenSize(&GlobalConfig.RequestedScreenWidth, &GlobalConfig.RequestedScreenHeight))) {
-          UGAWidth = GlobalConfig.RequestedScreenWidth;
-          UGAHeight = GlobalConfig.RequestedScreenHeight;
+    if (GlobalConfig.RequestedScreenWidth > 0) {
+       egSetScreenSize(&(GlobalConfig.RequestedScreenWidth), &(GlobalConfig.RequestedScreenHeight));
+       egGetScreenSize(&UGAWidth, &UGAHeight);
     } // if user requested a particular screen resolution
 
     if (GlobalConfig.TextOnly) {
@@ -141,7 +170,7 @@ VOID SetupScreen(VOID)
         SwitchToGraphics();
         BltClearScreen(TRUE);
     }
-}
+} // VOID SetupScreen()
 
 VOID SwitchToText(IN BOOLEAN CursorEnabled)
 {
@@ -197,12 +226,10 @@ VOID BeginExternalScreen(IN BOOLEAN UseGraphicsMode, IN CHAR16 *Title)
         SwitchToGraphics();
         BltClearScreen(FALSE);
     } else {
-       egClearScreen(&DarkBackgroundPixel);
-       DrawScreenHeader(Title);
-    } // if/else
-
-    if (!UseGraphicsMode)
+        egClearScreen(&DarkBackgroundPixel);
+        DrawScreenHeader(Title);
         SwitchToText(TRUE);
+    }
 
     // reset error flag
     haveError = FALSE;
@@ -408,24 +435,40 @@ VOID SwitchToGraphicsAndClear(VOID)
 
 VOID BltClearScreen(IN BOOLEAN ShowBanner)
 {
-    static EG_IMAGE *Banner = NULL;
+    static EG_IMAGE *Banner = NULL, *CroppedBanner;
+    INTN BannerPosX, BannerPosY;
 
     if (ShowBanner && !(GlobalConfig.HideUIFlags & HIDEUI_FLAG_BANNER)) {
         // load banner on first call
         if (Banner == NULL) {
-            if (GlobalConfig.BannerFileName == NULL)
+            if (GlobalConfig.BannerFileName == NULL) {
                 Banner = egPrepareEmbeddedImage(&egemb_refind_banner, FALSE);
-            else
+            } else {
                 Banner = egLoadImage(SelfDir, GlobalConfig.BannerFileName, FALSE);
+                if (Banner && ((Banner->Width > UGAWidth) || (Banner->Height > UGAHeight))) {
+                   CroppedBanner = egCropImage(Banner, 0, 0, (Banner->Width > UGAWidth) ? UGAWidth : Banner->Width,
+                                               (Banner->Height > UGAHeight) ? UGAHeight : Banner->Height);
+                   MyFreePool(Banner);
+                   Banner = CroppedBanner;
+                } // if image too big
+                if (Banner == NULL) {
+                   Banner = egPrepareEmbeddedImage(&egemb_refind_banner, FALSE);
+                } // if unusable image
+            }
             if (Banner != NULL)
-                MenuBackgroundPixel = Banner->PixelData[0];
+               MenuBackgroundPixel = Banner->PixelData[0];
         }
 
         // clear and draw banner
         egClearScreen(&MenuBackgroundPixel);
-        if (Banner != NULL)
-            BltImage(Banner, (UGAWidth - Banner->Width) >> 1,
-                     ((UGAHeight - LAYOUT_TOTAL_HEIGHT) >> 1) + LAYOUT_BANNER_HEIGHT - Banner->Height);
+        if (Banner != NULL) {
+            BannerPosX = (Banner->Width < UGAWidth) ? ((UGAWidth - Banner->Width) / 2) : 0;
+            BannerPosY = (ComputeRow0PosX() / 2) - Banner->Height;
+            if (BannerPosY < 0)
+               BannerPosY = 0;
+            GlobalConfig.BannerBottomEdge = BannerPosY + Banner->Height;
+            BltImage(Banner, (UINTN) BannerPosX, (UINTN) BannerPosY);
+        }
 
     } else {
         // clear to standard background color
@@ -433,6 +476,8 @@ VOID BltClearScreen(IN BOOLEAN ShowBanner)
     }
 
     GraphicsScreenDirty = FALSE;
+    egFreeImage(GlobalConfig.ScreenBackground);
+    GlobalConfig.ScreenBackground = egCopyScreen();
 }
 
 VOID BltImage(IN EG_IMAGE *Image, IN UINTN XPos, IN UINTN YPos)
@@ -515,7 +560,10 @@ VOID BltImageCompositeBadge(IN EG_IMAGE *BaseImage, IN EG_IMAGE *TopImage, IN EG
      }
 
      // blit to screen and clean up
-     egDrawImage(CompImage, XPos, YPos);
+     if (CompImage->HasAlpha)
+        egDrawImageWithTransparency(CompImage, NULL, XPos, YPos, CompImage->Width, CompImage->Height);
+     else
+        egDrawImage(CompImage, XPos, YPos);
      egFreeImage(CompImage);
      GraphicsScreenDirty = TRUE;
 }