Skip to content

Commit

Permalink
load icons as in xtheme
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Isakov <[email protected]>
  • Loading branch information
SergeySlice committed Mar 30, 2020
1 parent 17c92d9 commit f7254f5
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 44 deletions.
2 changes: 0 additions & 2 deletions Xcode/Clover/Clover.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2484,7 +2484,6 @@
A571C2742405749900B6A2C5 /* utf8Conversion.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = utf8Conversion.cpp; sourceTree = "<group>"; };
A571C2752405749900B6A2C5 /* utf8Conversion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = utf8Conversion.h; sourceTree = "<group>"; };
A571C2772405749900B6A2C5 /* XToolsCommon.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XToolsCommon.cpp; sourceTree = "<group>"; };
A571C2782405749900B6A2C5 /* printf_lite.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = printf_lite.h; sourceTree = "<group>"; };
A571C2792405749900B6A2C5 /* XArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XArray.h; sourceTree = "<group>"; };
A571C27A2405749900B6A2C5 /* XObjArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XObjArray.h; sourceTree = "<group>"; };
A571C27D240574A100B6A2C5 /* XStringWArray_test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XStringWArray_test.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8248,7 +8247,6 @@
A571C26E2405749900B6A2C5 /* cpp_foundation */ = {
isa = PBXGroup;
children = (
A571C2782405749900B6A2C5 /* printf_lite.h */,
A571C2742405749900B6A2C5 /* utf8Conversion.cpp */,
A571C2752405749900B6A2C5 /* utf8Conversion.h */,
A571C2792405749900B6A2C5 /* XArray.h */,
Expand Down
4 changes: 2 additions & 2 deletions rEFIt_UEFI/Platform/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
29 changes: 29 additions & 0 deletions rEFIt_UEFI/entry_scan/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -138,6 +166,7 @@ EG_IMAGE* ScanVolumeDefaultIcon(REFIT_VOLUME *Volume, IN UINT8 OSType, IN EFI_DE
break;
}
return NULL;
#endif
}


Expand Down
14 changes: 11 additions & 3 deletions rEFIt_UEFI/entry_scan/legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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


}
}
}
Expand Down
30 changes: 28 additions & 2 deletions rEFIt_UEFI/entry_scan/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")){
Expand Down Expand Up @@ -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
}
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions rEFIt_UEFI/entry_scan/securemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 36 additions & 5 deletions rEFIt_UEFI/entry_scan/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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++) {
Expand Down Expand Up @@ -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?
}
Expand Down
5 changes: 4 additions & 1 deletion rEFIt_UEFI/libeg/XImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions rEFIt_UEFI/libeg/XPointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions rEFIt_UEFI/refit/icns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit f7254f5

Please sign in to comment.