mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-10 09:40:53 +01:00
XIcon::GetBest now returns a reference, which save time and memory.
Added some const. Remove GetIconP from XTheme.
This commit is contained in:
parent
dbb93abca9
commit
8de61a22fb
@ -210,7 +210,7 @@ typedef
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT)(
|
(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT)(
|
||||||
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
|
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
|
||||||
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
|
IN JCONST EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
|
||||||
IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
|
IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
|
||||||
IN UINTN SourceX,
|
IN UINTN SourceX,
|
||||||
IN UINTN SourceY,
|
IN UINTN SourceY,
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
#include "../../../PosixCompilation/xcode_utf_fixed.h"
|
#include "../../../PosixCompilation/xcode_utf_fixed.h"
|
||||||
|
|
||||||
#include "../../../rEFIt_UEFI/cpp_unit_test/all_tests.h"
|
#include "../../../rEFIt_UEFI/cpp_unit_test/all_tests.h"
|
||||||
#include "../../../rEFIt_UEFI/cpp_foundation/XToolsCommon.h"
|
//#include "../../../rEFIt_UEFI/cpp_foundation/XToolsCommon.h"
|
||||||
|
#include "../../../rEFIt_UEFI/libeg/XImage.h"
|
||||||
//#include "../../../rEFIt_UEFI/Platform/platformdata.h"
|
//#include "../../../rEFIt_UEFI/Platform/platformdata.h"
|
||||||
|
|
||||||
//class Boolean
|
//class Boolean
|
||||||
@ -34,6 +35,91 @@
|
|||||||
// void setValue(bool a) {flag = a;}
|
// void setValue(bool a) {flag = a;}
|
||||||
//};
|
//};
|
||||||
|
|
||||||
|
// The following is by no means a FULL solution!
|
||||||
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Property {
|
||||||
|
public:
|
||||||
|
Property(){}
|
||||||
|
operator const T& () const {
|
||||||
|
// Call override getter if we have it
|
||||||
|
if (getter) return getter();
|
||||||
|
return get();
|
||||||
|
}
|
||||||
|
const T& operator = (const T& other) {
|
||||||
|
// Call override setter if we have it
|
||||||
|
if (setter) return setter(other);
|
||||||
|
return set(other);
|
||||||
|
}
|
||||||
|
bool operator == (const T& other) const {
|
||||||
|
// Static cast makes sure our getter operator is called, so we could use overrides if those are in place
|
||||||
|
return static_cast<const T&>(*this) == other;
|
||||||
|
}
|
||||||
|
// Use this to always get without overrides, useful for use with overriding implementations
|
||||||
|
const T& get() const {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
// Use this to always set without overrides, useful for use with overriding implementations
|
||||||
|
const T& set(const T& other) {
|
||||||
|
return t = other;
|
||||||
|
}
|
||||||
|
// Assign getter and setter to these properties
|
||||||
|
std::function<const T&()> getter;
|
||||||
|
std::function<const T&(const T&)> setter;
|
||||||
|
private:
|
||||||
|
T t;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Basic usage, no override
|
||||||
|
struct Test {
|
||||||
|
Property<int> prop;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Override getter and setter
|
||||||
|
struct TestWithOverride {
|
||||||
|
TestWithOverride(){
|
||||||
|
prop.setter = [&](const int& other){
|
||||||
|
std::cout << "Custom setter called" << std::endl;
|
||||||
|
return prop.set(other);
|
||||||
|
};
|
||||||
|
prop.setter = std::bind(&TestWithOverride::setProp,this,std::placeholders::_1);
|
||||||
|
prop.getter = std::bind(&TestWithOverride::getProp,this);
|
||||||
|
}
|
||||||
|
Property<int> prop;
|
||||||
|
private:
|
||||||
|
const int& getProp() const {
|
||||||
|
std::cout << "Custom getter called" << std::endl;
|
||||||
|
return prop.get();
|
||||||
|
}
|
||||||
|
const int& setProp(const int& other){
|
||||||
|
std::cout << "Custom setter called" << std::endl;
|
||||||
|
return prop.set(other);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class MyFloat {
|
||||||
|
public:
|
||||||
|
float f;
|
||||||
|
MyFloat() { f = 0.0f; }
|
||||||
|
MyFloat(float _f) : f(_f) {}
|
||||||
|
float get() { return 1; }
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
class MutableRef : public T {
|
||||||
|
public:
|
||||||
|
T* t;
|
||||||
|
const T& operator = (const T* other) {
|
||||||
|
t = other;
|
||||||
|
return *t;
|
||||||
|
}
|
||||||
|
operator T& () {
|
||||||
|
return *t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
extern "C" int main(int argc, const char * argv[])
|
extern "C" int main(int argc, const char * argv[])
|
||||||
{
|
{
|
||||||
@ -41,6 +127,36 @@ extern "C" int main(int argc, const char * argv[])
|
|||||||
(void)argv;
|
(void)argv;
|
||||||
setlocale(LC_ALL, "en_US"); // to allow printf unicode char
|
setlocale(LC_ALL, "en_US"); // to allow printf unicode char
|
||||||
|
|
||||||
|
MyFloat test = 5.0f;
|
||||||
|
|
||||||
|
MutableRef<MyFloat> Background;
|
||||||
|
|
||||||
|
Background = &test;
|
||||||
|
test = 6;
|
||||||
|
float test2 = Background.get();
|
||||||
|
|
||||||
|
Test t;
|
||||||
|
TestWithOverride t1;
|
||||||
|
t.prop = 1;
|
||||||
|
assert(t.prop == 1);
|
||||||
|
t1.prop = 1;
|
||||||
|
assert(t1.prop == 1);
|
||||||
|
/*
|
||||||
|
Expected output:
|
||||||
|
1. No aborts on assertions
|
||||||
|
2. Text:
|
||||||
|
Custom setter called
|
||||||
|
Custom getter called
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// xcode_utf_fixed_tests();
|
// xcode_utf_fixed_tests();
|
||||||
const int i = 2;
|
const int i = 2;
|
||||||
(void)i;
|
(void)i;
|
||||||
|
@ -142,6 +142,8 @@ UINT32 GetCrc32(UINT8 *Buffer, UINTN Size)
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef UNIT_TESTS_MACOS
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <Library/OcMemoryLib.h>
|
#include <Library/OcMemoryLib.h>
|
||||||
}
|
}
|
||||||
@ -155,6 +157,8 @@ void displayFreeMemory(const XString8& prefix)
|
|||||||
DebugLog(1, "--> %s: Firmware has %llu free pages (%llu in lower 4 GB)\n", prefix.c_str(), TotalMemory, LowMemory);
|
DebugLog(1, "--> %s: Firmware has %llu free pages (%llu in lower 4 GB)\n", prefix.c_str(), TotalMemory, LowMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
XBool haveError = false;
|
XBool haveError = false;
|
||||||
|
|
||||||
|
@ -130,9 +130,10 @@ extern XBool haveError;
|
|||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#ifndef UNIT_TESTS_MACOS
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void displayFreeMemory(const XString8& prefix);
|
void displayFreeMemory(const XString8& prefix);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _UTILS_H_
|
#endif // _UTILS_H_
|
||||||
|
@ -74,7 +74,7 @@ static LOCKED_GRAPHICS *LockedGraphics;
|
|||||||
// The screen lock
|
// The screen lock
|
||||||
static XBool ScreenIsLocked;
|
static XBool ScreenIsLocked;
|
||||||
|
|
||||||
static EFI_STATUS EFIAPI LockedGOPBlt(IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX, IN UINTN DestinationY, IN UINTN Width, IN UINTN Height, IN UINTN Delta OPTIONAL)
|
static EFI_STATUS EFIAPI LockedGOPBlt(IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX, IN UINTN DestinationY, IN UINTN Width, IN UINTN Height, IN UINTN Delta OPTIONAL)
|
||||||
{
|
{
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -120,13 +120,9 @@ void REFIT_MAINMENU_SCREEN::DrawMainMenuLabel(IN CONST XStringW& Text, IN INTN X
|
|||||||
INTN X = XPos - (TextWidth >> 1) - (BadgeDim + 16);
|
INTN X = XPos - (TextWidth >> 1) - (BadgeDim + 16);
|
||||||
INTN Y = YPos - ((BadgeDim - ThemeX->TextHeight) >> 1);
|
INTN Y = YPos - ((BadgeDim - ThemeX->TextHeight) >> 1);
|
||||||
Back.CopyRect(ThemeX->Background, X, Y);
|
Back.CopyRect(ThemeX->Background, X, Y);
|
||||||
XBool free = false;
|
const XImage& CurrSel = Entries[ScrollState.CurrentSelection].Image.GetBest(!Daylight);
|
||||||
XImage *CurrSel = Entries[ScrollState.CurrentSelection].Image.GetBest(!Daylight, &free);
|
Back.Compose(0, 0, CurrSel, false, BadgeDim/128.f);
|
||||||
Back.Compose(0, 0, *CurrSel, false, BadgeDim/128.f);
|
|
||||||
Back.DrawOnBack(X, Y, Back);
|
Back.DrawOnBack(X, Y, Back);
|
||||||
if (free) {
|
|
||||||
delete CurrSel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OldX = XPos;
|
OldX = XPos;
|
||||||
@ -238,8 +234,7 @@ void REFIT_MAINMENU_SCREEN::DrawMainMenuEntry(REFIT_ABSTRACT_MENU_ENTRY *Entry,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// const XImage& MainImage = (!ThemeX->Daylight && !MainIcon.ImageNight.isEmpty())? MainIcon.ImageNight : MainIcon.Image;
|
// const XImage& MainImage = (!ThemeX->Daylight && !MainIcon.ImageNight.isEmpty())? MainIcon.ImageNight : MainIcon.Image;
|
||||||
XBool free = false;
|
const XImage& MainImage = MainIcon.GetBest(!Daylight);
|
||||||
XImage *MainImage = MainIcon.GetBest(!Daylight, &free);
|
|
||||||
|
|
||||||
INTN CompWidth = (Entry->Row == 0) ? ThemeX->row0TileSize : ThemeX->row1TileSize;
|
INTN CompWidth = (Entry->Row == 0) ? ThemeX->row0TileSize : ThemeX->row1TileSize;
|
||||||
INTN CompHeight = CompWidth;
|
INTN CompHeight = CompWidth;
|
||||||
@ -264,9 +259,9 @@ void REFIT_MAINMENU_SCREEN::DrawMainMenuEntry(REFIT_ABSTRACT_MENU_ENTRY *Entry,
|
|||||||
XImage Back(CompWidth, CompHeight);
|
XImage Back(CompWidth, CompHeight);
|
||||||
Back.CopyRect(ThemeX->Background, XPos, YPos);
|
Back.CopyRect(ThemeX->Background, XPos, YPos);
|
||||||
|
|
||||||
INTN OffsetX = (CompWidth - MainImage->GetWidth()) / 2;
|
INTN OffsetX = (CompWidth - MainImage.GetWidth()) / 2;
|
||||||
OffsetX = (OffsetX > 0) ? OffsetX: 0;
|
OffsetX = (OffsetX > 0) ? OffsetX: 0;
|
||||||
INTN OffsetY = (CompHeight - MainImage->GetHeight()) / 2;
|
INTN OffsetY = (CompHeight - MainImage.GetHeight()) / 2;
|
||||||
OffsetY = (OffsetY > 0) ? OffsetY: 0;
|
OffsetY = (OffsetY > 0) ? OffsetY: 0;
|
||||||
|
|
||||||
INTN OffsetTX = (CompWidth - TopImage.GetWidth()) / 2;
|
INTN OffsetTX = (CompWidth - TopImage.GetWidth()) / 2;
|
||||||
@ -279,28 +274,24 @@ void REFIT_MAINMENU_SCREEN::DrawMainMenuEntry(REFIT_ABSTRACT_MENU_ENTRY *Entry,
|
|||||||
float composeScale = (ThemeX->NonSelectedGrey && !selected)? -1.f: 1.f;
|
float composeScale = (ThemeX->NonSelectedGrey && !selected)? -1.f: 1.f;
|
||||||
if(ThemeX->SelectionOnTop) {
|
if(ThemeX->SelectionOnTop) {
|
||||||
//place main image in centre. It may be OS or Drive
|
//place main image in centre. It may be OS or Drive
|
||||||
Back.Compose(OffsetX, OffsetY, *MainImage, false, composeScale);
|
Back.Compose(OffsetX, OffsetY, MainImage, false, composeScale);
|
||||||
} else {
|
} else {
|
||||||
Back.Compose(OffsetTX, OffsetTY, TopImage, false); //selection first
|
Back.Compose(OffsetTX, OffsetTY, TopImage, false); //selection first
|
||||||
Back.Compose(OffsetX, OffsetY, *MainImage, false, composeScale);
|
Back.Compose(OffsetX, OffsetY, MainImage, false, composeScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry->Place.XPos = XPos;
|
Entry->Place.XPos = XPos;
|
||||||
Entry->Place.YPos = YPos;
|
Entry->Place.YPos = YPos;
|
||||||
Entry->Place.Width = MainImage->GetWidth();
|
Entry->Place.Width = MainImage.GetWidth();
|
||||||
Entry->Place.Height = MainImage->GetHeight();
|
Entry->Place.Height = MainImage.GetHeight();
|
||||||
|
|
||||||
if (free) {
|
|
||||||
delete MainImage;
|
|
||||||
}
|
|
||||||
// place the badge image
|
// place the badge image
|
||||||
float fBadgeScale = ThemeX->BadgeScale/16.f;
|
float fBadgeScale = ThemeX->BadgeScale/16.f;
|
||||||
if ((Entry->Row == 0) && BadgeIcon && !BadgeIcon->isEmpty()) {
|
if ((Entry->Row == 0) && BadgeIcon && !BadgeIcon->isEmpty()) {
|
||||||
// const XImage& BadgeImage = (!ThemeX->Daylight && !BadgeIcon->ImageNight.isEmpty()) ? &BadgeIcon->ImageNight : BadgeImage = &BadgeIcon->Image;
|
// const XImage& BadgeImage = (!ThemeX->Daylight && !BadgeIcon->ImageNight.isEmpty()) ? &BadgeIcon->ImageNight : BadgeImage = &BadgeIcon->Image;
|
||||||
free = false;
|
const XImage& BadgeImage = BadgeIcon->GetBest(!Daylight);
|
||||||
XImage* BadgeImage = BadgeIcon->GetBest(!Daylight, &free);
|
INTN BadgeWidth = (INTN)(BadgeImage.GetWidth() * fBadgeScale);
|
||||||
INTN BadgeWidth = (INTN)(BadgeImage->GetWidth() * fBadgeScale);
|
INTN BadgeHeight = (INTN)(BadgeImage.GetHeight() * fBadgeScale);
|
||||||
INTN BadgeHeight = (INTN)(BadgeImage->GetHeight() * fBadgeScale);
|
|
||||||
|
|
||||||
if ((BadgeWidth + 8) < CompWidth && (BadgeHeight + 8) < CompHeight) {
|
if ((BadgeWidth + 8) < CompWidth && (BadgeHeight + 8) < CompHeight) {
|
||||||
|
|
||||||
@ -319,8 +310,7 @@ void REFIT_MAINMENU_SCREEN::DrawMainMenuEntry(REFIT_ABSTRACT_MENU_ENTRY *Entry,
|
|||||||
OffsetY += CompHeight - 8 - BadgeHeight;
|
OffsetY += CompHeight - 8 - BadgeHeight;
|
||||||
}
|
}
|
||||||
// DBG(" badge offset=[%lld,%lld]\n", OffsetX, OffsetY);
|
// DBG(" badge offset=[%lld,%lld]\n", OffsetX, OffsetY);
|
||||||
Back.Compose(OffsetX, OffsetY, *BadgeImage, false, fBadgeScale);
|
Back.Compose(OffsetX, OffsetY, BadgeImage, false, fBadgeScale);
|
||||||
if (free) delete BadgeImage;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1608,20 +1608,18 @@ void REFIT_MENU_SCREEN::GraphicsMenuStyle(IN UINTN Function, IN CONST CHAR16 *Pa
|
|||||||
if (!TitleImage.isEmpty()) {
|
if (!TitleImage.isEmpty()) {
|
||||||
INTN FilmXPos = (INTN)(EntriesPosX - (TitleImage.Image.GetWidth() + (int)(TITLEICON_SPACING * ThemeX->Scale)));
|
INTN FilmXPos = (INTN)(EntriesPosX - (TitleImage.Image.GetWidth() + (int)(TITLEICON_SPACING * ThemeX->Scale)));
|
||||||
INTN FilmYPos = (INTN)EntriesPosY;
|
INTN FilmYPos = (INTN)EntriesPosY;
|
||||||
XBool free;
|
const XImage& tImage = TitleImage.GetBest(!Daylight);
|
||||||
XImage *tImage = TitleImage.GetBest(!Daylight, &free);
|
|
||||||
// TitleImage.Image.Draw(FilmXPos, FilmYPos); //TODO - account night and svg
|
// TitleImage.Image.Draw(FilmXPos, FilmYPos); //TODO - account night and svg
|
||||||
|
|
||||||
// update FilmPlace only if not set by InitAnime
|
// update FilmPlace only if not set by InitAnime
|
||||||
if (FilmC->FilmPlace.Width == 0 || FilmC->FilmPlace.Height == 0) {
|
if (FilmC->FilmPlace.Width == 0 || FilmC->FilmPlace.Height == 0) {
|
||||||
FilmC->FilmPlace.XPos = FilmXPos;
|
FilmC->FilmPlace.XPos = FilmXPos;
|
||||||
FilmC->FilmPlace.YPos = FilmYPos;
|
FilmC->FilmPlace.YPos = FilmYPos;
|
||||||
FilmC->FilmPlace.Width = tImage->GetWidth();
|
FilmC->FilmPlace.Width = tImage.GetWidth();
|
||||||
FilmC->FilmPlace.Height = tImage->GetHeight();
|
FilmC->FilmPlace.Height = tImage.GetHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
tImage->Draw(FilmXPos, FilmYPos);
|
tImage.Draw(FilmXPos, FilmYPos);
|
||||||
if (free) delete tImage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (InfoLines.size() > 0) {
|
if (InfoLines.size() > 0) {
|
||||||
|
@ -338,13 +338,13 @@ if ( nsvg__nbDanglingPtr() > 0 ) {
|
|||||||
SelectionBackgroundPixel.Blue = (SelectionColor >> 8) & 0xFF;
|
SelectionBackgroundPixel.Blue = (SelectionColor >> 8) & 0xFF;
|
||||||
SelectionBackgroundPixel.Reserved = (SelectionColor >> 0) & 0xFF;
|
SelectionBackgroundPixel.Reserved = (SelectionColor >> 0) & 0xFF;
|
||||||
//TODO make SelectionImages to be XIcon
|
//TODO make SelectionImages to be XIcon
|
||||||
SelectionImages[0] = *GetIconP(BUILTIN_SELECTION_BIG)->GetBest(!Daylight);
|
SelectionImages[0] = GetIcon(BUILTIN_SELECTION_BIG).GetBest(!Daylight);
|
||||||
SelectionImages[2] = *GetIconP(BUILTIN_SELECTION_SMALL)->GetBest(!Daylight);
|
SelectionImages[2] = GetIcon(BUILTIN_SELECTION_SMALL).GetBest(!Daylight);
|
||||||
SelectionImages[4] = *GetIconP(BUILTIN_ICON_SELECTION)->GetBest(!Daylight);
|
SelectionImages[4] = GetIcon(BUILTIN_ICON_SELECTION).GetBest(!Daylight);
|
||||||
|
|
||||||
//buttons
|
//buttons
|
||||||
for (INTN i = BUILTIN_RADIO_BUTTON; i <= BUILTIN_CHECKBOX_CHECKED; ++i) {
|
for (INTN i = BUILTIN_RADIO_BUTTON; i <= BUILTIN_CHECKBOX_CHECKED; ++i) {
|
||||||
Buttons[i - BUILTIN_RADIO_BUTTON] = *GetIconP(i)->GetBest(!Daylight);
|
Buttons[i - BUILTIN_RADIO_BUTTON] = GetIcon(i).GetBest(!Daylight);
|
||||||
}
|
}
|
||||||
//for (int i=0 ; i<6 ; i+=2 ) {
|
//for (int i=0 ; i<6 ; i+=2 ) {
|
||||||
//SelectionImages[i].Draw(i*100, 0);
|
//SelectionImages[i].Draw(i*100, 0);
|
||||||
|
@ -250,43 +250,9 @@ EFI_STATUS XIcon::LoadXImage(const EFI_FILE *BaseDir, const XStringW& IconName)
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
XImage* XIcon::GetBest(XBool night, XBool *free)
|
const XImage& XIcon::GetBest(XBool night) const
|
||||||
{
|
{
|
||||||
#if 1
|
const XImage& RetImage = (night && !ImageNight.isEmpty())? ImageNight : Image;
|
||||||
if (ImageSVG) {
|
|
||||||
NSVGimage* sImage = (NSVGimage*)ImageSVGnight;
|
|
||||||
if (!night || !ImageSVGnight) sImage = (NSVGimage*)ImageSVG;
|
|
||||||
float Scale = sImage->scale;
|
|
||||||
NSVGrasterizer* rast = nsvgCreateRasterizer();
|
|
||||||
float Height = sImage->height * Scale;
|
|
||||||
float Width = sImage->width * Scale;
|
|
||||||
int iWidth = (int)(Width + 0.5f);
|
|
||||||
int iHeight = (int)(Height + 0.5f);
|
|
||||||
XImage* NewImage = new XImage(iWidth, iHeight); //TODO creating new XImage we have to delete it after use
|
|
||||||
if (sImage->shapes == NULL) {
|
|
||||||
if (free) *free = true;
|
|
||||||
return NewImage;
|
|
||||||
}
|
|
||||||
float bounds[4];
|
|
||||||
nsvg__imageBounds(sImage, bounds);
|
|
||||||
|
|
||||||
float tx = 0.f, ty = 0.f;
|
|
||||||
float realWidth = (bounds[2] - bounds[0]) * Scale;
|
|
||||||
float realHeight = (bounds[3] - bounds[1]) * Scale;
|
|
||||||
tx = (Width - realWidth) * 0.5f;
|
|
||||||
ty = (Height - realHeight) * 0.5f;
|
|
||||||
|
|
||||||
nsvgRasterize(rast, sImage, tx, ty, Scale, Scale, (UINT8*)NewImage->GetPixelPtr(0,0), iWidth, iHeight, iWidth*4);
|
|
||||||
nsvgDeleteRasterizer(rast);
|
|
||||||
// if (night) ImageNight = *NewImage;
|
|
||||||
// else Image = *NewImage;
|
|
||||||
// delete NewImage;
|
|
||||||
if (free) *free = true;
|
|
||||||
return NewImage;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
XImage* RetImage = (night && !ImageNight.isEmpty())? &ImageNight : &Image;
|
|
||||||
if (free) *free = false;
|
|
||||||
return RetImage;
|
return RetImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
// Default are not valid, as usual. We delete them. If needed, proper ones can be created
|
// Default are not valid, as usual. We delete them. If needed, proper ones can be created
|
||||||
// Icon(const Icon&) = delete;
|
// Icon(const Icon&) = delete;
|
||||||
XIcon& operator=(const XIcon&); // = delete;
|
XIcon& operator=(const XIcon&); // = delete;
|
||||||
XImage* GetBest(XBool night, XBool *free = nullptr);
|
const XImage& GetBest(XBool night) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -530,7 +530,7 @@ void XImage::GetArea(INTN x, INTN y, UINTN W, UINTN H)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XImage::DrawWithoutCompose(INTN x, INTN y, UINTN width, UINTN height)
|
void XImage::DrawWithoutCompose(INTN x, INTN y, UINTN width, UINTN height) const
|
||||||
{
|
{
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@ -556,27 +556,27 @@ void XImage::DrawWithoutCompose(INTN x, INTN y, UINTN width, UINTN height)
|
|||||||
}
|
}
|
||||||
//output combined image
|
//output combined image
|
||||||
if (GraphicsOutput != NULL) {
|
if (GraphicsOutput != NULL) {
|
||||||
GraphicsOutput->Blt(GraphicsOutput, (*this).GetPixelPtr(0, 0),
|
GraphicsOutput->Blt(GraphicsOutput, PixelData.data(),
|
||||||
EfiBltBufferToVideo,
|
EfiBltBufferToVideo,
|
||||||
0, 0, x, y, AreaWidth, AreaHeight, GetWidth()*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
|
0, 0, x, y, AreaWidth, AreaHeight, GetWidth()*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
|
||||||
}
|
}
|
||||||
else if (UgaDraw != NULL) {
|
else if (UgaDraw != NULL) {
|
||||||
UgaDraw->Blt(UgaDraw, (EFI_UGA_PIXEL *)(*this).GetPixelPtr(0, 0), EfiUgaBltBufferToVideo,
|
UgaDraw->Blt(UgaDraw, (EFI_UGA_PIXEL *)GetPixelPtr(0, 0), EfiUgaBltBufferToVideo,
|
||||||
0, 0, x, y, AreaWidth, AreaHeight, GetWidth()*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
|
0, 0, x, y, AreaWidth, AreaHeight, GetWidth()*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XImage::Draw(INTN x, INTN y)
|
void XImage::Draw(INTN x, INTN y) const
|
||||||
{
|
{
|
||||||
Draw(x, y, 0, true);
|
Draw(x, y, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XImage::Draw(INTN x, INTN y, float scale)
|
void XImage::Draw(INTN x, INTN y, float scale) const
|
||||||
{
|
{
|
||||||
Draw(x, y, scale, true);
|
Draw(x, y, scale, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XImage::Draw(INTN x, INTN y, float scale, XBool Opaque)
|
void XImage::Draw(INTN x, INTN y, float scale, XBool Opaque) const
|
||||||
{
|
{
|
||||||
//prepare images
|
//prepare images
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
@ -601,7 +601,7 @@ void XImage::Draw(INTN x, INTN y, float scale, XBool Opaque)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void XImage::DrawOnBack(INTN XPos, INTN YPos, const XImage& Plate)
|
void XImage::DrawOnBack(INTN XPos, INTN YPos, const XImage& Plate) const
|
||||||
{
|
{
|
||||||
XImage BackLayer(Width, Height);
|
XImage BackLayer(Width, Height);
|
||||||
BackLayer.CopyRect(Plate, XPos, YPos); //assume Plate is big enough [XPos+Width, YPos+Height]
|
BackLayer.CopyRect(Plate, XPos, YPos); //assume Plate is big enough [XPos+Width, YPos+Height]
|
||||||
|
@ -90,11 +90,11 @@ public:
|
|||||||
|
|
||||||
void GetArea(const EG_RECT& Rect);
|
void GetArea(const EG_RECT& Rect);
|
||||||
void GetArea(INTN x, INTN y, UINTN W, UINTN H);
|
void GetArea(INTN x, INTN y, UINTN W, UINTN H);
|
||||||
void Draw(INTN x, INTN y, float scale, XBool Opaque);
|
void Draw(INTN x, INTN y, float scale, XBool Opaque) const;
|
||||||
void Draw(INTN x, INTN y, float scale); //can accept 0 scale as 1.f
|
void Draw(INTN x, INTN y, float scale) const; //can accept 0 scale as 1.f
|
||||||
void Draw(INTN x, INTN y);
|
void Draw(INTN x, INTN y) const;
|
||||||
void DrawWithoutCompose(INTN x, INTN y, UINTN width = 0, UINTN height = 0);
|
void DrawWithoutCompose(INTN x, INTN y, UINTN width = 0, UINTN height = 0) const;
|
||||||
void DrawOnBack(INTN x, INTN y, const XImage& Plate);
|
void DrawOnBack(INTN x, INTN y, const XImage& Plate) const;
|
||||||
//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(const EFI_FILE *Dir, const XStringW& FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name);
|
EFI_STATUS LoadXImage(const EFI_FILE *Dir, const XStringW& FileName); //for example LoadImage(ThemeDir, L"icons\\" + Name);
|
||||||
|
@ -77,7 +77,7 @@ EFI_STATUS XPointer::MouseBirth()
|
|||||||
PointerImage = nullptr;
|
PointerImage = nullptr;
|
||||||
}
|
}
|
||||||
// Now update image because of other theme has other image
|
// Now update image because of other theme has other image
|
||||||
PointerImage = new XImage(*ThemeX->GetIconP(BUILTIN_ICON_POINTER)->GetBest(night));
|
PointerImage = new XImage(ThemeX->GetIcon(BUILTIN_ICON_POINTER).GetBest(night));
|
||||||
|
|
||||||
oldImage.setSizeInPixels(PointerImage->GetWidth(), PointerImage->GetHeight());
|
oldImage.setSizeInPixels(PointerImage->GetWidth(), PointerImage->GetHeight());
|
||||||
LastClickTime = 0;
|
LastClickTime = 0;
|
||||||
|
@ -32,7 +32,9 @@ public:
|
|||||||
XPointer(const XPointer&) = delete;
|
XPointer(const XPointer&) = delete;
|
||||||
XPointer& operator=(const XPointer&) = delete;
|
XPointer& operator=(const XPointer&) = delete;
|
||||||
|
|
||||||
~XPointer() {};
|
~XPointer() {
|
||||||
|
delete PointerImage;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -795,18 +795,6 @@ const XIcon& XTheme::GetIcon(const XString8& Name)
|
|||||||
return NullIcon; //if name is not found
|
return NullIcon; //if name is not found
|
||||||
}
|
}
|
||||||
|
|
||||||
XIcon* XTheme::GetIconP(const XString8& Name)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < Icons.size(); i++)
|
|
||||||
{
|
|
||||||
if (Icons[i].Name == Name) //night icon has same name as daylight icon
|
|
||||||
{
|
|
||||||
return GetIconP(Icons[i].Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &NullIcon; //if name is not found
|
|
||||||
}
|
|
||||||
|
|
||||||
XBool XTheme::CheckNative(INTN Id)
|
XBool XTheme::CheckNative(INTN Id)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < Icons.size(); i++)
|
for (size_t i = 0; i < Icons.size(); i++)
|
||||||
@ -824,11 +812,6 @@ const XIcon& XTheme::GetIcon(INTN Id)
|
|||||||
return GetIconAlt(Id, -1);
|
return GetIconAlt(Id, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
XIcon* XTheme::GetIconP(INTN Id)
|
|
||||||
{
|
|
||||||
return &GetIconAlt(Id, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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 with Native attribute set, for example VOL_INTERNAL
|
* if not found then search for ID=Alt with Native attribute set, for example VOL_INTERNAL
|
||||||
@ -1160,17 +1143,17 @@ 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;
|
||||||
//TODO - make them XIcon
|
//TODO - make them XIcon
|
||||||
SelectionImages[2] = *GetIconP(BUILTIN_SELECTION_SMALL)->GetBest(!Daylight);
|
SelectionImages[2] = GetIcon(BUILTIN_SELECTION_SMALL).GetBest(!Daylight);
|
||||||
SelectionImages[0] = *GetIconP(BUILTIN_SELECTION_BIG)->GetBest(!Daylight);
|
SelectionImages[0] = GetIcon(BUILTIN_SELECTION_BIG).GetBest(!Daylight);
|
||||||
if (BootCampStyle) {
|
if (BootCampStyle) {
|
||||||
SelectionImages[4] = *GetIconP(BUILTIN_ICON_SELECTION)->GetBest(!Daylight);
|
SelectionImages[4] = GetIcon(BUILTIN_ICON_SELECTION).GetBest(!Daylight);
|
||||||
}
|
}
|
||||||
|
|
||||||
//and buttons
|
//and buttons
|
||||||
Buttons[0] = *GetIconP(BUILTIN_RADIO_BUTTON)->GetBest(!Daylight);
|
Buttons[0] = GetIcon(BUILTIN_RADIO_BUTTON).GetBest(!Daylight);
|
||||||
Buttons[1] = *GetIconP(BUILTIN_RADIO_BUTTON_SELECTED)->GetBest(!Daylight);
|
Buttons[1] = GetIcon(BUILTIN_RADIO_BUTTON_SELECTED).GetBest(!Daylight);
|
||||||
Buttons[2] = *GetIconP(BUILTIN_CHECKBOX)->GetBest(!Daylight);
|
Buttons[2] = GetIcon(BUILTIN_CHECKBOX).GetBest(!Daylight);
|
||||||
Buttons[3] = *GetIconP(BUILTIN_CHECKBOX_CHECKED)->GetBest(!Daylight);
|
Buttons[3] = GetIcon(BUILTIN_CHECKBOX_CHECKED).GetBest(!Daylight);
|
||||||
|
|
||||||
//load banner and background
|
//load banner and background
|
||||||
Banner.LoadXImage(ThemeDir, BannerFileName);
|
Banner.LoadXImage(ThemeDir, BannerFileName);
|
||||||
@ -1196,14 +1179,14 @@ void XTheme::InitBar()
|
|||||||
UpButtonImage.LoadXImage(ThemeDir, "scrollbar\\up_button");
|
UpButtonImage.LoadXImage(ThemeDir, "scrollbar\\up_button");
|
||||||
DownButtonImage.LoadXImage(ThemeDir, "scrollbar\\down_button");
|
DownButtonImage.LoadXImage(ThemeDir, "scrollbar\\down_button");
|
||||||
} else {
|
} else {
|
||||||
ScrollbarBackgroundImage = *GetIconP("scrollbar_background"_XS8)->GetBest(!Daylight);
|
ScrollbarBackgroundImage = GetIcon("scrollbar_background"_XS8).GetBest(!Daylight);
|
||||||
BarStartImage.setEmpty();
|
BarStartImage.setEmpty();
|
||||||
BarEndImage.setEmpty();
|
BarEndImage.setEmpty();
|
||||||
ScrollbarImage = *GetIconP("scrollbar_holder"_XS8)->GetBest(!Daylight); //"_night" is already accounting
|
ScrollbarImage = GetIcon("scrollbar_holder"_XS8).GetBest(!Daylight); //"_night" is already accounting
|
||||||
ScrollStartImage = *GetIconP("scrollbar_start"_XS8)->GetBest(!Daylight);
|
ScrollStartImage = GetIcon("scrollbar_start"_XS8).GetBest(!Daylight);
|
||||||
ScrollEndImage = *GetIconP("scrollbar_end"_XS8)->GetBest(!Daylight);
|
ScrollEndImage = GetIcon("scrollbar_end"_XS8).GetBest(!Daylight);
|
||||||
UpButtonImage = *GetIconP("scrollbar_up_button"_XS8)->GetBest(!Daylight);
|
UpButtonImage = GetIcon("scrollbar_up_button"_XS8).GetBest(!Daylight);
|
||||||
DownButtonImage = *GetIconP("scrollbar_down_button"_XS8)->GetBest(!Daylight);
|
DownButtonImage = GetIcon("scrollbar_down_button"_XS8).GetBest(!Daylight);
|
||||||
}
|
}
|
||||||
|
|
||||||
//some help with embedded scroll
|
//some help with embedded scroll
|
||||||
|
@ -160,9 +160,7 @@ public:
|
|||||||
// const XImage& GetIcon(const char* Name);
|
// const XImage& GetIcon(const char* Name);
|
||||||
// const XImage& GetIcon(const CHAR16* Name);
|
// const XImage& GetIcon(const CHAR16* Name);
|
||||||
const XIcon& GetIcon(const XString8& Name); //get by name
|
const XIcon& GetIcon(const XString8& Name); //get by name
|
||||||
XIcon* GetIconP(const XString8& Name);
|
|
||||||
const XIcon& GetIcon(INTN Id); //get by id
|
const XIcon& GetIcon(INTN Id); //get by id
|
||||||
XIcon* GetIconP(INTN Id); //not const
|
|
||||||
XIcon& GetIconAlt(INTN Id, INTN Alt); //if id not found
|
XIcon& GetIconAlt(INTN Id, INTN Alt); //if id not found
|
||||||
const XIcon& LoadOSIcon(const CHAR16* OSIconName); //TODO make XString provider
|
const XIcon& LoadOSIcon(const CHAR16* OSIconName); //TODO make XString provider
|
||||||
const XIcon& LoadOSIcon(const XString8& Full);
|
const XIcon& LoadOSIcon(const XString8& Full);
|
||||||
|
Loading…
Reference in New Issue
Block a user