- if (TextBuffer == NULL)
- TextBuffer = egCreateImage(LAYOUT_TEXT_WIDTH, TEXT_LINE_HEIGHT, FALSE);
-
- egFillImage(TextBuffer, &MenuBackgroundPixel);
- if (SelectedWidth > 0) {
- // draw selection bar background
- egFillImageArea(TextBuffer, 0, 0, SelectedWidth, TextBuffer->Height,
- &SelectionBackgroundPixel);
+ EG_IMAGE *TextBuffer;
+ EG_PIXEL Bg;
+
+ TextBuffer = egCreateImage(FieldWidth, TextLineHeight(), FALSE);
+
+ egFillImage(TextBuffer, &MenuBackgroundPixel);
+ Bg = MenuBackgroundPixel;
+ if (Selected) {
+ // draw selection bar background
+ egFillImageArea(TextBuffer, 0, 0, FieldWidth, TextBuffer->Height, &SelectionBackgroundPixel);
+ Bg = SelectionBackgroundPixel;
+ }
+
+ // render the text
+ egRenderText(Text, TextBuffer, egGetFontCellWidth(), TEXT_YMARGIN, (Bg.r + Bg.g + Bg.b) / 3);
+ egDrawImageWithTransparency(TextBuffer, NULL, XPos, YPos, TextBuffer->Width, TextBuffer->Height);
+// BltImage(TextBuffer, XPos, YPos);
+}
+
+// Finds the average brightness of the input Image.
+// NOTE: Passing an Image that covers the whole screen can strain the
+// capacity of a UINTN on a 32-bit system with a very large display.
+// Using UINT64 instead is unworkable, since the code won't compile
+// on a 32-bit system. As the intended use for this function is to handle
+// a single text string's background, this shouldn't be a problem, but it
+// may need addressing if it's applied more broadly....
+static UINT8 AverageBrightness(EG_IMAGE *Image) {
+ UINTN i;
+ UINTN Sum = 0;
+
+ if (Image != NULL) {
+ for (i = 0; i < (Image->Width * Image->Height); i++) {
+ Sum += (Image->PixelData[i].r + Image->PixelData[i].g + Image->PixelData[i].b);
+ }
+ } // if
+ return (UINT8) (Sum / (Image->Width * Image->Height * 3));
+} // UINT8 AverageBrightness()
+
+// Display text against the screen's background image. Special case: If Text is NULL
+// or 0-length, clear the line. Does NOT indent the text or reposition it relative
+// to the specified XPos and YPos values.
+static VOID DrawTextWithTransparency(IN CHAR16 *Text, IN UINTN XPos, IN UINTN YPos)
+{
+ UINTN TextWidth;
+ EG_IMAGE *TextBuffer = NULL;
+
+ if (Text == NULL)
+ Text = L"";
+
+ egMeasureText(Text, &TextWidth, NULL);
+ if (TextWidth == 0) {
+ TextWidth = UGAWidth;
+ XPos = 0;
+ }
+
+ TextBuffer = egCropImage(GlobalConfig.ScreenBackground, XPos, YPos, TextWidth, TextLineHeight());
+ if (TextBuffer == NULL) {
+ Print(L"Error: NULL TextBuffer in DrawTextWithTransparency()\n");
+ return;