This commit is contained in:
Jief L 2020-03-29 09:54:31 +03:00
commit d093af9b01
4 changed files with 99 additions and 112 deletions

View File

@ -37,6 +37,7 @@
#if USE_XTHEME
#include "XTheme.h"
extern XTheme ThemeX;
extern CONST CHAR8* IconsNames[];
#endif
@ -466,54 +467,54 @@ EFI_STATUS ParseSVGXTheme(CONST CHAR8* buffer, TagPtr * dict)
DBG(" parsed banner->width=%lld\n", ThemeX.Banner.GetWidth());
// --- Make other icons
INTN i = BUILTIN_ICON_FUNC_ABOUT;
CHAR8 *IconName;
while (BuiltinIconTable[i].Path) {
for (INTN i = BUILTIN_ICON_FUNC_ABOUT; i < BUILTIN_CHECKBOX_CHECKED; ++i) {
if (i == BUILTIN_ICON_BANNER) {
i++;
continue;
}
CONST CHAR16 *IconPath = BuiltinIconTable[i].Path;
// DBG("next table icon=%ls\n", IconPath);
CONST CHAR16 *ptr = StrStr(IconPath, L"\\");
if (!ptr) {
ptr = IconPath;
} else {
ptr++;
}
// DBG("next icon=%ls Len=%d\n", ptr, StrLen(ptr));
UINTN Size = StrLen(ptr)+1;
IconName = (__typeof__(IconName))AllocateZeroPool(Size);
UnicodeStrToAsciiStrS(ptr, IconName, Size);
// DBG("search for icon name %s\n", IconName);
CHAR8 IconNight[64];
AsciiStrCpyS(IconNight, 64, IconName);
AsciiStrCatS(IconNight, 64, "_night");
Status = EFI_NOT_FOUND;
if (!DayLight) {
Status = ParseSVGIcon(mainParser, i, IconNight, Scale, &BuiltinIconTable[i].Image);
}
if (EFI_ERROR(Status)) {
Status = ParseSVGIcon(mainParser, i, IconName, Scale, &BuiltinIconTable[i].Image);
}
if (EFI_ERROR(Status)) {
DBG(" icon %lld not parsed take common %ls\n", i, BuiltinIconTable[i].Path);
if ((i >= BUILTIN_ICON_VOL_EXTERNAL) && (i <= BUILTIN_ICON_VOL_INTERNAL_REC)) {
if (BuiltinIconTable[BUILTIN_ICON_VOL_INTERNAL].Image) {
BuiltinIconTable[i].Image = egCopyImage(BuiltinIconTable[BUILTIN_ICON_VOL_INTERNAL].Image);
}
}
}
if (i == BUILTIN_SELECTION_BIG) {
DBG("icon main size=[%lld,%lld]\n", BuiltinIconTable[i].Image->Width,
BuiltinIconTable[i].Image->Height);
}
i++;
FreePool(IconName);
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);
}
//selection for bootcamp style
Status = EFI_NOT_FOUND;
if (!DayLight) {
Status = ParseSVGXIcon(mainParser, BUILTIN_ICON_SELECTION, XString("selection_indicator_night"), Scale, SelectionImages[4]);
}
if (EFI_ERROR(Status)) {
Status = ParseSVGXIcon(mainParser, BUILTIN_ICON_SELECTION, XString("selection_indicator"), Scale, SelectionImages[4]);
}
//banner animation
GUI_ANIME *Anime = (__typeof__(Anime))AllocateZeroPool (sizeof(GUI_ANIME));
Anime->ID = 1; //main screen
//there is no Anime->Path in vectors
Anime->Frames = NumFrames;
Anime->FrameTime = FrameTime;
Anime->Next = GuiAnime;
Anime->FilmX = INITVALUE;
Anime->FilmY = INITVALUE;
Anime->NudgeX = INITVALUE;
Anime->NudgeY = INITVALUE;
GuiAnime = Anime;
nsvgDeleteRasterizer(rast);
*dict = (__typeof_am__(*dict))AllocateZeroPool(sizeof(TagStruct));
(*dict)->type = kTagTypeNone;
ThemeX.TypeSVG = TRUE;
ThemeX.ThemeDesignHeight = (int)SVGimage->height;
ThemeX.ThemeDesignWidth = (int)SVGimage->width;
if (ThemeX.SelectionOnTop) {
ThemeX.row0TileSize = (INTN)(144.f * Scale);
ThemeX.row1TileSize = (INTN)(64.f * Scale);
ThemeX.MainEntriesSize = (INTN)(128.f * Scale);
}
DBG("parsing svg theme finished\n");
return Status;
}
#else
@ -551,22 +552,6 @@ EFI_STATUS ParseSVGTheme(CONST CHAR8* buffer, TagPtr * dict)
DBG("theme contains font-family=%s\n", mainParser->font->fontFamily);
}
#if 0
// --- Create rastered font
if (fontSVG) {
if (p->font) {
FontHeight = (int)(textFace[2].size * Scale); //as in MenuRows
DBG("Menu font scaled height=%d color=%X\n", FontHeight, textFace[2].color);
}
if (!FontHeight) FontHeight = 16; //xxx
if (fontSVG->fontFamily[0] < 0x30) {
AsciiStrCpyS(fontSVG->fontFamily, 64, fontSVG->id);
}
RenderSVGfont(fontSVG, p->fontColor);
DBG("font %s parsed\n", fontSVG->fontFamily);
}
#endif
// --- Make background
BackgroundImage = egCreateFilledImage(UGAWidth, UGAHeight, TRUE, &BlackPixel);
if (BigBack) {
@ -712,22 +697,7 @@ EFI_STATUS ParseSVGTheme(CONST CHAR8* buffer, TagPtr * dict)
GlobalConfig.MainEntriesSize = (INTN)(128.f * Scale);
}
DBG("parsing theme finish\n");
#if 0 //dump fonts
{
NSVGfont *fontSVG = NULL;
NSVGfontChain *fontChain = fontsDB;
while (fontChain) {
fontSVG = fontChain->font;
if (fontSVG) {
DBG("probe fontFamily=%s fontStyle=%c\n", fontSVG->fontFamily, fontSVG->fontStyle);
}
else {
DBG("nextChain is empty\n");
}
fontChain = fontChain->next;
}
}
#endif
return EFI_SUCCESS;
}

