+// Compute the size & position of the window that will hold a subscreen's information.
+static VOID ComputeSubScreenWindowSize(REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN *XPos, UINTN *YPos,
+ UINTN *Width, UINTN *Height, UINTN *LineWidth) {
+ UINTN i, ItemWidth, HintTop, BannerBottomEdge, TitleWidth;
+ UINTN FontCellWidth = egGetFontCellWidth();
+ UINTN FontCellHeight = egGetFontHeight();
+
+ *Width = 20;
+ *Height = 5;
+ TitleWidth = egComputeTextWidth(Screen->Title);
+
+ for (i = 0; i < Screen->InfoLineCount; i++) {
+ ItemWidth = StrLen(Screen->InfoLines[i]);
+ if (*Width < ItemWidth) {
+ *Width = ItemWidth;
+ }
+ (*Height)++;
+ }
+ for (i = 0; i <= State->MaxIndex; i++) {
+ ItemWidth = StrLen(Screen->Entries[i]->Title);
+ if (*Width < ItemWidth) {
+ *Width = ItemWidth;
+ }
+ (*Height)++;
+ }
+ *Width = (*Width + 2) * FontCellWidth;
+ *LineWidth = *Width;
+ if (Screen->TitleImage)
+ *Width += (Screen->TitleImage->Width + TITLEICON_SPACING * 2 + FontCellWidth);
+ else
+ *Width += FontCellWidth;
+
+ if (*Width < TitleWidth)
+ *Width = TitleWidth + 2 * FontCellWidth;
+
+ // Keep it within the bounds of the screen, or 2/3 of the screen's width
+ // for screens over 800 pixels wide
+ if (*Width > UGAWidth)
+ *Width = UGAWidth;
+
+ *XPos = (UGAWidth - *Width) / 2;
+
+ HintTop = UGAHeight - (FontCellHeight * 3); // top of hint text
+ *Height *= TextLineHeight();
+ if (Screen->TitleImage && (*Height < (Screen->TitleImage->Height + TextLineHeight() * 4)))
+ *Height = Screen->TitleImage->Height + TextLineHeight() * 4;
+
+ if (GlobalConfig.BannerBottomEdge >= HintTop) { // probably a full-screen image; treat it as an empty banner
+ BannerBottomEdge = 0;
+ } else {
+ BannerBottomEdge = GlobalConfig.BannerBottomEdge;
+ }
+ if (*Height > (HintTop - BannerBottomEdge - FontCellHeight * 2)) {
+ BannerBottomEdge = 0;
+ }
+ if (*Height > (HintTop - BannerBottomEdge - FontCellHeight * 2)) {
+ // TODO: Implement scrolling in text screen.
+ *Height = (HintTop - BannerBottomEdge - FontCellHeight * 2);
+ }
+
+ *YPos = ((UGAHeight - *Height) / 2);
+ if (*YPos < BannerBottomEdge)
+ *YPos = BannerBottomEdge + FontCellHeight + (HintTop - BannerBottomEdge - *Height) / 2;
+} // VOID ComputeSubScreenWindowSize()
+