From f7254f53e6bece94f2a066a258817cbd653df335 Mon Sep 17 00:00:00 2001 From: Sergey Isakov Date: Mon, 30 Mar 2020 11:34:16 +0300 Subject: [PATCH] load icons as in xtheme Signed-off-by: Sergey Isakov --- Xcode/Clover/Clover.xcodeproj/project.pbxproj | 2 - rEFIt_UEFI/Platform/Settings.cpp | 4 +- rEFIt_UEFI/entry_scan/common.cpp | 29 +++++++ rEFIt_UEFI/entry_scan/legacy.cpp | 14 +++- rEFIt_UEFI/entry_scan/loader.cpp | 30 ++++++- rEFIt_UEFI/entry_scan/securemenu.cpp | 9 ++ rEFIt_UEFI/entry_scan/tool.cpp | 41 +++++++-- rEFIt_UEFI/libeg/XImage.cpp | 5 +- rEFIt_UEFI/libeg/XPointer.cpp | 8 ++ rEFIt_UEFI/refit/icns.cpp | 5 -- rEFIt_UEFI/refit/lib.h | 10 ++- rEFIt_UEFI/refit/main.cpp | 21 +++-- rEFIt_UEFI/refit/menu.cpp | 83 +++++++++++++++---- 13 files changed, 217 insertions(+), 44 deletions(-) diff --git a/Xcode/Clover/Clover.xcodeproj/project.pbxproj b/Xcode/Clover/Clover.xcodeproj/project.pbxproj index 7e978deeb..6e1331270 100644 --- a/Xcode/Clover/Clover.xcodeproj/project.pbxproj +++ b/Xcode/Clover/Clover.xcodeproj/project.pbxproj @@ -2484,7 +2484,6 @@ A571C2742405749900B6A2C5 /* utf8Conversion.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = utf8Conversion.cpp; sourceTree = ""; }; A571C2752405749900B6A2C5 /* utf8Conversion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = utf8Conversion.h; sourceTree = ""; }; A571C2772405749900B6A2C5 /* XToolsCommon.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XToolsCommon.cpp; sourceTree = ""; }; - A571C2782405749900B6A2C5 /* printf_lite.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = printf_lite.h; sourceTree = ""; }; A571C2792405749900B6A2C5 /* XArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XArray.h; sourceTree = ""; }; A571C27A2405749900B6A2C5 /* XObjArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XObjArray.h; sourceTree = ""; }; A571C27D240574A100B6A2C5 /* XStringWArray_test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XStringWArray_test.h; sourceTree = ""; }; @@ -8248,7 +8247,6 @@ A571C26E2405749900B6A2C5 /* cpp_foundation */ = { isa = PBXGroup; children = ( - A571C2782405749900B6A2C5 /* printf_lite.h */, A571C2742405749900B6A2C5 /* utf8Conversion.cpp */, A571C2752405749900B6A2C5 /* utf8Conversion.h */, A571C2792405749900B6A2C5 /* XArray.h */, diff --git a/rEFIt_UEFI/Platform/Settings.cpp b/rEFIt_UEFI/Platform/Settings.cpp index 7a63098c9..3cfab5b7f 100644 --- a/rEFIt_UEFI/Platform/Settings.cpp +++ b/rEFIt_UEFI/Platform/Settings.cpp @@ -61,7 +61,7 @@ UINT8 gLanMac[4][6]; // their MAC addresses UINTN nLanPaths; // number of LAN pathes UINTN ThemesNum = 0; -CHAR16 *ThemesList[50]; //no more then 50 themes? +CONST CHAR16 *ThemesList[100]; //no more then 100 themes? UINTN ConfigsNum; CHAR16 *ConfigsList[20]; UINTN DsdtsNum; @@ -2975,7 +2975,7 @@ GetEarlyUserSettings ( OldChosenTheme = 0xFFFF; //default for embedded for (UINTN i = 0; i < ThemesNum; i++) { //now comparison is case sensitive - if (ThemeX.Theme == ThemesList[i]) { //(StriCmp(ThemeX.Theme, ThemesList[i]) == 0) + if (StriCmp(ThemeX.Theme.data(), ThemesList[i]) == 0) { OldChosenTheme = i; break; } diff --git a/rEFIt_UEFI/entry_scan/common.cpp b/rEFIt_UEFI/entry_scan/common.cpp index 9fbed7295..f2637d72f 100644 --- a/rEFIt_UEFI/entry_scan/common.cpp +++ b/rEFIt_UEFI/entry_scan/common.cpp @@ -82,7 +82,12 @@ EG_IMAGE *LoadBuiltinIcon(IN CONST CHAR16 *IconName) } while (Index < BuiltinIconNamesCount) { if (StriCmp(IconName, BuiltinIconNames[Index]) == 0) { +#if USE_XTHEME + XImage IconX = ThemeX.GetIcon(BUILTIN_ICON_VOL_INTERNAL + Index); + return IconX.ToEGImage(); +#else return BuiltinIcon(BUILTIN_ICON_VOL_INTERNAL + Index); +#endif } ++Index; } @@ -92,6 +97,9 @@ EG_IMAGE *LoadBuiltinIcon(IN CONST CHAR16 *IconName) EG_IMAGE* ScanVolumeDefaultIcon(REFIT_VOLUME *Volume, IN UINT8 OSType, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath) //IN UINT8 DiskKind) { UINTN IconNum = 0; +#if USE_XTHEME + XImage IconX; +#endif // default volume icon based on disk kind switch (Volume->DiskKind) { case DISK_KIND_INTERNAL: @@ -125,6 +133,26 @@ EG_IMAGE* ScanVolumeDefaultIcon(REFIT_VOLUME *Volume, IN UINT8 OSType, IN EFI_DE IconNum = BUILTIN_ICON_VOL_INTERNAL; break; } +#if USE_XTHEME + IconX = ThemeX.GetIcon(IconNum); + break; + case DISK_KIND_EXTERNAL: + IconX = ThemeX.GetIcon(BUILTIN_ICON_VOL_EXTERNAL); + break; + case DISK_KIND_OPTICAL: + IconX = ThemeX.GetIcon(BUILTIN_ICON_VOL_OPTICAL); + break; + case DISK_KIND_FIREWIRE: + IconX = ThemeX.GetIcon(BUILTIN_ICON_VOL_FIREWIRE); + break; + case DISK_KIND_BOOTER: + IconX = ThemeX.GetIcon(BUILTIN_ICON_VOL_BOOTER); + break; + default: + return NULL; + } + return IconX.ToEGImage(); +#else return BuiltinIcon(IconNum); case DISK_KIND_EXTERNAL: return BuiltinIcon(BUILTIN_ICON_VOL_EXTERNAL); @@ -138,6 +166,7 @@ EG_IMAGE* ScanVolumeDefaultIcon(REFIT_VOLUME *Volume, IN UINT8 OSType, IN EFI_DE break; } return NULL; +#endif } diff --git a/rEFIt_UEFI/entry_scan/legacy.cpp b/rEFIt_UEFI/entry_scan/legacy.cpp index 9b5d6edee..a1fa493cf 100644 --- a/rEFIt_UEFI/entry_scan/legacy.cpp +++ b/rEFIt_UEFI/entry_scan/legacy.cpp @@ -315,15 +315,15 @@ VOID AddCustomLegacy(VOID) // Traverse the custom entries for (Custom = gSettings.CustomLegacy; Custom; ++i, Custom = Custom->Next) { if (OSFLAG_ISSET(Custom->Flags, OSFLAG_DISABLED)) { - DBG("Custom legacy %llu skipped because it is disabled.\n", i); + DBG("Custom legacy %llu skipped because it is disabled.\n", i); continue; } if (!gSettings.ShowHiddenEntries && OSFLAG_ISSET(Custom->Flags, OSFLAG_HIDDEN)) { - DBG("Custom legacy %llu skipped because it is hidden.\n", i); + DBG("Custom legacy %llu skipped because it is hidden.\n", i); continue; } if (Custom->Volume) { - DBG("Custom legacy %llu matching \"%ls\" ...\n", i, Custom->Volume); + DBG("Custom legacy %llu matching \"%ls\" ...\n", i, Custom->Volume); } for (VolumeIndex = 0; VolumeIndex < Volumes.size(); ++VolumeIndex) { Volume = &Volumes[VolumeIndex]; @@ -414,7 +414,15 @@ VOID AddCustomLegacy(VOID) if (Image == NULL) { Image = egLoadImage(SelfRootDir, Custom->ImagePath, TRUE); if (Image == NULL) { +#if USE_XTHEME + XImage ImageX; + ImageX.LoadXImage(ThemeDir, "unknown"); + Image = ImageX.ToEGImage(); +#else Image = LoadOSIcon(Custom->ImagePath, L"unknown", 128, FALSE, FALSE); +#endif + + } } } diff --git a/rEFIt_UEFI/entry_scan/loader.cpp b/rEFIt_UEFI/entry_scan/loader.cpp index 6e5797973..d829d6168 100644 --- a/rEFIt_UEFI/entry_scan/loader.cpp +++ b/rEFIt_UEFI/entry_scan/loader.cpp @@ -701,7 +701,8 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath, } else if (Image) { Entry->Image.FromEGImage(Image); } else { - Entry->Image = ThemeX.GetIcon("unknown"); +// Entry->Image = ThemeX.GetIcon("unknown"); //no such icon + Entry->Image = ThemeX.GetIcon("vol_internal"); } #else if (GlobalConfig.CustomIcons && FileExists(Volume->RootDir, L"\\.VolumeIcon.icns")){ @@ -1253,8 +1254,15 @@ VOID ScanLoader(VOID) if ((AndroidEntryData[Index].Find[aIndex] == NULL) || FileExists(Volume->RootDir, AndroidEntryData[Index].Find[aIndex])) ++aFound; } if (aFound && (aFound == aIndex)) { +#if USE_XTHEME + XImage ImageX; + ImageX.LoadXImage(ThemeDir, AndroidEntryData[Index].Icon); + AddLoaderEntry(AndroidEntryData[Index].Path, L"", AndroidEntryData[Index].Title, Volume, + ImageX.ToEGImage(), OSTYPE_LIN, OSFLAG_NODEFAULTARGS); +#else AddLoaderEntry(AndroidEntryData[Index].Path, L"", AndroidEntryData[Index].Title, Volume, LoadOSIcon(AndroidEntryData[Index].Icon, L"unknown", 128, FALSE, TRUE), OSTYPE_LIN, OSFLAG_NODEFAULTARGS); +#endif } } } @@ -1264,8 +1272,15 @@ VOID ScanLoader(VOID) if (gSettings.LinuxScan) { // check for linux loaders for (Index = 0; Index < LinuxEntryDataCount; ++Index) { +#if USE_XTHEME + XImage ImageX; + ImageX.LoadXImage(ThemeDir, LinuxEntryData[Index].Icon); + AddLoaderEntry(LinuxEntryData[Index].Path, L"", LinuxEntryData[Index].Title, Volume, + ImageX.ToEGImage(), OSTYPE_LIN, OSFLAG_NODEFAULTARGS); +#else AddLoaderEntry(LinuxEntryData[Index].Path, L"", LinuxEntryData[Index].Title, Volume, LoadOSIcon(LinuxEntryData[Index].Icon, L"unknown", 128, FALSE, TRUE), OSTYPE_LIN, OSFLAG_NODEFAULTARGS); +#endif } // check for linux kernels PartGUID = FindGPTPartitionGuidInDevicePath(Volume->DevicePath); @@ -1805,7 +1820,13 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex, if (Image == NULL) { Image = egLoadImage(SelfRootDir, Custom->ImagePath, TRUE); if (Image == NULL) { +#if USE_XTHEME + XImage ImageX; + ImageX.LoadXImage(ThemeDir, Custom->ImagePath); + Image = ImageX.ToEGImage(); +#else Image = LoadOSIcon(Custom->ImagePath, L"unknown", 128, FALSE, FALSE); +#endif } } } @@ -1823,7 +1844,12 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex, if (DriveImage == NULL) { DriveImage = egLoadImage(SelfRootDir, Custom->DriveImagePath, TRUE); if (DriveImage == NULL) { +#if USE_XTHEME + XImage DriveImageX = ThemeX.GetIcon(Custom->DriveImagePath); + DriveImage = DriveImageX.ToEGImage(); +#else DriveImage = LoadBuiltinIcon(Custom->DriveImagePath); +#endif } } } @@ -2012,7 +2038,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex, SubScreen->AddMenuInfoLine(XStringWP(L"Volume size: ") + WPrintf("%lldMb", VolumeSize)); SubScreen->AddMenuInfoLine(FileDevicePathToStr(Entry->DevicePath)); if (Guid) { - SubScreen->AddMenuInfoLine(WPrintf("UUID: %s", strguid(Guid)).wc_str()); + SubScreen->AddMenuInfoLine(WPrintf("UUID: %s", strguid(Guid)).wc_str()); } SubScreen->AddMenuInfoLine(PoolPrint(L"Options: %s", Entry->LoadOptions)); DBG("Create sub entries\n"); diff --git a/rEFIt_UEFI/entry_scan/securemenu.cpp b/rEFIt_UEFI/entry_scan/securemenu.cpp index 692eb6f57..2eeab0530 100644 --- a/rEFIt_UEFI/entry_scan/securemenu.cpp +++ b/rEFIt_UEFI/entry_scan/securemenu.cpp @@ -69,12 +69,21 @@ VOID AddSecureBootTool(VOID) Entry = new REFIT_MENU_ENTRY_SECURE_BOOT(); Entry->Title.SPrintf("Clover Secure Boot Configuration"); // Entry->Tag = TAG_SECURE_BOOT_CONFIG; +#if USE_XTHEME + Entry->Image = ThemeX.GetIcon(BUILTIN_ICON_FUNC_SECURE_BOOT_CONFIG); +#else Entry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_SECURE_BOOT_CONFIG); +#endif + } else { Entry = new REFIT_MENU_ENTRY_SECURE_BOOT_CONFIG(); Entry->Title.SPrintf("Enable Clover Secure Boot"); // Entry->Tag = TAG_SECURE_BOOT; +#if USE_XTHEME + Entry->Image = ThemeX.GetIcon(BUILTIN_ICON_FUNC_SECURE_BOOT); +#else Entry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_SECURE_BOOT); +#endif } Entry->Row = 1; //actions diff --git a/rEFIt_UEFI/entry_scan/tool.cpp b/rEFIt_UEFI/entry_scan/tool.cpp index a3ea4c82e..142985a9a 100644 --- a/rEFIt_UEFI/entry_scan/tool.cpp +++ b/rEFIt_UEFI/entry_scan/tool.cpp @@ -36,6 +36,7 @@ #include "entry_scan.h" #include "../refit/menu.h" #include "../refit/screen.h" +#include "../libeg/XImage.h" // // Clover File location to boot from on removable media devices @@ -71,10 +72,16 @@ #endif extern EMU_VARIABLE_CONTROL_PROTOCOL *gEmuVariableControl; - +#if USE_XTHEME +STATIC BOOLEAN AddToolEntry(IN CONST CHAR16 *LoaderPath, IN CONST CHAR16 *FullTitle, IN CONST CHAR16 *LoaderTitle, + IN REFIT_VOLUME *Volume, const XImage& Image, + IN CHAR16 ShortcutLetter, IN CONST CHAR16 *Options) +#else STATIC BOOLEAN AddToolEntry(IN CONST CHAR16 *LoaderPath, IN CONST CHAR16 *FullTitle, IN CONST CHAR16 *LoaderTitle, IN REFIT_VOLUME *Volume, IN EG_IMAGE *Image, IN CHAR16 ShortcutLetter, IN CONST CHAR16 *Options) +#endif + { REFIT_MENU_ENTRY_LOADER_TOOL *Entry; // Check the loader exists @@ -131,7 +138,11 @@ STATIC VOID AddCloverEntry(IN CONST CHAR16 *LoaderPath, IN CONST CHAR16 *LoaderT // Entry->Tag = TAG_CLOVER; Entry->Row = 1; Entry->ShortcutLetter = 'C'; +#if USE_XTHEME + Entry->Image = ThemeX.GetIcon(BUILTIN_ICON_FUNC_CLOVER); +#else Entry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_CLOVER); +#endif Entry->Volume = Volume; Entry->LoaderPath = EfiStrDuplicate(LoaderPath); Entry->VolName = Volume->VolName; @@ -197,11 +208,24 @@ VOID ScanTool(VOID) UINTN VolumeIndex; REFIT_VOLUME *Volume; VOID *Interface; - +#if USE_XTHEME + if (ThemeX.HideUIFlags & HIDEUI_FLAG_TOOLS) + return; +#else if (GlobalConfig.DisableFlags & HIDEUI_FLAG_TOOLS) return; +#endif + // DBG("Scanning for tools...\n"); +#if USE_XTHEME + if (!(ThemeX.HideUIFlags & HIDEUI_FLAG_SHELL)) { + if (!AddToolEntry(L"\\EFI\\CLOVER\\tools\\Shell64U.efi", NULL, L"UEFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NULL)) { + AddToolEntry(L"\\EFI\\CLOVER\\tools\\Shell64.efi", NULL, L"EFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NULL); + } + } +#else + // look for the EFI shell if (!(GlobalConfig.DisableFlags & HIDEUI_FLAG_SHELL)) { @@ -218,6 +242,7 @@ VOID ScanTool(VOID) AddToolEntry(L"\\EFI\\CLOVER\\tools\\Shell32.efi", NULL, L"EFI Shell 32", SelfVolume, BuiltinIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NULL); #endif } +#endif // if (!gFirmwareClover) { //Slice: I wish to extend functionality on emulated nvram for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { @@ -336,14 +361,20 @@ VOID AddCustomTool(VOID) } } } +#if USE_XTHEME + if (Image == NULL) { + AddToolEntry(Custom->Path, Custom->FullTitle, Custom->Title, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), Custom->Hotkey, Custom->Options); + } else { + // Create a legacy entry for this volume + AddToolEntry(Custom->Path, Custom->FullTitle, Custom->Title, Volume, XImage().FromEGImage(Image), Custom->Hotkey, Custom->Options); + } +#else if (Image == NULL) { Image = BuiltinIcon(BUILTIN_ICON_TOOL_SHELL); } - // Create a legacy entry for this volume - AddToolEntry(Custom->Path, Custom->FullTitle, Custom->Title, Volume, Image, Custom->Hotkey, Custom->Options); - +#endif DBG("match!\n"); // break; // break scan volumes, continue scan entries -- why? } diff --git a/rEFIt_UEFI/libeg/XImage.cpp b/rEFIt_UEFI/libeg/XImage.cpp index 1e8223357..c1d680b54 100644 --- a/rEFIt_UEFI/libeg/XImage.cpp +++ b/rEFIt_UEFI/libeg/XImage.cpp @@ -640,7 +640,10 @@ void XImage::CopyRect(const XImage& Image, INTN XPos, INTN YPos) EG_IMAGE* XImage::ToEGImage() { - EG_IMAGE* Tmp = egCreateImage(Width, Height, TRUE); + if (isEmpty()) { + return NULL; // what is better, return NULL or empty image? + } + EG_IMAGE* Tmp = egCreateImage(Width, Height, TRUE); //memory leak CopyMem(&Tmp->PixelData[0], &PixelData[0], GetSizeInBytes()); return Tmp; } diff --git a/rEFIt_UEFI/libeg/XPointer.cpp b/rEFIt_UEFI/libeg/XPointer.cpp index cfc4e5077..2597f2e25 100644 --- a/rEFIt_UEFI/libeg/XPointer.cpp +++ b/rEFIt_UEFI/libeg/XPointer.cpp @@ -88,7 +88,15 @@ EFI_STATUS XPointer::MouseBirth() PointerImage = nullptr; } // Now update image because of other theme has other image +#if USE_XTHEME +// XImage PointerImageX = ThemeX.GetIcon(BUILTIN_ICON_POINTER); +// PointerImage = &PointerImageX; + PointerImage = new XImage(ThemeX.GetIcon(BUILTIN_ICON_POINTER)); +#else PointerImage = new XImage(BuiltinIcon(BUILTIN_ICON_POINTER)); +#endif + + oldImage.setSizeInPixels(PointerImage->GetWidth(), PointerImage->GetHeight()); LastClickTime = 0; oldPlace.XPos = (INTN)(UGAWidth >> 2); diff --git a/rEFIt_UEFI/refit/icns.cpp b/rEFIt_UEFI/refit/icns.cpp index 3a9a5d00a..cb1d8fc70 100644 --- a/rEFIt_UEFI/refit/icns.cpp +++ b/rEFIt_UEFI/refit/icns.cpp @@ -281,13 +281,8 @@ EG_IMAGE * BuiltinIcon(IN UINTN Id) // icon name is shutdown from historic reasons, but function is now exit UnicodeSPrint(Text, 30, L"exit"); } -#if USE_XTHEME -#else egRenderText(Text, TextBuffer, 0, 0, 0xFFFF, 1); BuiltinIconTable[Id].Image = TextBuffer; -#endif - - DebugLog(1, " [!] Icon %llu: Text <%ls> rendered\n", Id, Text); FreePool(Text); } diff --git a/rEFIt_UEFI/refit/lib.h b/rEFIt_UEFI/refit/lib.h index b87681d0b..c14089416 100644 --- a/rEFIt_UEFI/refit/lib.h +++ b/rEFIt_UEFI/refit/lib.h @@ -307,7 +307,7 @@ extern INTN ScrollbarYMovement; typedef struct { INTN Timeout; - UINTN DisableFlags; + UINTN DisableFlags; //to disable some volume types (optical, firewire etc) #if !USE_XTHEME UINTN HideBadges; UINTN HideUIFlags; @@ -507,8 +507,8 @@ EFI_STATUS InitializeUnicodeCollationProtocol (VOID); // local variables //extern INTN FontWidth; //extern INTN FontHeight; -#if !USE_XTHEME extern INTN TextHeight; +#if !USE_XTHEME extern INTN row0TileSize; extern INTN row1TileSize; #endif @@ -557,7 +557,7 @@ BOOLEAN CheckError(IN EFI_STATUS Status, IN CONST CHAR16 *where); // // icns loader module // - +#if !USE_XTHEME EG_IMAGE * LoadOSIcon(IN CONST CHAR16 *OSIconName OPTIONAL, IN CONST CHAR16 *FallbackIconName, IN UINTN PixelSize, IN BOOLEAN BootLogo, IN BOOLEAN WantDummy); EG_IMAGE * LoadIcns(IN EFI_FILE_HANDLE BaseDir, IN CONST CHAR16 *FileName, IN UINTN PixelSize); EG_IMAGE * LoadIcnsFallback(IN EFI_FILE_HANDLE BaseDir, IN CONST CHAR16 *FileName, IN UINTN PixelSize); @@ -565,6 +565,7 @@ EG_IMAGE * DummyImage(IN UINTN PixelSize); EG_IMAGE * BuiltinIcon(IN UINTN Id); CHAR16 * GetIconsExt(IN CONST CHAR16 *Icon, IN CONST CHAR16 *Def); EG_IMAGE * GetSmallHover(IN UINTN Id); +#endif #define BUILTIN_ICON_FUNC_ABOUT (0) #define BUILTIN_ICON_FUNC_OPTIONS (1) @@ -623,11 +624,13 @@ EG_IMAGE * GetSmallHover(IN UINTN Id); #define ICON_FORMAT_PNG (2) #define ICON_FORMAT_BMP (3) VOID ReinitVolumes(VOID); + BOOLEAN ReadAllKeyStrokes(VOID); // // config module // +#if !USE_XTHEME typedef struct MISC_ICONS { EG_IMAGE *image; CONST CHAR8 *name; @@ -635,6 +638,7 @@ typedef struct MISC_ICONS { extern MISC_ICONS OSIconsTable[]; extern BUILTIN_ICON BuiltinIconTable[]; +#endif extern REFIT_CONFIG GlobalConfig; VOID ReadConfig(INTN What); diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index c12dd58dd..d80a907aa 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -111,7 +111,7 @@ extern VOID AboutRefit(VOID); extern BOOLEAN BooterPatch(IN UINT8 *BooterData, IN UINT64 BooterSize, LOADER_ENTRY *Entry); extern UINTN ThemesNum; -extern CHAR16 *ThemesList[]; +extern CONST CHAR16 *ThemesList[]; extern UINTN ConfigsNum; extern CHAR16 *ConfigsList[]; extern UINTN DsdtsNum; @@ -1026,14 +1026,21 @@ static VOID StartLegacy(IN LEGACY_ENTRY *Entry) egClearScreen(&DarkBackgroundPixel); BeginExternalScreen(TRUE/*, L"Booting Legacy OS"*/); - - BootLogoImage = LoadOSIcon(Entry->Volume->LegacyOS->IconName, L"legacy", 128, TRUE, TRUE); +#if USE_XTHEME + XImage BootLogoX; + BootLogoX.LoadXImage(ThemeDir, Entry->Volume->LegacyOS->IconName); + BootLogoX.Draw((UGAWidth - BootLogoX.GetWidth()) >> 1, + (UGAHeight - BootLogoX.GetHeight()) >> 1); +#else + BootLogoImage = LoadOSIcon(Entry->Volume->LegacyOS->IconName, L"legacy", 128, TRUE, TRUE); if (BootLogoImage != NULL) { - BltImageAlpha(BootLogoImage, - (UGAWidth - BootLogoImage->Width) >> 1, - (UGAHeight - BootLogoImage->Height) >> 1, - &StdBackgroundPixel, 16); + BltImageAlpha(BootLogoImage, + (UGAWidth - BootLogoImage->Width) >> 1, + (UGAHeight - BootLogoImage->Height) >> 1, + &StdBackgroundPixel, 16); } +#endif + //try my LegacyBoot switch (Entry->Volume->BootType) { case BOOTING_BY_CD: diff --git a/rEFIt_UEFI/refit/menu.cpp b/rEFIt_UEFI/refit/menu.cpp index 3318dc4f9..ea81e1188 100644 --- a/rEFIt_UEFI/refit/menu.cpp +++ b/rEFIt_UEFI/refit/menu.cpp @@ -74,7 +74,7 @@ static INTN MaxItemOnScreen = -1; REFIT_MENU_SCREEN OptionMenu(4, L"Options", NULL); extern REFIT_MENU_ITEM_RETURN MenuEntryReturn; extern UINTN ThemesNum; -extern CHAR16 *ThemesList[]; +extern CONST CHAR16 *ThemesList[]; extern UINTN ConfigsNum; extern CHAR16 *ConfigsList[]; extern UINTN DsdtsNum; @@ -787,6 +787,15 @@ VOID ApplyInputs(VOID) } i++; //3 if (InputItems[i].Valid) { +#if USE_XTHEME + if (OldChosenTheme == 0xFFFF) { + ThemeX.Theme.takeValueFrom("embedded"); + } else { + ThemeX.Theme.takeValueFrom(ThemesList[OldChosenTheme]); + ThemeX.DarkEmbedded = FALSE; + ThemeX.Font = FONT_ALFA; + } +#else if (GlobalConfig.Theme) { FreePool(GlobalConfig.Theme); } @@ -797,6 +806,7 @@ VOID ApplyInputs(VOID) GlobalConfig.DarkEmbedded = FALSE; GlobalConfig.Font = FONT_ALFA; } +#endif //will change theme after ESC gThemeChanged = TRUE; @@ -877,7 +887,7 @@ VOID ApplyInputs(VOID) for (j = 0; j < NGFX; j++) { i++; //20 if (InputItems[i].Valid) { - snprintf(gGraphics[j].Model, 64, "%ls", InputItems[i].SValue); + snprintf(gGraphics[j].Model, 64, "%ls", InputItems[i].SValue); } i++; //21 if (InputItems[i].Valid) { @@ -895,7 +905,7 @@ VOID ApplyInputs(VOID) UnicodeSPrint(gSettings.FBName, 32, L"%s", InputItems[i].SValue); } else if (gGraphics[j].Vendor == Nvidia) { ZeroMem(AString, 256); - snprintf(AString, 255, "%ls", InputItems[i].SValue); + snprintf(AString, 255, "%ls", InputItems[i].SValue); hex2bin(AString, (UINT8*)&gSettings.Dcfg[0], 8); } else if (gGraphics[j].Vendor == Intel) { //ig-platform-id for Ivy+ and snb-platform-id for Sandy @@ -918,7 +928,7 @@ VOID ApplyInputs(VOID) if (gGraphics[j].Vendor == Nvidia) { ZeroMem(AString, 256); if (StrLen(InputItems[i].SValue) > 0) { - snprintf(AString, 255, "%ls", InputItems[i].SValue); + snprintf(AString, 255, "%ls", InputItems[i].SValue); hex2bin(AString, (UINT8*)&gSettings.NVCAP[0], 20); } } else { @@ -1340,7 +1350,6 @@ VOID ApplyInputs(VOID) gBootChanged = TRUE; } - if (NeedSave) { SaveSettings(); } @@ -1375,12 +1384,20 @@ VOID REFIT_MENU_SCREEN::AddMenuInfo_f(CONST char *format, ...) VOID AboutRefit(VOID) { - // CHAR8* Revision = NULL; +#if USE_XTHEME + if (!(ThemeX.HideUIFlags & HIDEUI_FLAG_MENU_TITLE_IMAGE)) { + AboutMenu.TitleImage = ThemeX.GetIcon((INTN)BUILTIN_ICON_FUNC_ABOUT); + } else { + AboutMenu.TitleImage.setEmpty(); + } +#else if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_MENU_TITLE_IMAGE)) { AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT); } else { AboutMenu.TitleImage = NULL; } +#endif + if (AboutMenu.Entries.size() == 0) { // AboutMenu.AddMenuInfo_f(("Clover Version 5.0")); #ifdef REVISION_STR @@ -1436,11 +1453,19 @@ VOID AboutRefit(VOID) VOID HelpRefit(VOID) { +#if USE_XTHEME + if (!(ThemeX.HideUIFlags & HIDEUI_FLAG_MENU_TITLE_IMAGE)) { + HelpMenu.TitleImage = ThemeX.GetIcon(BUILTIN_ICON_FUNC_HELP); + } else { + HelpMenu.TitleImage.setEmpty(); + } +#else if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_MENU_TITLE_IMAGE)) { HelpMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_HELP); } else { HelpMenu.TitleImage = NULL; } +#endif if (HelpMenu.Entries.size() == 0) { switch (gLanguage) { @@ -3241,6 +3266,21 @@ VOID DrawBCSText(IN CONST CHAR16 *Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAl CHAR16 *BCSText = NULL; // more space, more characters +#if USE_XTHEME + if (ThemeX.TileXSpace >= 25 && ThemeX.TileXSpace < 30) { + MaxTextLen = 14; + } else if (ThemeX.TileXSpace >= 30 && ThemeX.TileXSpace < 35) { + MaxTextLen = 15; + } else if (ThemeX.TileXSpace >= 35 && ThemeX.TileXSpace < 40) { + MaxTextLen = 16; + } else if (ThemeX.TileXSpace >= 40 && ThemeX.TileXSpace < 45) { + MaxTextLen = 17; + } else if (ThemeX.TileXSpace >= 45 && ThemeX.TileXSpace < 50) { + MaxTextLen = 18; + } else if (ThemeX.TileXSpace >= 50) { + MaxTextLen = 19; + } +#else if (GlobalConfig.TileXSpace >= 25 && GlobalConfig.TileXSpace < 30) { MaxTextLen = 14; } else if (GlobalConfig.TileXSpace >= 30 && GlobalConfig.TileXSpace < 35) { @@ -3254,6 +3294,7 @@ VOID DrawBCSText(IN CONST CHAR16 *Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAl } else if (GlobalConfig.TileXSpace >= 50) { MaxTextLen = 19; } +#endif MaxTextLen += EllipsisLen; @@ -5117,7 +5158,7 @@ VOID REFIT_MENU_SCREEN::MainMenuStyle(IN UINTN Function, IN CONST CHAR16 *ParamT row0PosXRunning += EntriesWidth + EntriesGap; } else { itemPosX[i] = row1PosXRunning; - row1PosXRunning += row1TileSize + (INTN)(TILE1_XSPACING * ThemeX.Scale); + row1PosXRunning += ThemeX.row1TileSize + (INTN)(TILE1_XSPACING * ThemeX.Scale); //DBG("next item in row1 at x=%d\n", row1PosXRunning); } } @@ -5149,12 +5190,12 @@ VOID REFIT_MENU_SCREEN::MainMenuStyle(IN UINTN Function, IN CONST CHAR16 *ParamT // draw static text for the boot options, BootCampStyle if (ThemeX.BootCampStyle && !(ThemeX.HideUIFlags & HIDEUI_FLAG_LABEL)) { - INTN textPosX = itemPosX[i - ScrollState.FirstVisible] + (row0TileSize / 2); + INTN textPosX = itemPosX[i - ScrollState.FirstVisible] + (ThemeX.row0TileSize / 2); // clear the screen - ThemeX.FillRectAreaOfScreen(textPosX, textPosY, EntriesWidth + GlobalConfig.TileXSpace, + ThemeX.FillRectAreaOfScreen(textPosX, textPosY, EntriesWidth + ThemeX.TileXSpace, MessageHeight); - DrawBCSText(Entries[i].Title, textPosX, textPosY, X_IS_CENTER); + DrawBCSText(Entries[i].Title.data(), textPosX, textPosY, X_IS_CENTER); } } } else { @@ -5356,7 +5397,7 @@ VOID REFIT_MENU_SCREEN::MainMenuStyle(IN UINTN Function, IN CONST CHAR16 *ParamT FillRectAreaOfScreen(textPosX, textPosY, EntriesWidth + GlobalConfig.TileXSpace, MessageHeight, &MenuBackgroundPixel, X_IS_CENTER); // draw the text - DrawBCSText(Entries[i].Title, textPosX, textPosY, X_IS_CENTER); + DrawBCSText(Entries[i].Title.data(), textPosX, textPosY, X_IS_CENTER); } } } else { @@ -6632,9 +6673,9 @@ VOID OptionsMenu(OUT REFIT_ABSTRACT_MENU_ENTRY **ChosenEntry) // FillInputs and ApplyInputs #if USE_XTHEME if (!(ThemeX.HideUIFlags & HIDEUI_FLAG_MENU_TITLE_IMAGE)) { - OptionMenu.TitleImage = (*ThemeX.GetIcon(BUILTIN_ICON_FUNC_OPTIONS)).ToEGImage(); + OptionMenu.TitleImage = ThemeX.GetIcon(BUILTIN_ICON_FUNC_OPTIONS); } else { - OptionMenu.TitleImage = NULL; + OptionMenu.TitleImage.setEmpty(); } #else if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_MENU_TITLE_IMAGE)) { @@ -6720,7 +6761,13 @@ VOID OptionsMenu(OUT REFIT_ABSTRACT_MENU_ENTRY **ChosenEntry) } // if MENU_EXIT_ENTER } //exit: +#if USE_XTHEME + ThemeX.Proportional = OldFontStyle; +#else GlobalConfig.Proportional = OldFontStyle; +#endif + + ApplyInputs(); } @@ -6797,11 +6844,19 @@ UINTN REFIT_MENU_SCREEN::RunMainMenu(IN INTN DefaultSelection, OUT REFIT_ABSTRAC if (AllowGraphicsMode) { Style = &REFIT_MENU_SCREEN::GraphicsMenuStyle; +#if USE_XTHEME + if (ThemeX.VerticalLayout) { + MainStyle = &REFIT_MENU_SCREEN::MainMenuVerticalStyle; + } else { + MainStyle = &REFIT_MENU_SCREEN::MainMenuStyle; + } +#else if (GlobalConfig.VerticalLayout) { MainStyle = &REFIT_MENU_SCREEN::MainMenuVerticalStyle; } else { MainStyle = &REFIT_MENU_SCREEN::MainMenuStyle; } +#endif } while (!MenuExit) { @@ -6855,7 +6910,7 @@ UINTN REFIT_MENU_SCREEN::RunMainMenu(IN INTN DefaultSelection, OUT REFIT_ABSTRAC } if (/*MenuExit == MENU_EXIT_ENTER &&*/ MainChosenEntry->getLOADER_ENTRY()) { if (MainChosenEntry->getLOADER_ENTRY()->LoadOptions) { - snprintf(gSettings.BootArgs, 255, "%ls", MainChosenEntry->getLOADER_ENTRY()->LoadOptions); + snprintf(gSettings.BootArgs, 255, "%ls", MainChosenEntry->getLOADER_ENTRY()->LoadOptions); } else { ZeroMem(&gSettings.BootArgs, 255); }