View File

@ -57,7 +57,7 @@ CONST CHAR8* IconsNames[] = {
"vol_internal_ntfs",
"vol_internal_ext3" ,
"vol_recovery",//21
// not used?
// not used? will be skipped while theme parsing
"logo",
"selection_small",
"selection_big", //BUILTIN_SELECTION_BIG=24 we keep this numeration
@ -74,7 +74,7 @@ CONST CHAR8* IconsNames[] = {
"os_sierra",
"os_hsierra",
"os_moja", //11
"os_cata", //12
"os_cata", //12 //there is no reserve for 10.16, next oses should be added to the end of the list
"os_linux",
"os_ubuntu",
"os_suse",
@ -82,20 +82,16 @@ CONST CHAR8* IconsNames[] = {
"os_freedos",
"os_win",
"os_vista",
"radio_button", //20
"radio_button", //20+25
"radio_button_selected",
"checkbox", //22
"checkbox_checked",
"scrollbar_background", //24
"scrollbar_holder"
"scrollbar_background", //24 - present here for SVG theme but should be done more common way
"scrollbar_holder",
//other oses will be added below
""
};
Icon::Icon(INTN Index) : Image(0), ImageNight(0)
{
Id = Index;
Name.takeValueFrom(IconsNames[Index]);
}
Icon::~Icon() {}
XTheme::XTheme() {
@ -165,17 +161,23 @@ void XTheme::Init()
row1TileSize = 64;
}
/*
* what if the icon is not found or name is wrong?
* probably it whould return Empty image
* Image.isEmpty() == true
*/
XImage& XTheme::GetIcon(const char* Name)
{
return GetIcon(XStringW().takeValueFrom(Name));
return GetIcon(XString().takeValueFrom(Name));
}
XImage& XTheme::GetIcon(const XStringW& Name)
XImage& XTheme::GetIcon(const XString& Name)
{
XImage NullIcon();
XImage* TheIcon = NULL;
for (size_t i = 0; i < Icons.size(); i++)
{
if (Icons[i].Name == Name)
if (Icons[i].Name == Name) //night icon has same name as daylight icon
{
if (!Daylight) {
TheIcon = &Icons[i].ImageNight;
@ -183,10 +185,10 @@ XImage& XTheme::GetIcon(const XStringW& Name)
if (TheIcon == NULL || (*TheIcon).isEmpty()) { //if daylight or night icon absent
TheIcon = &Icons[i].Image;
}
break;
return *TheIcon;;
}
}
return *TheIcon;
return NullIcon; //return pointer to XImage? Or XImage copy?
}
XImage& XTheme::GetIcon(INTN Id)
@ -205,7 +207,7 @@ XImage& XTheme::GetIcon(INTN Id)
break;
}
}
return *TheIcon;
return TheIcon;
}
void XTheme::AddIcon(Icon& NewIcon)
@ -223,11 +225,11 @@ void XTheme::AddIcon(Icon& NewIcon)
ImageNight.FromPNG(ACCESS_EMB_DATA(dark), ACCESS_EMB_SIZE(dark)); \
}
Icon::Icon(INTN Index, BOOLEAN Embedded) : Image(0), ImageNight(0)
Icon::Icon(INTN Index) : Image(0), ImageNight(0)
{
Id = Index;
if (Index < BUILTIN_ICON_FUNC_ABOUT || Index >=BUILTIN_ICON_COUNT || !Embedded) {
Name.setEmpty();
Name.setEmpty();
if (Index < BUILTIN_ICON_FUNC_ABOUT || Index > BUILTIN_CHECKBOX_CHECKED) {
return;
}
Name.takeValueFrom(IconsNames[Index]);
@ -299,9 +301,26 @@ Icon::Icon(INTN Index, BOOLEAN Embedded) : Image(0), ImageNight(0)
case BUILTIN_ICON_VOL_INTERNAL_REC:
DEC_BUILTIN_ICON(BUILTIN_ICON_VOL_INTERNAL_REC, emb_vol_internal_recovery)
break;
case BUILTIN_RADIO_BUTTON:
DEC_BUILTIN_ICON(BUILTIN_RADIO_BUTTON, emb_radio_button)
break;
case BUILTIN_RADIO_BUTTON_SELECTED:
DEC_BUILTIN_ICON(BUILTIN_RADIO_BUTTON_SELECTED, emb_radio_button_selected)
break;
case BUILTIN_CHECKBOX:
DEC_BUILTIN_ICON(BUILTIN_CHECKBOX, emb_checkbox)
break;
case BUILTIN_CHECKBOX_CHECKED:
DEC_BUILTIN_ICON(BUILTIN_CHECKBOX_CHECKED, emb_checkbox_checked)
break;
"radio_button", //20+25
"radio_button_selected",
"checkbox", //22
"checkbox_checked",
default:
Name.setEmpty();
// Image.setEmpty(); //done by ctor?
break;
}
//something to do else?
@ -315,6 +334,7 @@ void XTheme::FillByEmbedded()
Icon NewIcon(i, true);
Icons.AddCopy(NewIcon);
}
//radio buttons will be inited by InitSelection()
}
void XTheme::ClearScreen() //and restore background and banner
@ -424,7 +444,7 @@ void XTheme::ClearScreen() //and restore background and banner
}
void XTheme::InitSelection()
void XTheme::InitSelection() //for PNG theme
{
EFI_STATUS Status;
if (!AllowGraphicsMode)
@ -439,10 +459,10 @@ void XTheme::InitSelection()
return;
}
// load small selection image
if (SelectionSmallFileName.isEmpty()){
if (!TypeSVG && SelectionImages[2].isEmpty()){
SelectionImages[2].LoadXImage(ThemeDir, SelectionSmallFileName);
}
if (SelectionImages[2].isEmpty()){
if (!TypeSVG && SelectionImages[2].isEmpty()){
// SelectionImages[2] = BuiltinIcon(BUILTIN_SELECTION_SMALL);
// SelectionImages[2]->HasAlpha = FALSE; // support transparensy for selection icons
if (Daylight) {
@ -460,11 +480,11 @@ void XTheme::InitSelection()
} */
// load big selection image
if (!TypeSVG && !SelectionBigFileName.isEmpty()) {
if (!TypeSVG && SelectionImages[0].isEmpty()) {
SelectionImages[0].LoadXImage(ThemeDir, SelectionBigFileName);
// SelectionImages[0].EnsureImageSize(row0TileSize, row0TileSize, &MenuBackgroundPixel);
}
if (SelectionImages[0].isEmpty()) {
if (!TypeSVG && SelectionImages[0].isEmpty()) {
// calculate big selection image from small one
// SelectionImages[0] = BuiltinIcon(BUILTIN_SELECTION_BIG);
if (Daylight) {
@ -487,7 +507,7 @@ void XTheme::InitSelection()
// BootCampStyle indicator image
if (BootCampStyle) {
// load indicator selection image
if (!SelectionIndicatorName.isEmpty()) {
if (!TypeSVG && SelectionImages[4].isEmpty()) {
SelectionImages[4].LoadXImage(ThemeDir, SelectionIndicatorName);
}
if (!SelectionImages[4].isEmpty()) {
@ -565,19 +585,13 @@ void XTheme::InitSelection()
//use this only for PNG theme
void XTheme::FillByDir() //assume ThemeDir is defined by InitTheme() procedure
{
for (INTN i = 0; i < BUILTIN_ICON_COUNT; ++i) {
Icon NewIcon(i, true); //initialize with embedded but further replace by loaded
for (INTN i = 0; i <= BUILTIN_CHECKBOX_CHECKED; ++i) {
Icon NewIcon(i); //initialize with embedded but further replace by loaded
NewIcon.Image.LoadXImage(ThemeDir, IconsNames[i]);
NewIcon.ImageNight.LoadXImage(ThemeDir, XStringWP(IconsNames[i]) + XStringWP("_night"));
Icons.AddCopy(NewIcon);
}
for (INTN i = BUILTIN_ICON_COUNT; i < 45; ++i) {
Icon NewIcon(i); //there is no embedded
NewIcon.Image.LoadXImage(ThemeDir, IconsNames[i]); //all os_***
Icons.AddCopy(NewIcon);
}
InitSelection(); //initialize selections, buttons
//load banner and background
@ -654,7 +668,7 @@ void XTheme::InitBar()
}
}
//TODO it must be somewhere in InitScroll - Scrfeen function
//TODO it must be somewhere in InitScroll - Screen function
if (!TypeSVG) {
UpButton.Width = ScrollWidth; // 16
UpButton.Height = ScrollButtonsHeight; // 20

View File

@ -15,12 +15,11 @@ class Icon
{
public:
INTN Id; //for example BUILTIN_ICON_POINTER
XStringW Name; //for example "os_moja", "vol_internal"
XString Name; //for example "os_moja", "vol_internal"
XImage Image;
XImage ImageNight;
Icon(INTN Id);
Icon(INTN Index, BOOLEAN Embedded);
~Icon();
};

View File

@ -589,6 +589,10 @@ EG_IMAGE * GetSmallHover(IN UINTN Id);
#define BUILTIN_SELECTION_SMALL (23)
#define BUILTIN_SELECTION_BIG (24)
#define BUILTIN_ICON_COUNT (25)
#define BUILTIN_RADIO_BUTTON (45)
#define BUILTIN_RADIO_BUTTON_SELECTED (46)
#define BUILTIN_CHECKBOX (47)
#define BUILTIN_CHECKBOX_CHECKED (48)
#define BUILTIN_ICON_BACKGROUND (100)
#define BUILTIN_ICON_SELECTION (101)
#define BUILTIN_ICON_ANIME (102)