a possibility to use wchar in icon names

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-03-30 18:31:52 +03:00
parent f7254f53e6
commit 6dc43d9d8e
11 changed files with 33 additions and 19 deletions

View File

@ -102,7 +102,7 @@ class XArray
bool isEmpty() const { return size() == 0; } bool isEmpty() const { return size() == 0; }
xsize IdxOf(TYPE& e) const; xsize IdxOf(TYPE& e) const;
bool ExistIn(TYPE& e) const { return IdxOf(e) != MAX_XSIZE; } bool ExistIn(TYPE& e) const { return IdxOf(e) != MAX_XSIZE; } //logically it should be named as Contains(e)
}; };
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

View File

@ -32,17 +32,19 @@
XStringWP::XStringWP(const wchar_t *S) XStringWP::XStringWP(const wchar_t *S)
{ {
if ( !S ) { if ( !S ) {
DebugLog(2, "XStringWP(const wchar_t *S) called with NULL. Use setEmpty()\n"); // DebugLog(2, "XStringWP(const wchar_t *S) called with NULL. Use setEmpty()\n");
panic(); // panic();
} Init(0);
DBG("Constructor(const wchar_t *S) : %ls, StrLen(S)=%d\n", S, StrLen(S)); } else {
Init(wcslen(S)); DBG("Constructor(const wchar_t *S) : %ls, StrLen(S)=%d\n", S, StrLen(S));
StrCpy(S); Init(wcslen(S));
StrCpy(S);
}
} }
XStringWP::XStringWP(const char* S) XStringWP::XStringWP(const char* S)
{ {
DBG("Constructor(const char* S)\n"); DBG("Constructor(const char* S)\n");
xsize newLen = StrLenInWChar(S); xsize newLen = StrLenInWChar(S);
Init(newLen); Init(newLen);
utf8ToWChar(m_data, m_allocatedSize+1, S); // m_size doesn't count the NULL terminator utf8ToWChar(m_data, m_allocatedSize+1, S); // m_size doesn't count the NULL terminator

View File

@ -180,10 +180,11 @@ CHAR16 *AddLoadOption(IN CONST CHAR16 *LoadOptions, IN CONST CHAR16 *LoadOption)
return EfiStrDuplicate(LoadOption); return EfiStrDuplicate(LoadOption);
} }
// If there is no option or it is already present duplicate original // If there is no option or it is already present duplicate original
// with XStringW it will be replaced by if (LoadOptions.ExistIn(LoadOption))
else if ((LoadOption == NULL) || StrStr(LoadOptions, LoadOption)) else if ((LoadOption == NULL) || StrStr(LoadOptions, LoadOption))
return EfiStrDuplicate(LoadOptions); return EfiStrDuplicate(LoadOptions);
// Otherwise add option // Otherwise add option
return PoolPrint(L"%s %s", LoadOptions, LoadOption); return PoolPrint(L"%s %s", LoadOptions, LoadOption); //LoadOptions + LoadOption
} }
CHAR16 *RemoveLoadOption(IN CONST CHAR16 *LoadOptions, IN CONST CHAR16 *LoadOption) CHAR16 *RemoveLoadOption(IN CONST CHAR16 *LoadOptions, IN CONST CHAR16 *LoadOption)

View File

