#define FONT_CELL_WIDTH (7)
#define FONT_CELL_HEIGHT (12)
-static EG_IMAGE *FontImage = NULL;
+static EG_IMAGE *BlackFontImage = NULL;
+static EG_IMAGE *WhiteFontImage = NULL;
//
// Text rendering
*Height = FONT_CELL_HEIGHT;
}
-VOID egRenderText(IN CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN UINTN PosX, IN UINTN PosY)
+VOID egRenderText(IN CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN UINTN PosX, IN UINTN PosY, IN UINT8 BGBrightness)
{
+ EG_IMAGE *FontImage;
EG_PIXEL *BufferPtr;
EG_PIXEL *FontPixelData;
UINTN BufferLineOffset, FontLineOffset;
if (TextLength * FONT_CELL_WIDTH + PosX > CompImage->Width)
TextLength = (CompImage->Width - PosX) / FONT_CELL_WIDTH;
- // load the font
- if (FontImage == NULL)
- FontImage = egPrepareEmbeddedImage(&egemb_font, TRUE);
+ if (BGBrightness < 128) {
+ if (WhiteFontImage == NULL) {
+ WhiteFontImage = egPrepareEmbeddedImage(&egemb_font, TRUE);
+ if (WhiteFontImage == NULL)
+ return;
+ for (i = 0; i < (WhiteFontImage->Width * WhiteFontImage->Height); i++) {
+ WhiteFontImage->PixelData[i].r = 255 - WhiteFontImage->PixelData[i].r;
+ WhiteFontImage->PixelData[i].g = 255 - WhiteFontImage->PixelData[i].g;
+ WhiteFontImage->PixelData[i].b = 255 - WhiteFontImage->PixelData[i].b;
+// WhiteFontImage->PixelData[i].a = 255 - WhiteFontImage->PixelData[i].a;
+ } // for
+ } // if
+ FontImage = WhiteFontImage;
+ } else {
+ if (BlackFontImage == NULL)
+ BlackFontImage = egPrepareEmbeddedImage(&egemb_font, TRUE);
+ if (BlackFontImage == NULL)
+ return;
+ FontImage = BlackFontImage;
+ } // if/else
+
+// // load the font
+// if (FontImage == NULL) {
+// FontImage = egPrepareEmbeddedImage(&egemb_font, TRUE);
+// } // if font not yet loaded.
// render it
BufferPtr = CompImage->PixelData;
// Display a submenu
-static VOID DrawSubmenuText(IN CHAR16 *Text, IN BOOLEAN Selected, IN UINTN FieldWidth, IN UINTN XPos, IN UINTN YPos)
+static VOID DrawText(IN CHAR16 *Text, IN BOOLEAN Selected, IN UINTN FieldWidth, IN UINTN XPos, IN UINTN YPos)
{
-// UINTN TextWidth = TEXT_XMARGIN * 2 + StrLen(Text) * FONT_CELL_WIDTH;
EG_IMAGE *TextBuffer;
+ EG_PIXEL Bg;
TextBuffer = egCreateImage(FieldWidth, TEXT_LINE_HEIGHT, 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, TEXT_XMARGIN, TEXT_YMARGIN);
+ egRenderText(Text, TextBuffer, TEXT_XMARGIN, TEXT_YMARGIN, (Bg.r + Bg.g + Bg.b) / 3);
egDrawImageWithTransparency(TextBuffer, NULL, XPos, YPos, TextBuffer->Width, TextBuffer->Height);
// BltImage(TextBuffer, XPos, YPos);
}
-static VOID DrawMainMenuText(IN CHAR16 *Text, IN UINTN XPos, IN UINTN 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.
+// 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()
+
+static VOID DrawTextWithTransparency(IN CHAR16 *Text, IN UINTN XPos, IN UINTN YPos)
{
UINTN TextWidth, TextPosX;
EG_IMAGE *TextBuffer;
TextPosX = 0;
else
TextPosX = (TextBuffer->Width - TextWidth) / 2;
- egRenderText(Text, TextBuffer, TextPosX, 0);
+ egRenderText(Text, TextBuffer, TextPosX, 0, AverageBrightness(TextBuffer));
egDrawImageWithTransparency(TextBuffer, NULL, XPos, YPos, TextBuffer->Width, TextBuffer->Height);
}
Window = egCreateFilledImage(MenuWidth, MenuHeight, FALSE, BackgroundPixel);
egDrawImage(Window, EntriesPosX, EntriesPosY);
egMeasureText(Screen->Title, &ItemWidth, NULL);
- DrawSubmenuText(Screen->Title, FALSE, (StrLen(Screen->Title) + 2) * FONT_CELL_WIDTH,
- EntriesPosX + (MenuWidth - ItemWidth) / 2, EntriesPosY += TEXT_LINE_HEIGHT);
+ DrawText(Screen->Title, FALSE, (StrLen(Screen->Title) + 2) * FONT_CELL_WIDTH,
+ EntriesPosX + (MenuWidth - ItemWidth) / 2, EntriesPosY += TEXT_LINE_HEIGHT);
if (Screen->TitleImage) {
BltImageAlpha(Screen->TitleImage, EntriesPosX, EntriesPosY + TEXT_LINE_HEIGHT * 2, BackgroundPixel);
EntriesPosX += (Screen->TitleImage->Width + TITLEICON_SPACING);
EntriesPosY += (TEXT_LINE_HEIGHT * 2);
if (Screen->InfoLineCount > 0) {
for (i = 0; i < (INTN)Screen->InfoLineCount; i++) {
- DrawSubmenuText(Screen->InfoLines[i], FALSE, LineWidth, EntriesPosX, EntriesPosY);
+ DrawText(Screen->InfoLines[i], FALSE, LineWidth, EntriesPosX, EntriesPosY);
EntriesPosY += TEXT_LINE_HEIGHT;
}
EntriesPosY += TEXT_LINE_HEIGHT; // also add a blank line
case MENU_FUNCTION_PAINT_ALL:
for (i = 0; i <= State->MaxIndex; i++) {
- DrawSubmenuText(Screen->Entries[i]->Title, (i == State->CurrentSelection), LineWidth,
- EntriesPosX, EntriesPosY + i * TEXT_LINE_HEIGHT);
+ DrawText(Screen->Entries[i]->Title, (i == State->CurrentSelection), LineWidth, EntriesPosX,
+ EntriesPosY + i * TEXT_LINE_HEIGHT);
}
if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
if ((Screen->Hint1 != NULL) && (StrLen(Screen->Hint1) > 0))
- DrawMainMenuText(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
+ DrawTextWithTransparency(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
if ((Screen->Hint2 != NULL) && (StrLen(Screen->Hint2) > 0))
- DrawMainMenuText(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
+ DrawTextWithTransparency(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
} // if
break;
case MENU_FUNCTION_PAINT_SELECTION:
// redraw selection cursor
- DrawSubmenuText(Screen->Entries[State->PreviousSelection]->Title, FALSE, LineWidth,
- EntriesPosX, EntriesPosY + State->PreviousSelection * TEXT_LINE_HEIGHT);
- DrawSubmenuText(Screen->Entries[State->CurrentSelection]->Title, TRUE, LineWidth,
- EntriesPosX, EntriesPosY + State->CurrentSelection * TEXT_LINE_HEIGHT);
+ DrawText(Screen->Entries[State->PreviousSelection]->Title, FALSE, LineWidth,
+ EntriesPosX, EntriesPosY + State->PreviousSelection * TEXT_LINE_HEIGHT);
+ DrawText(Screen->Entries[State->CurrentSelection]->Title, TRUE, LineWidth,
+ EntriesPosX, EntriesPosY + State->CurrentSelection * TEXT_LINE_HEIGHT);
break;
case MENU_FUNCTION_PAINT_TIMEOUT:
- DrawSubmenuText(ParamText, FALSE, LineWidth, EntriesPosX, TimeoutPosY);
+ DrawText(ParamText, FALSE, LineWidth, EntriesPosX, TimeoutPosY);
break;
}
}
}
if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
- DrawMainMenuText(Screen->Entries[State->CurrentSelection]->Title,
+ DrawTextWithTransparency(Screen->Entries[State->CurrentSelection]->Title,
(UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY);
if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
- DrawMainMenuText(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
- DrawMainMenuText(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
+ DrawTextWithTransparency(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
+ DrawTextWithTransparency(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
} // if
} // static VOID PaintAll()
DrawMainMenuEntry(Screen->Entries[State->PreviousSelection], FALSE, itemPosX[XSelectPrev], YPosPrev);
DrawMainMenuEntry(Screen->Entries[State->CurrentSelection], TRUE, itemPosX[XSelectCur], YPosCur);
if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
- DrawMainMenuText(Screen->Entries[State->CurrentSelection]->Title,
+ DrawTextWithTransparency(Screen->Entries[State->CurrentSelection]->Title,
(UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY);
} else { // Current selection not visible; must redraw the menu....
MainMenuStyle(Screen, State, MENU_FUNCTION_PAINT_ALL, NULL);
case MENU_FUNCTION_PAINT_TIMEOUT:
if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
- DrawMainMenuText(ParamText, (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY + TEXT_LINE_HEIGHT);
+ DrawTextWithTransparency(ParamText, (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY + TEXT_LINE_HEIGHT);
break;
}