This commit is contained in:
Jief L 2020-03-31 18:59:42 +03:00
commit 0b19538bee
10 changed files with 92 additions and 52 deletions

View File

@ -135,13 +135,13 @@ typedef struct {
INTN CharWidth;
UINTN SelectionColor;
CHAR16 *FontFileName;
CHAR16 *Theme;
CHAR16 *BannerFileName;
CHAR16 *SelectionSmallFileName;
CHAR16 *SelectionBigFileName;
CHAR16 *SelectionIndicatorName;
CHAR16 *DefaultSelection;
#endif
CHAR16 *Theme;
CHAR16 *ScreenResolution;
INTN ConsoleMode;
BOOLEAN CustomIcons;
@ -209,13 +209,13 @@ REFIT_CONFIG GlobalConfig = {
9, // INTN CharWidth;
0xFFFFFF80, // UINTN SelectionColor;
NULL, // CHAR16 *FontFileName;
NULL, // CHAR16 *Theme;
NULL, // CHAR16 *BannerFileName;
NULL, // CHAR16 *SelectionSmallFileName;
NULL, // CHAR16 *SelectionBigFileName;
NULL, // CHAR16 *SelectionIndicatorName;
NULL, // CHAR16 *DefaultSelection;
#endif
NULL, // CHAR16 *Theme;
NULL, // CHAR16 *ScreenResolution;
0, // INTN ConsoleMode;
FALSE, // BOOLEAN CustomIcons;
@ -2971,11 +2971,12 @@ GetEarlyUserSettings (
if (Prop != NULL) {
if ((Prop->type == kTagTypeString) && Prop->string) {
ThemeX.Theme.takeValueFrom(Prop->string);
DBG ("Default theme: %ls\n", ThemeX.Theme.data());
GlobalConfig.Theme = PoolPrint (L"%a", Prop->string);
DBG ("Default theme: %ls\n", GlobalConfig.Theme);
OldChosenTheme = 0xFFFF; //default for embedded
for (UINTN i = 0; i < ThemesNum; i++) {
//now comparison is case sensitive
if (StriCmp(ThemeX.Theme.data(), ThemesList[i]) == 0) {
if (StriCmp(GlobalConfig.Theme, ThemesList[i]) == 0) {
OldChosenTheme = i;
break;
}
@ -3831,7 +3832,7 @@ XTheme::GetThemeTagSettings (void* DictP)
// if NULL parameter, quit after setting default values, this is embedded theme
if (DictPointer == NULL) {
if (DictP == NULL) {
return EFI_SUCCESS;
}
@ -4869,7 +4870,8 @@ InitTheme(BOOLEAN UseThemeDefinedInNVRam, EFI_TIME *Time)
// DBG("...done\n");
ThemeX.GetThemeTagSettings(NULL);
if (ThemesNum > 0) {
if (ThemesNum > 0 &&
(!GlobalConfig.Theme || StriCmp(GlobalConfig.Theme, L"embedded") != 0)) {
// Try special theme first
if (Time != NULL) {
if ((Time->Month == 12) && ((Time->Day >= 25) && (Time->Day <= 31))) {
@ -4882,7 +4884,12 @@ InitTheme(BOOLEAN UseThemeDefinedInNVRam, EFI_TIME *Time)
ThemeDict = LoadTheme (TestTheme);
if (ThemeDict != NULL) {
DBG ("special theme %ls found and %ls parsed\n", TestTheme, CONFIG_THEME_FILENAME);
ThemeX.Theme.takeValueFrom(TestTheme);
// ThemeX.Theme.takeValueFrom(TestTheme);
if (GlobalConfig.Theme) {
FreePool (GlobalConfig.Theme);
}
GlobalConfig.Theme = TestTheme;
} else { // special theme not loaded
DBG ("special theme %ls not found, skipping\n", TestTheme/*, CONFIG_THEME_FILENAME*/);
FreePool (TestTheme);
@ -4907,10 +4914,14 @@ InitTheme(BOOLEAN UseThemeDefinedInNVRam, EFI_TIME *Time)
ThemeDict = LoadTheme (TestTheme);
if (ThemeDict != NULL) {
DBG ("theme %s defined in NVRAM found and %ls parsed\n", ChosenTheme, CONFIG_THEME_FILENAME);
ThemeX.Theme.takeValueFrom(TestTheme);
// ThemeX.Theme.takeValueFrom(TestTheme);
if (GlobalConfig.Theme) {
FreePool (GlobalConfig.Theme);
}
GlobalConfig.Theme = TestTheme;
} else { // theme from nvram not loaded
if (!ThemeX.Theme.isEmpty()) {
DBG ("theme %s chosen from nvram is absent, using theme defined in config: %ls\n", ChosenTheme, ThemeX.Theme.data());
if (GlobalConfig.Theme) {
DBG ("theme %s chosen from nvram is absent, using theme defined in config: %ls\n", ChosenTheme, GlobalConfig.Theme);
} else {
DBG ("theme %s chosen from nvram is absent, get first theme\n", ChosenTheme);
}
@ -4924,19 +4935,23 @@ InitTheme(BOOLEAN UseThemeDefinedInNVRam, EFI_TIME *Time)
}
// Try to get theme from settings
if (ThemeDict == NULL) {
if (ThemeX.Theme.isEmpty()) {
if (!GlobalConfig.Theme) {
if (Time != NULL) {
DBG ("no default theme, get random theme %ls\n", ThemesList[Rnd]);
} else {
DBG ("no default theme, get first theme %ls\n", ThemesList[0]);
}
} else {
if (StriCmp(ThemeX.Theme.data(), L"random") == 0) {
ThemeDict = LoadTheme (ThemesList[Rnd]);
} else {
ThemeDict = LoadTheme (ThemeX.Theme.data());
DBG ("no default theme, get first theme %ls\n", ThemesList[0]);
ThemeDict = LoadTheme (ThemesList[0]);
}
} else {
if (StriCmp(GlobalConfig.Theme, L"random") == 0) {
ThemeDict = LoadTheme (ThemesList[Rnd]);
} else {
ThemeDict = LoadTheme (GlobalConfig.Theme);
if (ThemeDict == NULL) {
DBG ("GlobalConfig: %ls not found, get embedded theme\n", ThemeX.Theme.data());
DBG ("GlobalConfig: %ls not found, get embedded theme\n", GlobalConfig.Theme);
} else {
DBG("chosen theme %ls\n", GlobalConfig.Theme);
}
}
}
@ -4958,12 +4973,14 @@ finish:
ThemeDir = NULL;
}
ThemeX.GetThemeTagSettings(NULL);
// ThemeX.GetThemeTagSettings(NULL); already done
//fill some fields
ThemeX.Font = FONT_ALFA; //to be inverted later. At start we have FONT_GRAY
ThemeX.embedded = true;
Status = StartupSoundPlay(ThemeDir, NULL);
} else { // theme loaded successfully
ThemeX.embedded = false;
ThemeX.Theme.takeValueFrom(GlobalConfig.Theme);
// read theme settings
if (!ThemeX.TypeSVG) {
TagPtr DictPointer = GetProperty(ThemeDict, "Theme");
@ -5001,10 +5018,7 @@ finish:
#else
EFI_STATUS
InitTheme(
BOOLEAN UseThemeDefinedInNVRam,
EFI_TIME *Time
)
InitTheme(BOOLEAN UseThemeDefinedInNVRam, EFI_TIME *Time)
{
EFI_STATUS Status = EFI_NOT_FOUND;
UINTN Size = 0;
@ -7325,7 +7339,8 @@ GetUserSettings(
if (DictPointer != NULL) {
Prop = GetProperty (DictPointer, "Theme");
if ((Prop != NULL) && (Prop->type == kTagTypeString) && Prop->string) {
ThemeX.Theme.takeValueFrom(Prop->string);
// ThemeX.Theme.takeValueFrom(Prop->string);
GlobalConfig.Theme = PoolPrint (L"%a", Prop->string);
DBG ("Theme from new config: %ls\n", ThemeX.Theme.data());
}
}

View File

@ -438,7 +438,7 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer)
}
float ScaleF = UGAHeight / SVGimage->height;
DBG("using scale %f\n", ScaleF);
/*ThemeX.*/ Scale = ScaleF;
Scale = ScaleF;
CentreShift = (vbx * Scale - (float)UGAWidth) * 0.5f;
if (mainParser->font) {
@ -456,7 +456,7 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer)
if (EFI_ERROR(Status)) {
Status = ParseSVGXIcon(mainParser, BUILTIN_ICON_BACKGROUND, "Background"_XS, Scale, &BigBack);
}
DBG(" Background parsed\n");
DBG(" Background parsed [%lld, %lld]\n", BigBack.GetWidth(), BigBack.GetHeight());
// --- Make Banner
Banner.setEmpty(); //for the case of theme switch
Status = EFI_NOT_FOUND;
@ -479,7 +479,7 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer)
Icon NewIcon(i); //initialize with embedded but further replace by loaded
ParseSVGXIcon(mainParser, i, NewIcon.Name, Scale, &NewIcon.Image);
ParseSVGXIcon(mainParser, i, NewIcon.Name + "_night", Scale, &NewIcon.ImageNight);
ThemeX.Icons.AddCopy(NewIcon);
Icons.AddCopy(NewIcon);
}

View File

@ -506,10 +506,10 @@ void XImage::Draw(INTN x, INTN y, float scale, bool Opaque)
XImage Top(*this, scale); //can accept 0 as scale
XImage Background(Width, Height);
Background.GetArea(x, y, Width, Height);
Background.Compose(0, 0, Top, Opaque);
UINTN AreaWidth = (x + Width > (UINTN)UGAWidth) ? (UGAWidth - x) : Width;
UINTN AreaHeight = (y + Height > (UINTN)UGAHeight) ? (UGAHeight - y) : Height;
Background.GetArea(x, y, AreaWidth, AreaHeight); //it will resize the Background image
Background.Compose(0, 0, Top, Opaque);
// prepare protocols
EFI_STATUS Status;
@ -529,11 +529,11 @@ void XImage::Draw(INTN x, INTN y, float scale, bool Opaque)
if (GraphicsOutput != NULL) {
GraphicsOutput->Blt(GraphicsOutput, Background.GetPixelPtr(0, 0),
EfiBltBufferToVideo,
0, 0, x, y, AreaWidth, AreaHeight, GetWidth()*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
0, 0, x, y, AreaWidth, AreaHeight, AreaWidth*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
}
else if (UgaDraw != NULL) {
UgaDraw->Blt(UgaDraw, (EFI_UGA_PIXEL *)Background.GetPixelPtr(0, 0), EfiUgaBltBufferToVideo,
0, 0, x, y, AreaWidth, AreaHeight, GetWidth()*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
0, 0, x, y, AreaWidth, AreaHeight, AreaWidth*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
}
}

View File

@ -116,7 +116,11 @@ VOID XPointer::Draw()
oldPlace = newPlace;
// CopyMem(&oldPlace, &newPlace, sizeof(EG_RECT)); //can we use oldPlace = newPlace; ?
// take background image for later to restore background
oldImage.GetArea(newPlace);
newPlace.Width = PointerImage->GetWidth();
newPlace.Height = PointerImage->GetHeight();
oldImage.GetArea(newPlace); //GetArea will resize oldImage, so correct newPlace
newPlace.Width = oldImage.GetWidth();
newPlace.Height = oldImage.GetHeight();
PointerImage->Draw(newPlace.XPos, newPlace.YPos); //zero means no scale
}

View File

@ -13,6 +13,18 @@ extern "C" {
#if USE_XTHEME
#ifndef DEBUG_ALL
#define DEBUG_XTHEME 1
#else
#define DEBUG_XTHEME DEBUG_ALL
#endif
#if DEBUG_XTHEME == 0
#define DBG(...)
#else
#define DBG(...) DebugLog(DEBUG_XTHEME, __VA_ARGS__)
#endif
//temporary
extern INTN ScrollWidth;
@ -340,6 +352,7 @@ void XTheme::ClearScreen() //and restore background and banner
if (BanHeight < 2) {
BanHeight = ((UGAHeight - (int)(LayoutHeight * Scale)) >> 1);
}
egClearScreen(&DarkBackgroundPixel);
if (!(HideUIFlags & HIDEUI_FLAG_BANNER)) {
//Banner image prepared before
if (!Banner.isEmpty()) {
@ -384,6 +397,7 @@ void XTheme::ClearScreen() //and restore background and banner
if (!BigBack.isEmpty()) {
switch (BackgroundScale) {
case imScale:
DBG("back copy scaled\n");
Background.CopyScaled(BigBack, Scale);
break;
case imCrop:
@ -410,10 +424,12 @@ void XTheme::ClearScreen() //and restore background and banner
y = UGAHeight;
}
//the function can be in XImage class
/* egRawCopy(Background.GetPixelPtr(x1, y1),
BigBack.GetPixelPtr(x2, y2),
x, y, Background.GetWidth(), BigBack.GetWidth()); */
Background.Compose(x, y, BigBack, true);
egRawCopy((EG_PIXEL*)Background.GetPixelPtr(x1, y1),
(EG_PIXEL*)BigBack.GetPixelPtr(x2, y2),
x, y, Background.GetWidth(), BigBack.GetWidth());
// DBG("crop to x,y: %lld, %lld\n", x, y);
// Background.CopyRect(BigBack, x, y);
DBG("back copy cropped\n");
break;
}
case imTile:
@ -426,15 +442,19 @@ void XTheme::ClearScreen() //and restore background and banner
*p1++ = BigBack.GetPixel((i + x) % BigBack.GetWidth(), (j + y) % BigBack.GetHeight());
}
}
DBG("back copy tiled\n");
break;
}
case imNone:
default:
// already scaled
Background = BigBack;
DBG("back copy equal\n");
break;
}
}
Background.Draw(0, 0);
// Background.DrawWithoutCompose(0, 0, UGAWidth, UGAHeight);
Background.Draw(0,0,0,false);
//then draw banner
if (!Banner.isEmpty()) {
Banner.Draw(BannerPlace.XPos, BannerPlace.YPos, Scale);

View File

@ -686,7 +686,7 @@ VOID egFillImageArea(IN OUT EG_IMAGE *CompImage,
}
//will be replaced by
// TmpBuffer.CopyRect(Background, XPos, YPos);
// CompBase.CopyRect(TopBase, XPos, YPos);
VOID egRawCopy(IN OUT EG_PIXEL *CompBasePtr, IN EG_PIXEL *TopBasePtr,
IN INTN Width, IN INTN Height,

View File

@ -328,13 +328,13 @@ typedef struct {
INTN CharWidth;
UINTN SelectionColor;
CHAR16 *FontFileName;
CHAR16 *Theme;
CHAR16 *BannerFileName;
CHAR16 *SelectionSmallFileName;
CHAR16 *SelectionBigFileName;
CHAR16 *SelectionIndicatorName;
CHAR16 *DefaultSelection;
#endif
CHAR16 *Theme;
CHAR16 *ScreenResolution;
INTN ConsoleMode;
BOOLEAN CustomIcons;

View File

@ -2255,12 +2255,13 @@ RefitMain (IN EFI_HANDLE ImageHandle,
GetListOfConfigs();
}
#if USE_XTHEME
ThemeX.FillByEmbedded(); //init XTheme before EarlyUserSettings
#endif
for (i=0; i<2; i++) {
if (gConfigDict[i]) {
/* Status = */GetEarlyUserSettings(SelfRootDir, gConfigDict[i]);
// if (EFI_ERROR(Status)) {
// DBG("Error in Early settings%d: %s\n", i, strerror(Status));
// }
GetEarlyUserSettings(SelfRootDir, gConfigDict[i]);
}
}
@ -2273,9 +2274,6 @@ RefitMain (IN EFI_HANDLE ImageHandle,
#endif // ENABLE_SECURE_BOOT
MainMenu.TimeoutSeconds = GlobalConfig.Timeout >= 0 ? GlobalConfig.Timeout : 0;
#if USE_XTHEME
ThemeX.FillByEmbedded();
#endif
//DBG("LoadDrivers() start\n");
LoadDrivers();
//DBG("LoadDrivers() end\n");

View File

@ -3773,11 +3773,11 @@ VOID REFIT_MENU_SCREEN::GraphicsMenuStyle(IN UINTN Function, IN CONST CHAR16 *Pa
case MENU_FUNCTION_PAINT_ALL:
// DrawMenuText(NULL, 0, 0, 0, 0); //should clean every line to avoid artefacts
// DBG("PAINT_ALL: EntriesPosY=%d MaxVisible=%d\n", EntriesPosY, ScrollState.MaxVisible);
// DBG("DownButton.Height=%d TextHeight=%d\n", DownButton.Height, TextHeight);
DBG("PAINT_ALL: EntriesPosY=%lld MaxVisible=%lld\n", EntriesPosY, ScrollState.MaxVisible);
DBG("DownButton.Height=%lld TextHeight=%lld\n", DownButton.Height, TextHeight);
t2 = EntriesPosY + (ScrollState.MaxVisible + 1) * TextHeight - DownButton.Height;
t1 = EntriesPosX + TextHeight + MenuWidth + (INTN)((TEXT_XMARGIN + 16) * ThemeX.Scale);
// DBG("PAINT_ALL: %d %d\n", t1, t2);
DBG("PAINT_ALL: %lld %lld\n", t1, t2);
SetBar(t1, EntriesPosY, t2, &ScrollState); //823 302 554
// blackosx swapped this around so drawing of selection comes before drawing scrollbar.
@ -4536,7 +4536,7 @@ VOID XTheme::FillRectAreaOfScreen(IN INTN XPos, IN INTN YPos, IN INTN Width, IN
// TmpBuffer.CopyScaled(Background, 1.f);
INTN X = XPos - (Width >> 1); //X_IS_CENTRE
TmpBuffer.CopyRect(Background, X, YPos);
TmpBuffer.Draw(X, YPos);
TmpBuffer.DrawWithoutCompose(X, YPos);
}
#else
VOID FillRectAreaOfScreen(IN INTN XPos, IN INTN YPos, IN INTN Width, IN INTN Height, IN EG_PIXEL *Color, IN UINT8 XAlign)
@ -6873,9 +6873,11 @@ UINTN REFIT_MENU_SCREEN::RunMainMenu(IN INTN DefaultSelection, OUT REFIT_ABSTRAC
gSettings.OptionsBits = EncodeOptions(TmpArgs);
// DBG("main OptionsBits = 0x%X\n", gSettings.OptionsBits);
if ( MainChosenEntry->getLOADER_ENTRY() ) gSettings.OptionsBits |= EncodeOptions(MainChosenEntry->getLOADER_ENTRY()->LoadOptions);
if (MainChosenEntry->getLOADER_ENTRY())
gSettings.OptionsBits |= EncodeOptions(MainChosenEntry->getLOADER_ENTRY()->LoadOptions);
// DBG("add OptionsBits = 0x%X\n", gSettings.OptionsBits);
if ( MainChosenEntry->getREFIT_MENU_ITEM_BOOTNUM() ) DecodeOptions(MainChosenEntry->getREFIT_MENU_ITEM_BOOTNUM());
if (MainChosenEntry->getREFIT_MENU_ITEM_BOOTNUM())
DecodeOptions(MainChosenEntry->getREFIT_MENU_ITEM_BOOTNUM());
// DBG(" enter menu with LoadOptions: %ls\n", ((LOADER_ENTRY*)MainChosenEntry)->LoadOptions);
if (MainChosenEntry->getLOADER_ENTRY()) {
// Only for non-legacy entries, as LEGACY_ENTRY doesn't have Flags

View File

@ -334,6 +334,7 @@ VOID SwitchToGraphicsAndClear(VOID) //called from MENU_FUNCTION_INIT
{
SwitchToGraphics();
#if USE_XTHEME
DBG("clear screen and draw back\n");
ThemeX.ClearScreen();
#else
if (GraphicsScreenDirty) { //Invented in rEFIt 15 years ago