+// 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;
+
+ *Width = 20;
+ *Height = 5;
+ TitleWidth = StrLen(Screen->Title);
+ if ((Screen->TitleImage) && (TitleWidth > (Screen->TitleImage->Width / FONT_CELL_WIDTH))) {
+ TitleWidth -= (Screen->TitleImage->Width / FONT_CELL_WIDTH);
+ }
+ if (TitleWidth > *Width) {
+ *Width = TitleWidth;
+ }
+ 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 = TEXT_XMARGIN * 2 + *Width * FONT_CELL_WIDTH;
+ *LineWidth = *Width;
+ if (Screen->TitleImage)
+ *Width += (Screen->TitleImage->Width + TITLEICON_SPACING * 2 + FONT_CELL_WIDTH);
+ else
+ *Width += FONT_CELL_WIDTH;
+
+ // 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;
+ if ((*Width > (2 * UGAWidth) / 3) && (UGAWidth > 800))
+ *Width = (2 * UGAWidth) / 3;
+
+ *XPos = (UGAWidth - *Width) / 2;
+
+ HintTop = UGAHeight - (FONT_CELL_HEIGHT * 3); // top of hint text
+ *Height *= TEXT_LINE_HEIGHT;
+ if (Screen->TitleImage && (*Height < (Screen->TitleImage->Height + TEXT_LINE_HEIGHT * 4)))
+ *Height = Screen->TitleImage->Height + TEXT_LINE_HEIGHT * 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 - FONT_CELL_HEIGHT * 2)) {
+ BannerBottomEdge = 0;
+ }
+ if (*Height > (HintTop - BannerBottomEdge - FONT_CELL_HEIGHT * 2)) {
+ // TODO: Implement scrolling in text screen.
+ *Height = (HintTop - BannerBottomEdge - FONT_CELL_HEIGHT * 2);
+ }
+
+ *YPos = ((UGAHeight - *Height) / 2);
+ if (*YPos < BannerBottomEdge)
+ *YPos = BannerBottomEdge + FONT_CELL_HEIGHT + (HintTop - BannerBottomEdge - *Height) / 2;
+} // VOID ComputeSubScreenWindowSize()
+