Fix compilation.

This commit is contained in:
jief 2020-03-18 09:39:11 +03:00
parent 5ed385d3fa
commit 255c331069
8 changed files with 73 additions and 43 deletions

View File

@ -475,15 +475,15 @@ void XImage::Draw(INTN x, INTN y, float scale)
}
}
EFI_STATUS XImage::LoadImage(EFI_FILE *BaseDir, XStringW& FileName)
EFI_STATUS XImage::LoadImage(EFI_FILE *BaseDir, const XStringW& FileName)
{
EFI_STATUS Status = EFI_NOT_FOUND;
UINT8 *FileData = NULL;
UINTN FileDataLength = 0;
if (TypeSVG) {
return EFI_SUCCESS;
}
// if (TypeSVG) {
// return EFI_SUCCESS;
// }
if (BaseDir == NULL || FileName.isEmpty())
return EFI_NOT_FOUND;
@ -504,3 +504,21 @@ EFI_STATUS XImage::LoadImage(EFI_FILE *BaseDir, XStringW& FileName)
return Status;
}
void XImage::EnsureImageSize(IN INTN Width, IN INTN Height, IN EG_PIXEL *Color)
{
EG_IMAGE *NewImage;
if (isEmpty())
return;
if (GetWidth() == (UINTN)Width && GetHeight() == (UINTN)Height) // should we type UGAWidth and UGAHeight as UINTN to avoid cast ?
return;
NewImage = egCreateFilledImage(Width, Height, true, Color); // TODO : import that method to directly deal with XImage
if (NewImage == NULL) {
return; // panic instead ?
}
Compose(0, 0, NewImage, false);
egFreeImage(NewImage);
}

View File

@ -13,6 +13,7 @@ extern "C" {
}
#include "../cpp_foundation/XToolsCommon.h"
#include "../cpp_foundation/XArray.h"
#include "../cpp_foundation/XStringW.h"
#include "../libeg/libeg.h"
//#include "lodepng.h"
//
@ -91,7 +92,9 @@ public:
void Draw(INTN x, INTN y, float scale);
void DrawWithoutCompose(INTN x, INTN y, UINTN width = 0, UINTN height = 0);
EFI_STATUS LoadImage(EFI_FILE *Dir, XStringW FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name);
EFI_STATUS LoadImage(EFI_FILE *Dir, const XStringW& FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name);
void EnsureImageSize(IN INTN Width, IN INTN Height, IN EG_PIXEL *Color);
};
#endif //__XSTRINGW_H__

View File

