mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-09-21 02:51:04 +02:00
Restructuring of GetIcon/GetIconAlt/FillByDir, hopefully cover all cases now
This commit is contained in:
parent
50faf1ae0a
commit
2c65cd53f7
@ -293,22 +293,24 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer)
|
|||||||
}
|
}
|
||||||
Icon* NewIcon = new Icon(i, false); //initialize without embedded
|
Icon* NewIcon = new Icon(i, false); //initialize without embedded
|
||||||
Status = ParseSVGXIcon(i, NewIcon->Name, &NewIcon->Image);
|
Status = ParseSVGXIcon(i, NewIcon->Name, &NewIcon->Image);
|
||||||
|
// DBG("parse %s status %s\n", NewIcon->Name.c_str(), strerror(Status));
|
||||||
NewIcon->Native = !EFI_ERROR(Status);
|
NewIcon->Native = !EFI_ERROR(Status);
|
||||||
if (EFI_ERROR(Status) &&
|
if (!EFI_ERROR(Status)) {
|
||||||
(i >= BUILTIN_ICON_VOL_INTERNAL_HFS) &&
|
ParseSVGXIcon(i, NewIcon->Name + "_night"_XS, &NewIcon->ImageNight);
|
||||||
(i <= BUILTIN_ICON_VOL_INTERNAL_REC)) {
|
|
||||||
NewIcon->Image = GetIconAlt(i, BUILTIN_ICON_VOL_INTERNAL); //copy existing
|
|
||||||
}
|
|
||||||
// DBG("parse %s status %s\n", NewIcon->Name.c_str(), strerror(Status));
|
|
||||||
Status = ParseSVGXIcon(i, NewIcon->Name + "_night"_XS, &NewIcon->ImageNight);
|
|
||||||
// DBG("...night status %s\n", strerror(Status));
|
|
||||||
if (EFI_ERROR(Status) &&
|
|
||||||
(i >= BUILTIN_ICON_VOL_INTERNAL_HFS) &&
|
|
||||||
(i <= BUILTIN_ICON_VOL_INTERNAL_REC)) {
|
|
||||||
NewIcon->ImageNight = GetIconAlt(i, BUILTIN_ICON_VOL_INTERNAL); //copy existing
|
|
||||||
}
|
}
|
||||||
Icons.AddReference(NewIcon, true);
|
Icons.AddReference(NewIcon, true);
|
||||||
|
if (EFI_ERROR(Status) && i >= BUILTIN_ICON_VOL_INTERNAL_HFS && i <= BUILTIN_ICON_VOL_INTERNAL_REC) {
|
||||||
|
// call to GetIconAlt will get alternate/embedded into Icon if missing
|
||||||
|
GetIconAlt(i, BUILTIN_ICON_VOL_INTERNAL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
//selection for bootcampstyle
|
||||||
|
Icon *NewIcon = new Icon(BUILTIN_ICON_SELECTION);
|
||||||
|
Status = ParseSVGXIcon(BUILTIN_ICON_SELECTION, "selection_indicator"_XS, &NewIcon->Image);
|
||||||
|
if (!EFI_ERROR(Status)) {
|
||||||
|
ParseSVGXIcon(BUILTIN_ICON_SELECTION, "selection_indicator_night"_XS, &NewIcon->ImageNight);
|
||||||
|
}
|
||||||
|
Icons.AddReference(NewIcon, true);
|
||||||
|
|
||||||
//selections
|
//selections
|
||||||
SelectionBackgroundPixel.Red = (SelectionColor >> 24) & 0xFF;
|
SelectionBackgroundPixel.Red = (SelectionColor >> 24) & 0xFF;
|
||||||
@ -318,15 +320,7 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer)
|
|||||||
|
|
||||||
SelectionImages[0] = GetIcon(BUILTIN_SELECTION_BIG);
|
SelectionImages[0] = GetIcon(BUILTIN_SELECTION_BIG);
|
||||||
SelectionImages[2] = GetIcon(BUILTIN_SELECTION_SMALL);
|
SelectionImages[2] = GetIcon(BUILTIN_SELECTION_SMALL);
|
||||||
|
SelectionImages[5] = GetIcon(BUILTIN_ICON_SELECTION);
|
||||||
//selection for bootcamp style
|
|
||||||
Status = EFI_NOT_FOUND;
|
|
||||||
if (!ThemeX.Daylight) {
|
|
||||||
Status = ParseSVGXIcon(BUILTIN_ICON_SELECTION, "selection_indicator_night"_XS, &SelectionImages[4]);
|
|
||||||
}
|
|
||||||
if (EFI_ERROR(Status)) {
|
|
||||||
Status = ParseSVGXIcon(BUILTIN_ICON_SELECTION, "selection_indicator"_XS, &SelectionImages[4]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//buttons
|
//buttons
|
||||||
for (INTN i = BUILTIN_RADIO_BUTTON; i <= BUILTIN_CHECKBOX_CHECKED; ++i) {
|
for (INTN i = BUILTIN_RADIO_BUTTON; i <= BUILTIN_CHECKBOX_CHECKED; ++i) {
|
||||||
|
@ -320,76 +320,64 @@ bool XTheme::CheckNative(INTN Id)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const XImage& XTheme::GetIcon(INTN Id) //if not found then take embedded
|
const XImage& XTheme::GetIcon(INTN Id)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < Icons.size(); i++)
|
return GetIconAlt(Id, -1);
|
||||||
{
|
|
||||||
if (Icons[i].Id == Id)
|
|
||||||
{
|
|
||||||
if (!Daylight && !Icons[i].ImageNight.isEmpty()) {
|
|
||||||
// DBG("got night icon %lld name{%s}\n", Id, IconsNames[Id]);
|
|
||||||
return Icons[i].ImageNight;
|
|
||||||
}
|
|
||||||
//if daylight or night icon absent
|
|
||||||
if (!Icons[i].Image.isEmpty()) {
|
|
||||||
// DBG("got day icon %lld name{%s}\n", Id, IconsNames[Id]);
|
|
||||||
return Icons[i].Image;
|
|
||||||
}
|
|
||||||
//if not found then create new one from embedded
|
|
||||||
Icon NewIcon(Id, true);
|
|
||||||
// NewIcon.GetEmbedded();
|
|
||||||
// DBG("got embedded icon %lld name{%s}\n", Id, IconsNames[Id]);
|
|
||||||
if (!Daylight && !NewIcon.ImageNight.isEmpty()) {
|
|
||||||
// DBG("got night icon and cache\n");
|
|
||||||
Icons[i].ImageNight = NewIcon.ImageNight; //
|
|
||||||
return Icons[i].ImageNight; // Do not return NewIcon.ImageNight, it'll freed
|
|
||||||
}
|
|
||||||
//if daylight or night icon absent
|
|
||||||
if (!NewIcon.Image.isEmpty()) {
|
|
||||||
// DBG("got day icon and cache\n");
|
|
||||||
Icons[i].Image = NewIcon.Image;
|
|
||||||
return Icons[i].Image;; // Do not return NewIcon.ImageNight, it'll freed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// icon ID not found in icons array, but in case an embedded exists, get it and add it to icons array
|
|
||||||
Icon *NewIcon = new Icon(Id, true);
|
|
||||||
if (!Daylight && !NewIcon->ImageNight.isEmpty()) {
|
|
||||||
return Icons[Icons.AddReference(NewIcon, true)].ImageNight;
|
|
||||||
} else if (!NewIcon->Image.isEmpty()) {
|
|
||||||
return Icons[Icons.AddReference(NewIcon, true)].Image;
|
|
||||||
}
|
|
||||||
return NullIcon; //such Id is not found in the database
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get Icon with this ID=id, for example vol_internal_hfs
|
* Get Icon with this ID=id, for example VOL_INTERNAL_HFS
|
||||||
* if not found then search for ID=Alt, for example vol_internal
|
* if not found then search for ID=Alt with Native attribute set, for example VOL_INTERNAL
|
||||||
* if not found then check embedded with ID=id
|
* if not found then check embedded with ID=Id
|
||||||
* if not found then check embedded with ID=Alt
|
* if not found then check embedded with ID=Alt
|
||||||
*/
|
*/
|
||||||
const XImage& XTheme::GetIconAlt(INTN Id, INTN Alt)
|
const XImage& XTheme::GetIconAlt(INTN Id, INTN Alt) //if not found then take embedded
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < Icons.size(); i++)
|
INTN IdFound = -1;
|
||||||
{
|
INTN AltFound = -1;
|
||||||
if (Icons[i].Id == Id)
|
|
||||||
{
|
for (size_t i = 0; i < Icons.size() && (IdFound < 0 || (Alt >= 0 && AltFound < 0)); i++) {
|
||||||
if (!Daylight && !Icons[i].ImageNight.isEmpty()) {
|
if (Icons[i].Id == Id) {
|
||||||
return Icons[i].ImageNight;
|
IdFound = i;
|
||||||
}
|
}
|
||||||
//if daylight or night icon absent
|
if (Icons[i].Id == Alt) {
|
||||||
if (!Icons[i].Image.isEmpty()) {
|
AltFound = i;
|
||||||
return Icons[i].Image;
|
|
||||||
}
|
|
||||||
if (CheckNative(Alt)) {
|
|
||||||
return GetIcon(Alt);
|
|
||||||
}
|
|
||||||
//if Id and Alt native absent return embedded
|
|
||||||
return GetIcon(Id); //including embedded
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NullIcon; //such Id is not found in the database
|
|
||||||
|
|
||||||
|
// if icon is empty, try to fill it with alternative
|
||||||
|
if (IdFound >= 0 && Icons[IdFound].Image.isEmpty()) {
|
||||||
|
// check for native ID=Alt, if Alt was specified
|
||||||
|
if (Alt >= 0 && AltFound >= 0 && Icons[AltFound].Native && !Icons[AltFound].Image.isEmpty()) {
|
||||||
|
// using Alt icon
|
||||||
|
Icons[IdFound].Image = Icons[AltFound].Image;
|
||||||
|
Icons[IdFound].ImageNight = Icons[AltFound].ImageNight;
|
||||||
|
} else {
|
||||||
|
// check for embedded with ID=Id
|
||||||
|
Icon *NewIcon = new Icon(Id, true);
|
||||||
|
if (NewIcon->Image.isEmpty()) {
|
||||||
|
// check for embedded with ID=Alt
|
||||||
|
NewIcon = new Icon(Alt, true);
|
||||||
|
}
|
||||||
|
if (!NewIcon->Image.isEmpty()) {
|
||||||
|
// using Embedded icon
|
||||||
|
Icons[IdFound].Image = NewIcon->Image;
|
||||||
|
Icons[IdFound].ImageNight = NewIcon->ImageNight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IdFound >= 0 && !Icons[IdFound].Image.isEmpty()) {
|
||||||
|
// icon not empty, return it
|
||||||
|
if (!Daylight && !Icons[IdFound].ImageNight.isEmpty()) {
|
||||||
|
DBG("got night icon %lld name{%s}\n", Id, IconsNames[Id]);
|
||||||
|
return Icons[IdFound].ImageNight;
|
||||||
|
}
|
||||||
|
//if daylight or night icon absent
|
||||||
|
DBG("got day icon %lld name{%s}\n", Id, IconsNames[Id]);
|
||||||
|
return Icons[IdFound].Image;
|
||||||
|
}
|
||||||
|
return NullIcon; //such Id is not found in the database
|
||||||
}
|
}
|
||||||
|
|
||||||
const XImage& XTheme::LoadOSIcon(const CHAR16* OSIconName)
|
const XImage& XTheme::LoadOSIcon(const CHAR16* OSIconName)
|
||||||
@ -772,20 +760,39 @@ void XTheme::FillByDir() //assume ThemeDir is defined by InitTheme() procedure
|
|||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
Icons.Empty();
|
Icons.Empty();
|
||||||
for (INTN i = 0; i <= BUILTIN_CHECKBOX_CHECKED; ++i) {
|
for (INTN i = 0; i <= BUILTIN_CHECKBOX_CHECKED; ++i) {
|
||||||
|
Status = EFI_NOT_FOUND;
|
||||||
Icon* NewIcon = new Icon(i); //initialize without embedded
|
Icon* NewIcon = new Icon(i); //initialize without embedded
|
||||||
Status = NewIcon->Image.LoadXImage(ThemeDir, IconsNames[i]);
|
switch (i) {
|
||||||
NewIcon->Native = !EFI_ERROR(Status);
|
case BUILTIN_SELECTION_SMALL:
|
||||||
if (EFI_ERROR(Status) &&
|
Status = NewIcon->Image.LoadXImage(ThemeDir, SelectionSmallFileName);
|
||||||
(i >= BUILTIN_ICON_VOL_INTERNAL_HFS) &&
|
break;
|
||||||
(i <= BUILTIN_ICON_VOL_INTERNAL_REC)) {
|
case BUILTIN_SELECTION_BIG:
|
||||||
NewIcon->Image = GetIconAlt(i, BUILTIN_ICON_VOL_INTERNAL); //copy existing
|
Status = NewIcon->Image.LoadXImage(ThemeDir, SelectionBigFileName);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (EFI_ERROR(Status)) {
|
||||||
Status = NewIcon->ImageNight.LoadXImage(ThemeDir, SWPrintf("%s_night", IconsNames[i]));
|
Status = NewIcon->Image.LoadXImage(ThemeDir, IconsNames[i]);
|
||||||
if (EFI_ERROR(Status) &&
|
}
|
||||||
(i >= BUILTIN_ICON_VOL_INTERNAL_HFS) &&
|
NewIcon->Native = !EFI_ERROR(Status);
|
||||||
(i <= BUILTIN_ICON_VOL_INTERNAL_REC)) {
|
if (!EFI_ERROR(Status)) {
|
||||||
NewIcon->ImageNight = GetIconAlt(i, BUILTIN_ICON_VOL_INTERNAL); //copy existing
|
NewIcon->ImageNight.LoadXImage(ThemeDir, SWPrintf("%s_night", IconsNames[i]));
|
||||||
|
}
|
||||||
|
Icons.AddReference(NewIcon, true);
|
||||||
|
if (EFI_ERROR(Status)) {
|
||||||
|
if (i >= BUILTIN_ICON_VOL_INTERNAL_HFS && i <= BUILTIN_ICON_VOL_INTERNAL_REC) {
|
||||||
|
// call to GetIconAlt will get alternate/embedded into Icon if missing
|
||||||
|
GetIconAlt(i, BUILTIN_ICON_VOL_INTERNAL);
|
||||||
|
} else if (i == BUILTIN_SELECTION_BIG) {
|
||||||
|
GetIconAlt(i, BUILTIN_SELECTION_SMALL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (BootCampStyle) {
|
||||||
|
Icon *NewIcon = new Icon(BUILTIN_ICON_SELECTION);
|
||||||
|
// load indicator selection image
|
||||||
|
Status = NewIcon->Image.LoadXImage(ThemeDir, SelectionIndicatorName);
|
||||||
|
if (EFI_ERROR(Status)) {
|
||||||
|
Status = NewIcon->Image.LoadXImage(ThemeDir, "selection_indicator");
|
||||||
}
|
}
|
||||||
Icons.AddReference(NewIcon, true);
|
Icons.AddReference(NewIcon, true);
|
||||||
}
|
}
|
||||||
@ -795,42 +802,10 @@ void XTheme::FillByDir() //assume ThemeDir is defined by InitTheme() procedure
|
|||||||
SelectionBackgroundPixel.Blue = (SelectionColor >> 8) & 0xFF;
|
SelectionBackgroundPixel.Blue = (SelectionColor >> 8) & 0xFF;
|
||||||
SelectionBackgroundPixel.Reserved = (SelectionColor >> 0) & 0xFF;
|
SelectionBackgroundPixel.Reserved = (SelectionColor >> 0) & 0xFF;
|
||||||
|
|
||||||
// try special name
|
SelectionImages[2] = GetIcon(BUILTIN_SELECTION_SMALL);
|
||||||
SelectionImages[2].setEmpty();
|
SelectionImages[0] = GetIcon(BUILTIN_SELECTION_BIG);
|
||||||
SelectionImages[2].LoadXImage(ThemeDir, SelectionSmallFileName);
|
|
||||||
// then common name selection_small.png
|
|
||||||
if (SelectionImages[2].isEmpty()){
|
|
||||||
SelectionImages[2] = GetIcon(BUILTIN_SELECTION_SMALL);
|
|
||||||
}
|
|
||||||
// now the big selection
|
|
||||||
SelectionImages[0].setEmpty();
|
|
||||||
Status = SelectionImages[0].LoadXImage(ThemeDir, SelectionBigFileName);
|
|
||||||
// then common name selection_small.png
|
|
||||||
if (EFI_ERROR(Status)){
|
|
||||||
SelectionImages[0] = GetIcon(BUILTIN_SELECTION_BIG);
|
|
||||||
}
|
|
||||||
// else use small selection
|
|
||||||
if (SelectionImages[0].isEmpty()) {
|
|
||||||
SelectionImages[0] = SelectionImages[2]; //use same selection if OnTop for example
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BootCampStyle) {
|
if (BootCampStyle) {
|
||||||
// load indicator selection image
|
SelectionImages[4] = GetIcon(BUILTIN_ICON_SELECTION);
|
||||||
SelectionImages[4].setEmpty();
|
|
||||||
Status = SelectionImages[4].LoadXImage(ThemeDir, SelectionIndicatorName);
|
|
||||||
if (EFI_ERROR(Status)) {
|
|
||||||
Status = SelectionImages[4].LoadXImage(ThemeDir, "selection_indicator");
|
|
||||||
}
|
|
||||||
if (EFI_ERROR(Status)){
|
|
||||||
SelectionImages[4] = GetIcon(BUILTIN_ICON_SELECTION);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if (EFI_ERROR(Status)) {
|
|
||||||
INTN ScaledIndicatorSize = (INTN)(INDICATOR_SIZE * Scale);
|
|
||||||
SelectionImages[4].EnsureImageSize(ScaledIndicatorSize, ScaledIndicatorSize, MenuBackgroundPixel);
|
|
||||||
SelectionImages[4].Fill(StdBackgroundPixel);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//and buttons
|
//and buttons
|
||||||
|
Loading…
Reference in New Issue
Block a user