@ -363,10 +363,12 @@ VOID AddCustomTool(VOID)
} }
#if USE_XTHEME #if USE_XTHEME
if (Image == NULL) { if (Image == NULL) {
AddToolEntry(Custom->Path, Custom->FullTitle, Custom->Title, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), Custom->Hotkey, Custom->Options); AddToolEntry(Custom->Path, Custom->FullTitle, Custom->Title, Volume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), Custom->Hotkey, Custom->Options);
} else { } else {
// Create a legacy entry for this volume // Create a legacy entry for this volume
AddToolEntry(Custom->Path, Custom->FullTitle, Custom->Title, Volume, XImage().FromEGImage(Image), Custom->Hotkey, Custom->Options); XImage ImageX;
ImageX.FromEGImage(Image);
AddToolEntry(Custom->Path, Custom->FullTitle, Custom->Title, Volume, ImageX, Custom->Hotkey, Custom->Options);
} }
#else #else
if (Image == NULL) { if (Image == NULL) {

View File

@ -541,6 +541,11 @@ EFI_STATUS XImage::LoadXImage(EFI_FILE *BaseDir, const char* IconName)
{ {
return LoadXImage(BaseDir, XStringWP(IconName)); return LoadXImage(BaseDir, XStringWP(IconName));
} }
EFI_STATUS XImage::LoadXImage(EFI_FILE *BaseDir, const wchar_t* LIconName)
{
return LoadXImage(BaseDir, XStringWP(LIconName));
}
//dont call this procedure for SVG theme BaseDir == NULL? //dont call this procedure for SVG theme BaseDir == NULL?
EFI_STATUS XImage::LoadXImage(EFI_FILE *BaseDir, const XStringW& IconName) EFI_STATUS XImage::LoadXImage(EFI_FILE *BaseDir, const XStringW& IconName)
{ {

View File

@ -101,6 +101,7 @@ public:
//I changed the name because LoadImage is too widely used //I changed the name because LoadImage is too widely used
// will be used instead of old egLoadImage // will be used instead of old egLoadImage
EFI_STATUS LoadXImage(EFI_FILE *Dir, const XStringW& FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name); EFI_STATUS LoadXImage(EFI_FILE *Dir, const XStringW& FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name);
EFI_STATUS LoadXImage(EFI_FILE *Dir, const wchar_t* LIconName);
EFI_STATUS LoadXImage(EFI_FILE *Dir, const char* IconName); EFI_STATUS LoadXImage(EFI_FILE *Dir, const char* IconName);
EFI_STATUS LoadIcns(IN EFI_FILE *Dir, IN CONST CHAR16 *FileName, IN UINTN PixelSize); EFI_STATUS LoadIcns(IN EFI_FILE *Dir, IN CONST CHAR16 *FileName, IN UINTN PixelSize);
void EnsureImageSize(IN UINTN Width, IN UINTN Height, IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color); void EnsureImageSize(IN UINTN Width, IN UINTN Height, IN CONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color);

View File

@ -175,6 +175,11 @@ const XImage& XTheme::GetIcon(const char* Name)
return GetIcon(XString().takeValueFrom(Name)); return GetIcon(XString().takeValueFrom(Name));
} }
const XImage& XTheme::GetIcon(const CHAR16* Name)
{
return GetIcon(XString().takeValueFrom(Name));
}
static XImage NullIcon; static XImage NullIcon;
const XImage& XTheme::GetIcon(const XString& Name) const XImage& XTheme::GetIcon(const XString& Name)

View File

@ -105,6 +105,7 @@ public:
//fill the theme //fill the theme
const XImage& GetIcon(const XString& Name); //get by name const XImage& GetIcon(const XString& Name); //get by name
const XImage& GetIcon(const char* Name); const XImage& GetIcon(const char* Name);
const XImage& GetIcon(const CHAR16* Name);
const XImage& GetIcon(INTN Id); //get by id const XImage& GetIcon(INTN Id); //get by id
void AddIcon(Icon& NewIcon); //return EFI_STATUS? void AddIcon(Icon& NewIcon); //return EFI_STATUS?

View File

@ -38,7 +38,7 @@
#define __LIBEG_LIBEG_H__ #define __LIBEG_LIBEG_H__
#ifndef USE_XTHEME #ifndef USE_XTHEME
#define USE_XTHEME 0 #define USE_XTHEME 1
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1004,9 +1004,6 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry)
static VOID StartLegacy(IN LEGACY_ENTRY *Entry) static VOID StartLegacy(IN LEGACY_ENTRY *Entry)
{ {
EFI_STATUS Status = EFI_UNSUPPORTED; EFI_STATUS Status = EFI_UNSUPPORTED;
EG_IMAGE *BootLogoImage;
// UINTN ErrorInStep = 0;
// EFI_DEVICE_PATH *DiscoveredPathList[MAX_DISCOVERED_PATHS];
// Unload EmuVariable before booting legacy. // Unload EmuVariable before booting legacy.
// This is not needed in most cases, but it seems to interfere with legacy OS // This is not needed in most cases, but it seems to interfere with legacy OS
@ -1032,7 +1029,7 @@ static VOID StartLegacy(IN LEGACY_ENTRY *Entry)
BootLogoX.Draw((UGAWidth - BootLogoX.GetWidth()) >> 1, BootLogoX.Draw((UGAWidth - BootLogoX.GetWidth()) >> 1,
(UGAHeight - BootLogoX.GetHeight()) >> 1); (UGAHeight - BootLogoX.GetHeight()) >> 1);
#else #else
BootLogoImage = LoadOSIcon(Entry->Volume->LegacyOS->IconName, L"legacy", 128, TRUE, TRUE); EG_IMAGE *BootLogoImage = LoadOSIcon(Entry->Volume->LegacyOS->IconName, L"legacy", 128, TRUE, TRUE);
if (BootLogoImage != NULL) { if (BootLogoImage != NULL) {
BltImageAlpha(BootLogoImage, BltImageAlpha(BootLogoImage,
(UGAWidth - BootLogoImage->Width) >> 1, (UGAWidth - BootLogoImage->Width) >> 1,

View File

@ -3795,14 +3795,14 @@ VOID REFIT_MENU_SCREEN::GraphicsMenuStyle(IN UINTN Function, IN CONST CHAR16 *Pa
//clovy//PlaceCentre1 = (TextHeight - (INTN)(Buttons[2]->Height * GlobalConfig.Scale)) / 2; //clovy//PlaceCentre1 = (TextHeight - (INTN)(Buttons[2]->Height * GlobalConfig.Scale)) / 2;
//clovy//PlaceCentre = (PlaceCentre>0)?PlaceCentre:0; //clovy//PlaceCentre = (PlaceCentre>0)?PlaceCentre:0;
//clovy//PlaceCentre1 = (TextHeight - (INTN)(Buttons[0]->Height * GlobalConfig.Scale)) / 2; //clovy//PlaceCentre1 = (TextHeight - (INTN)(Buttons[0]->Height * GlobalConfig.Scale)) / 2;
PlaceCentre = (INTN)((TextHeight - (INTN)(Buttons[2]->Height)) * ThemeX.Scale / 2); PlaceCentre = (INTN)((TextHeight - (INTN)(ThemeX.Buttons[2].GetHeight())) * ThemeX.Scale / 2);
PlaceCentre1 = (INTN)((TextHeight - (INTN)(Buttons[0]->Height)) * ThemeX.Scale / 2); PlaceCentre1 = (INTN)((TextHeight - (INTN)(ThemeX.Buttons[0].GetHeight())) * ThemeX.Scale / 2);
// clovy // clovy
if (ThemeX.TypeSVG) if (ThemeX.TypeSVG)
ctrlX = EntriesPosX; ctrlX = EntriesPosX;
else ctrlX = EntriesPosX + (INTN)(TEXT_XMARGIN * ThemeX.Scale); else ctrlX = EntriesPosX + (INTN)(TEXT_XMARGIN * ThemeX.Scale);
ctrlTextX = ctrlX + Buttons[0]->Width + (INTN)(TEXT_XMARGIN * ThemeX.Scale / 2); ctrlTextX = ctrlX + ThemeX.Buttons[0].GetWidth() + (INTN)(TEXT_XMARGIN * ThemeX.Scale / 2);
ctrlY = Entry->Place.YPos + PlaceCentre; ctrlY = Entry->Place.YPos + PlaceCentre;
if ( Entry->getREFIT_INPUT_DIALOG() ) { if ( Entry->getREFIT_INPUT_DIALOG() ) {