@ -7,6 +7,8 @@ extern "C" {
}
#include "libegint.h"
#include "../refit/screen.h"
#include "XTheme.h"
CONST CHAR8* IconsNames[] = {
@ -68,7 +70,7 @@ CONST CHAR8* IconsNames[] = {
Icon::Icon(INTN Index) : Image(0), ImageNight(0)
{
Id = Index;
Name = XString(IconsNames[Index]);
Name.takeValueFrom(IconsNames[Index]);
}
Icon::~Icon() {}
@ -225,8 +227,8 @@ void XTheme::ClearScreen() //and restore background and banner
if (!(HideUIFlags & HIDEUI_FLAG_BANNER)) {
//Banner image prepared before
if (!Banner.isEmpty()) {
BannerPlace.Width = Banner->Width;
BannerPlace.Height = (BanHeight >= Banner->Height) ? (INTN)Banner->Height : BanHeight;
BannerPlace.Width = Banner.GetWidth();
BannerPlace.Height = (BanHeight >= Banner.GetHeight()) ? Banner.GetHeight() : BanHeight;
BannerPlace.XPos = BannerPosX;
BannerPlace.YPos = BannerPosY;
if (!TypeSVG) {
@ -239,13 +241,13 @@ void XTheme::ClearScreen() //and restore background and banner
BannerPlace.XPos = HybridRepositioning(BannerEdgeHorizontal, BannerPosX, BannerPlace.Width, UGAWidth, ThemeDesignWidth );
BannerPlace.YPos = HybridRepositioning(BannerEdgeVertical, BannerPosY, BannerPlace.Height, UGAHeight, ThemeDesignHeight);
// Check if banner is required to be nudged.
BannerPlace.XPos = CalculateNudgePosition(BannerPlace.XPos, BannerNudgeX, Banner->Width, UGAWidth);
BannerPlace.YPos = CalculateNudgePosition(BannerPlace.YPos, BannerNudgeY, Banner->Height, UGAHeight);
BannerPlace.XPos = CalculateNudgePosition(BannerPlace.XPos, BannerNudgeX, Banner.GetWidth(), UGAWidth);
BannerPlace.YPos = CalculateNudgePosition(BannerPlace.YPos, BannerNudgeY, Banner.GetHeight(), UGAHeight);
// DBG("banner position new style\n");
} else {
// Use rEFIt default (no placement values speicifed)
BannerPlace.XPos = (UGAWidth - Banner->Width) >> 1;
BannerPlace.YPos = (BanHeight >= Banner->Height) ? (BanHeight - Banner->Height) : 0;
BannerPlace.XPos = (UGAWidth - Banner.GetWidth()) >> 1;
BannerPlace.YPos = (BanHeight >= Banner.GetHeight()) ? (BanHeight - Banner.GetHeight()) : 0;
// DBG("banner position old style\n");
}
}
@ -254,14 +256,14 @@ void XTheme::ClearScreen() //and restore background and banner
}
//Then prepare Background from BigBack
if (!Background.isEmpty() && (Background.GetWidth() != UGAWidth || Background.GetHeight() != UGAHeight)) {
if (!Background.isEmpty() && (Background.GetWidth() != (UINTN)UGAWidth || Background.GetHeight() != (UINTN)UGAHeight)) { // should we type UGAWidth and UGAHeight as UINTN to avoid cast ?
// Resolution changed
Background.setEmpty();
}
if (Background.isEmpty()) {
Background = XImage(UGAWidth, UGAHeight);
Background.Fill(&BlueBackgroundPixel);
Background.Fill((EFI_GRAPHICS_OUTPUT_BLT_PIXEL&)BlueBackgroundPixel);
}
if (!BigBack.isEmpty()) {
switch (BackgroundScale) {
@ -269,6 +271,7 @@ void XTheme::ClearScreen() //and restore background and banner
Background.CopyScaled(BigBack, Scale);
break;
case imCrop:
{
INTN x = UGAWidth - BigBack.GetWidth();
INTN x1, x2, y1, y2;
if (x >= 0) {
@ -296,16 +299,19 @@ void XTheme::ClearScreen() //and restore background and banner
x, y, Background.GetWidth(), BigBack.GetWidth()); */
Background.Compose(x, y, BigBack, true);
break;
}
case imTile:
x = (BigBack.GetWidth() * ((UGAWidth - 1) / BigBack.GetWidth() + 1) - UGAWidth) >> 1;
y = (BigBack.GetHeight() * ((UGAHeight - 1) / BigBack.GetHeight() + 1) - UGAHeight) >> 1;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* p1 = Background.GetPixelPtr(0, 0)
for (j = 0; j < UGAHeight; j++) {
for (i = 0; i < UGAWidth; i++) {
{
INTN x = (BigBack.GetWidth() * ((UGAWidth - 1) / BigBack.GetWidth() + 1) - UGAWidth) >> 1;
INTN y = (BigBack.GetHeight() * ((UGAHeight - 1) / BigBack.GetHeight() + 1) - UGAHeight) >> 1;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* p1 = Background.GetPixelPtr(0, 0);
for (INTN j = 0; j < UGAHeight; j++) {
for (INTN i = 0; i < UGAWidth; i++) {
*p1++ = BigBack.GetPixel((i + x) % BigBack.GetWidth(), (j + y) % BigBack.GetHeight());
}
}
break;
}
case imNone:
default:
// already scaled
@ -314,7 +320,7 @@ void XTheme::ClearScreen() //and restore background and banner
}
Background.Draw(0, 0, 1.f);
//then draw banner
if (Banner) {
if (!Banner.isEmpty()) {
Banner.Draw(BannerPlace.XPos, BannerPlace.YPos, Scale);
}
@ -335,7 +341,7 @@ void XTheme::InitSelection()
}
// load small selection image
if (GlobalConfig.SelectionSmallFileName != NULL){
SelectionImages[2].LoadImage(ThemeDir, SelectionSmallFileName.data());
SelectionImages[2].LoadImage(ThemeDir, SelectionSmallFileName);
}
if (SelectionImages[2].isEmpty()){
// SelectionImages[2] = BuiltinIcon(BUILTIN_SELECTION_SMALL);
@ -353,23 +359,20 @@ void XTheme::InitSelection()
// load big selection image
if (!GlobalConfig.TypeSVG && GlobalConfig.SelectionBigFileName != NULL) {
SelectionImages[0] = egLoadImage(ThemeDir, GlobalConfig.SelectionBigFileName, FALSE);
SelectionImages[0] = egEnsureImageSize(SelectionImages[0],
row0TileSize, row0TileSize,
&MenuBackgroundPixel);
SelectionImages[0].EnsureImageSize(row0TileSize, row0TileSize, &MenuBackgroundPixel);
}
if (SelectionImages[0] == NULL) {
if (SelectionImages[0].isEmpty()) {
// calculate big selection image from small one
SelectionImages[0] = BuiltinIcon(BUILTIN_SELECTION_BIG);
SelectionImages[0]->HasAlpha = FALSE; // support transparensy for selection icons
// SelectionImages[0]->HasAlpha = FALSE; // support transparensy for selection icons
CopyMem(&BlueBackgroundPixel, &StdBackgroundPixel, sizeof(EG_PIXEL));
if (SelectionImages[0] == NULL) {
egFreeImage(SelectionImages[2]);
SelectionImages[2] = NULL;
if (SelectionImages[0].isEmpty()) {
SelectionImages[2].setEmpty();
return;
}
if (GlobalConfig.SelectionOnTop) {
SelectionImages[0]->HasAlpha = TRUE;
SelectionImages[2]->HasAlpha = TRUE;
// SelectionImages[0]->HasAlpha = TRUE; // TODO ?
// SelectionImages[2]->HasAlpha = TRUE;
}
}
@ -379,13 +382,13 @@ void XTheme::InitSelection()
if (GlobalConfig.SelectionIndicatorName != NULL) {
SelectionImages[4] = egLoadImage(ThemeDir, GlobalConfig.SelectionIndicatorName, TRUE);
}
if (!SelectionImages[4]) {
if (!SelectionImages[4].isEmpty()) {
SelectionImages[4] = egDecodePNG(ACCESS_EMB_DATA(emb_selection_indicator), ACCESS_EMB_SIZE(emb_selection_indicator), TRUE);
}
INTN ScaledIndicatorSize = (INTN)(INDICATOR_SIZE * GlobalConfig.Scale);
SelectionImages[4] = egEnsureImageSize(SelectionImages[4], ScaledIndicatorSize, ScaledIndicatorSize, &MenuBackgroundPixel);
if (!SelectionImages[4]) {
SelectionImages[4].EnsureImageSize(ScaledIndicatorSize, ScaledIndicatorSize, &MenuBackgroundPixel);
if (SelectionImages[4].isEmpty()) {
SelectionImages[4] = egCreateFilledImage(ScaledIndicatorSize, ScaledIndicatorSize,
TRUE, &StdBackgroundPixel);

View File

@ -7,13 +7,15 @@
#include "libeg.h"
#include "XImage.h"
#define INDICATOR_SIZE (52)
class Icon
{
public:
INTN Id; //for example BUILTIN_ICON_POINTER
XString Name; //for example "os_moja", "vol_internal"
XImage ImageNight;
XStringW Name; //for example "os_moja", "vol_internal"
XImage Image;
XImage ImageNight;
Icon(INTN Id);
~Icon();
@ -74,7 +76,7 @@ public:
float CentreShift;
INTN row0TileSize;
INTN row1TileSize;
INTN BanHeight;
UINTN BanHeight;
INTN LayoutHeight; //it was 376 before
void Init();

View File

@ -386,7 +386,7 @@ VOID egInitScreen(IN BOOLEAN SetMaxResolution)
// if it not the first run, just restore resolution
if (egScreenWidth != 0 && egScreenHeight != 0) {
// Resolution = PoolPrint(L"%dx%d",egScreenWidth,egScreenHeight);
XStringW Resolution = WPrintf("%lux%lu", egScreenWidth, egScreenHeight);
XStringW Resolution = WPrintf("%llux%llu", egScreenWidth, egScreenHeight);
if (Resolution) {
Status = egSetScreenResolution(Resolution.data());
// FreePool(Resolution);

View File

@ -47,6 +47,7 @@
#include "menu.h"
#include "screen.h"
#include "../cpp_foundation/XString.h"
#include "../libeg/XTheme.h"
#ifndef DEBUG_ALL
#define DEBUG_MENU 1
@ -147,7 +148,6 @@ INTN ScrollbarYMovement;
#define TILE1_XSPACING (8)
//#define TILE_YSPACING (24)
#define ROW0_SCROLLSIZE (100)
#define INDICATOR_SIZE (52)
//EG_IMAGE *SelectionImages[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
//EG_IMAGE *Buttons[4] = {NULL, NULL, NULL, NULL};

View File

@ -63,12 +63,12 @@ static VOID SwitchToGraphics(VOID);
static VOID DrawScreenHeader(IN CONST CHAR16 *Title);
static VOID UpdateConsoleVars(VOID);
static INTN ConvertEdgeAndPercentageToPixelPosition(INTN Edge, INTN DesiredPercentageFromEdge, INTN ImageDimension, INTN ScreenDimension);
static INTN CalculateNudgePosition(INTN Position, INTN NudgeValue, INTN ImageDimension, INTN ScreenDimension);
INTN CalculateNudgePosition(INTN Position, INTN NudgeValue, INTN ImageDimension, INTN ScreenDimension);
//INTN RecalculateImageOffset(INTN AnimDimension, INTN ValueToScale, INTN ScreenDimensionToFit, INTN ThemeDesignDimension);
static BOOLEAN IsImageWithinScreenLimits(INTN Value, INTN ImageDimension, INTN ScreenDimension);
static INTN RepositionFixedByCenter(INTN Value, INTN ScreenDimension, INTN DesignScreenDimension);
static INTN RepositionRelativeByGapsOnEdges(INTN Value, INTN ImageDimension, INTN ScreenDimension, INTN DesignScreenDimension);
static INTN HybridRepositioning(INTN Edge, INTN Value, INTN ImageDimension, INTN ScreenDimension, INTN DesignScreenDimension);
INTN HybridRepositioning(INTN Edge, INTN Value, INTN ImageDimension, INTN ScreenDimension, INTN DesignScreenDimension);
EG_IMAGE * LoadSvgFrame(INTN i);
@ -889,7 +889,7 @@ static INTN ConvertEdgeAndPercentageToPixelPosition(INTN Edge, INTN DesiredPerce
return 0xFFFF; // to indicate that wrong edge was specified.
}
static INTN CalculateNudgePosition(INTN Position, INTN NudgeValue, INTN ImageDimension, INTN ScreenDimension)
INTN CalculateNudgePosition(INTN Position, INTN NudgeValue, INTN ImageDimension, INTN ScreenDimension)
{
INTN value=Position;
@ -916,7 +916,7 @@ static INTN RepositionRelativeByGapsOnEdges(INTN Value, INTN ImageDimension, INT
return (Value * (ScreenDimension - ImageDimension) / (DesignScreenDimension - ImageDimension));
}
static INTN HybridRepositioning(INTN Edge, INTN Value, INTN ImageDimension, INTN ScreenDimension, INTN DesignScreenDimension)
INTN HybridRepositioning(INTN Edge, INTN Value, INTN ImageDimension, INTN ScreenDimension, INTN DesignScreenDimension)
{
INTN pos, posThemeDesign;

View File

@ -23,3 +23,7 @@ VOID BltImageAlpha(IN EG_IMAGE *Image, IN INTN XPos, IN INTN YPos, IN EG_PIXEL *
//VOID BltImageComposite(IN EG_IMAGE *BaseImage, IN EG_IMAGE *TopImage, IN INTN XPos, IN INTN YPos);
VOID BltImageCompositeBadge(IN EG_IMAGE *BaseImage, IN EG_IMAGE *TopImage, IN EG_IMAGE *BadgeImage, IN INTN XPos, IN INTN YPos, INTN Scale);
//VOID BltImageCompositeIndicator(IN EG_IMAGE *BaseImage, IN EG_IMAGE *TopImage, IN INTN XPos, IN INTN YPos, INTN Scale);
INTN HybridRepositioning(INTN Edge, INTN Value, INTN ImageDimension, INTN ScreenDimension, INTN DesignScreenDimension);
INTN CalculateNudgePosition(INTN Position, INTN NudgeValue, INTN ImageDimension, INTN ScreenDimension);