2019-09-03 11:58:42 +02:00
|
|
|
/*
|
|
|
|
* Additional procedures for vector theme support
|
|
|
|
*
|
|
|
|
* Slice, 2018
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-03-13 14:38:52 +01:00
|
|
|
|
2020-03-13 14:34:36 +01:00
|
|
|
#define TEST_MATH 0
|
|
|
|
#define TEST_SVG_IMAGE 1
|
|
|
|
#define TEST_SIZEOF 0
|
|
|
|
#define TEST_FONT 0
|
|
|
|
#define TEST_DITHER 0
|
2020-03-16 12:15:25 +01:00
|
|
|
|
2020-03-31 17:59:35 +02:00
|
|
|
#include "VectorGraphics.h"
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-03-13 14:11:58 +01:00
|
|
|
#include "../Platform/Platform.h"
|
2020-03-13 14:38:52 +01:00
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
#include "nanosvg.h"
|
|
|
|
#include "FloatLib.h"
|
|
|
|
#include "lodepng.h"
|
2020-02-29 08:30:21 +01:00
|
|
|
#include "../refit/screen.h"
|
2020-03-12 18:45:28 +01:00
|
|
|
#include "../cpp_foundation/XString.h"
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
#ifndef DEBUG_ALL
|
|
|
|
#define DEBUG_VEC 1
|
|
|
|
#else
|
|
|
|
#define DEBUG_VEC DEBUG_ALL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DEBUG_VEC == 0
|
|
|
|
#define DBG(...)
|
|
|
|
#else
|
|
|
|
#define DBG(...) DebugLog(DEBUG_VEC, __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
2020-03-13 14:34:36 +01:00
|
|
|
#include "XTheme.h"
|
2020-03-20 21:10:08 +01:00
|
|
|
extern XTheme ThemeX;
|
2020-03-28 19:34:23 +01:00
|
|
|
extern CONST CHAR8* IconsNames[];
|
2020-03-13 14:34:36 +01:00
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
#define NSVG_RGB(r, g, b) (((unsigned int)b) | ((unsigned int)g << 8) | ((unsigned int)r << 16))
|
|
|
|
//#define NSVG_RGBA(r, g, b, a) (((unsigned int)b) | ((unsigned int)g << 8) | ((unsigned int)r << 16) | ((unsigned int)a << 24))
|
|
|
|
|
|
|
|
extern VOID
|
|
|
|
WaitForKeyPress(CHAR16 *Message);
|
|
|
|
|
2020-02-17 21:41:09 +01:00
|
|
|
extern void DumpFloat2 (CONST char* s, float* t, int N);
|
2020-04-10 12:04:21 +02:00
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
extern UINTN NumFrames;
|
|
|
|
extern UINTN FrameTime;
|
2020-03-29 09:14:14 +02:00
|
|
|
|
|
|
|
textFaces textFace[4]; //0-help 1-message 2-menu 3-test, far future it will be infinite list with id
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-04-15 22:12:43 +02:00
|
|
|
EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString& IconNameX, XImage* Image)
|
2020-03-13 14:34:36 +01:00
|
|
|
{
|
2020-03-16 12:15:25 +01:00
|
|
|
EFI_STATUS Status = EFI_NOT_FOUND;
|
|
|
|
NSVGimage *SVGimage;
|
2020-04-15 22:12:43 +02:00
|
|
|
NSVGparser *p = (NSVGparser *)SVGParser;
|
2020-03-16 12:15:25 +01:00
|
|
|
NSVGrasterizer* rast = nsvgCreateRasterizer();
|
|
|
|
SVGimage = p->image;
|
|
|
|
NSVGshape *shape;
|
|
|
|
NSVGgroup *group;
|
2020-03-20 21:10:08 +01:00
|
|
|
NSVGimage *IconImage;
|
|
|
|
NSVGshape *shapeNext, *shapesTail = NULL, *shapePrev;
|
2020-04-10 05:11:00 +02:00
|
|
|
// CONST CHAR8 *IconName = IconNameX.c_str();
|
2020-03-16 12:15:25 +01:00
|
|
|
|
|
|
|
NSVGparser* p2 = nsvg__createParser();
|
|
|
|
IconImage = p2->image;
|
|
|
|
shape = SVGimage->shapes;
|
|
|
|
shapePrev = NULL;
|
|
|
|
while (shape) {
|
|
|
|
group = shape->group;
|
|
|
|
shapeNext = shape->next;
|
|
|
|
while (group) {
|
2020-04-10 05:11:00 +02:00
|
|
|
if (strcmp(group->id, IconNameX.c_str()) == 0) {
|
2020-03-16 12:15:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
group = group->next;
|
|
|
|
}
|
|
|
|
if (group) { //the shape is in the group
|
|
|
|
// keep this sample for debug purpose
|
2020-03-25 19:32:44 +01:00
|
|
|
/* DBG("found shape %s", shape->id);
|
|
|
|
DBG(" from group %s\n", group->id);
|
2020-03-16 12:15:25 +01:00
|
|
|
if ((Id == BUILTIN_SELECTION_BIG) ||
|
|
|
|
(Id == BUILTIN_ICON_BACKGROUND) ||
|
|
|
|
(Id == BUILTIN_ICON_BANNER)) {
|
|
|
|
shape->debug = TRUE;
|
|
|
|
} */
|
2020-04-10 05:11:00 +02:00
|
|
|
// if (BootCampStyle && (strstr(IconName, "selection_big") != NULL)) {
|
|
|
|
// shape->opacity = 0.f;
|
|
|
|
// }
|
|
|
|
if (BootCampStyle && IconNameX.ExistIn("selection_big")) {
|
2020-03-16 12:15:25 +01:00
|
|
|
shape->opacity = 0.f;
|
|
|
|
}
|
2020-04-10 05:11:00 +02:00
|
|
|
// if (strstr(shape->id, "BoundingRect") != NULL) {
|
|
|
|
if (XString().takeValueFrom(shape->id).ExistIn("BoundingRect")) {
|
2020-03-16 12:15:25 +01:00
|
|
|
//there is bounds after nsvgParse()
|
|
|
|
IconImage->width = shape->bounds[2] - shape->bounds[0];
|
|
|
|
IconImage->height = shape->bounds[3] - shape->bounds[1];
|
2020-04-10 05:11:00 +02:00
|
|
|
// DBG("parsed bounds: %f, %f\n", IconImage->width, IconImage->height);
|
|
|
|
if ( IconImage->height < 1.f ) {
|
|
|
|
IconImage->height = 200.f;
|
2020-03-16 12:15:25 +01:00
|
|
|
}
|
2020-04-10 05:11:00 +02:00
|
|
|
if (IconNameX.ExistIn("selection_big") && (!SelectionOnTop)) {
|
|
|
|
MainEntriesSize = (int)(IconImage->width * Scale); //xxx
|
|
|
|
row0TileSize = MainEntriesSize + (int)(16.f * Scale);
|
2020-03-29 18:17:27 +02:00
|
|
|
DBG("main entry size = %lld\n", MainEntriesSize);
|
2020-03-16 12:15:25 +01:00
|
|
|
}
|
2020-04-10 05:11:00 +02:00
|
|
|
if (IconNameX.ExistIn("selection_small") && (!SelectionOnTop)) {
|
|
|
|
row1TileSize = (int)(IconImage->width * Scale);
|
2020-03-16 12:15:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// not exclude BoundingRect from IconImage?
|
|
|
|
shape->flags = 0; //invisible
|
|
|
|
if (shapePrev) {
|
|
|
|
shapePrev->next = shapeNext;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SVGimage->shapes = shapeNext;
|
|
|
|
}
|
|
|
|
shape = shapeNext;
|
|
|
|
continue; //while(shape) it is BoundingRect shape
|
|
|
|
|
|
|
|
// shape->opacity = 0.3f;
|
|
|
|
}
|
|
|
|
shape->flags = NSVG_VIS_VISIBLE;
|
|
|
|
// Add to tail
|
|
|
|
// ClipCount += shape->clip.count;
|
|
|
|
if (IconImage->shapes == NULL)
|
|
|
|
IconImage->shapes = shape;
|
|
|
|
else
|
|
|
|
shapesTail->next = shape;
|
|
|
|
shapesTail = shape;
|
|
|
|
if (shapePrev) {
|
|
|
|
shapePrev->next = shapeNext;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SVGimage->shapes = shapeNext;
|
|
|
|
}
|
|
|
|
shapePrev->next = shapeNext;
|
|
|
|
} //the shape in the group
|
|
|
|
else {
|
|
|
|
shapePrev = shape;
|
|
|
|
}
|
|
|
|
shape = shapeNext;
|
|
|
|
} //while shape
|
|
|
|
shapesTail->next = NULL;
|
|
|
|
//add clipPaths //xxx
|
|
|
|
NSVGclipPath* clipPaths = SVGimage->clipPaths;
|
|
|
|
NSVGclipPath* clipNext = NULL;
|
|
|
|
while (clipPaths) {
|
|
|
|
// ClipCount += clipPaths->shapes->clip.count;
|
2020-04-15 21:18:53 +02:00
|
|
|
if (!clipPaths->shapes) {
|
|
|
|
break;
|
|
|
|
}
|
2020-03-16 12:15:25 +01:00
|
|
|
group = clipPaths->shapes->group;
|
|
|
|
clipNext = clipPaths->next;
|
|
|
|
while (group) {
|
2020-04-10 05:11:00 +02:00
|
|
|
// if (strcmp(group->id, IconNameX.c_str()) == 0) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
if (IconNameX == XString().takeValueFrom(group->id)) {
|
2020-03-16 12:15:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
group = group->parent;
|
|
|
|
}
|
|
|
|
if (group) {
|
2020-04-10 05:11:00 +02:00
|
|
|
DBG("found clipPaths for %s\n", IconNameX.c_str());
|
2020-03-16 12:15:25 +01:00
|
|
|
IconImage->clipPaths = SVGimage->clipPaths;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
clipPaths = clipNext;
|
|
|
|
}
|
2020-03-25 19:32:44 +01:00
|
|
|
// DBG("found %d clips for %s\n", ClipCount, IconName);
|
2020-03-16 12:15:25 +01:00
|
|
|
// if (ClipCount) { //Id == BUILTIN_ICON_BANNER) {
|
|
|
|
// IconImage->clipPaths = SVGimage->clipPaths;
|
|
|
|
// }
|
|
|
|
|
|
|
|
float bounds[4];
|
|
|
|
bounds[0] = FLT_MAX;
|
|
|
|
bounds[1] = FLT_MAX;
|
|
|
|
bounds[2] = -FLT_MAX;
|
|
|
|
bounds[3] = -FLT_MAX;
|
|
|
|
nsvg__imageBounds(p2, bounds);
|
|
|
|
CopyMem(IconImage->realBounds, bounds, 4 * sizeof(float));
|
2020-04-10 05:11:00 +02:00
|
|
|
if ((Id == BUILTIN_ICON_BANNER) && IconNameX.ExistIn("Banner")) {
|
|
|
|
BannerPosX = (int)(bounds[0] * Scale - CentreShift);
|
|
|
|
if (BannerPosX < 0) {
|
|
|
|
BannerPosX = 1; //one pixel
|
|
|
|
}
|
|
|
|
BannerPosY = (int)(bounds[1] * Scale);
|
2020-03-29 18:17:27 +02:00
|
|
|
DBG("Banner position at parse [%lld,%lld]\n", BannerPosX, BannerPosY);
|
2020-03-22 11:48:13 +01:00
|
|
|
}
|
|
|
|
|
2020-04-10 05:11:00 +02:00
|
|
|
float Height = IconImage->height * Scale;
|
|
|
|
float Width = IconImage->width * Scale;
|
2020-04-15 21:18:53 +02:00
|
|
|
// DBG("icon %s width=%f height=%f\n", IconNameX.c_str(), Width, Height);
|
2020-03-22 11:48:13 +01:00
|
|
|
int iWidth = (int)(Width + 0.5f);
|
|
|
|
int iHeight = (int)(Height + 0.5f);
|
|
|
|
// EG_IMAGE *NewImage = egCreateFilledImage(iWidth, iHeight, TRUE, &MenuBackgroundPixel);
|
|
|
|
XImage NewImage(iWidth, iHeight); //empty
|
|
|
|
if (IconImage->shapes == NULL) {
|
2020-03-29 11:40:13 +02:00
|
|
|
*Image = NewImage;
|
2020-04-04 19:02:30 +02:00
|
|
|
// DBG("return empty with status=%s\n", strerror(Status));
|
2020-03-22 11:48:13 +01:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:18:53 +02:00
|
|
|
// DBG("begin rasterize %s\n", IconNameX.c_str());
|
2020-03-22 11:48:13 +01:00
|
|
|
float tx = 0.f, ty = 0.f;
|
|
|
|
if ((Id != BUILTIN_ICON_BACKGROUND) &&
|
2020-04-19 13:23:23 +02:00
|
|
|
(Id != BUILTIN_ICON_ANIME) /*&&
|
|
|
|
IconNameX.ExistIn("Banner")*/) {
|
2020-04-10 05:11:00 +02:00
|
|
|
float realWidth = (bounds[2] - bounds[0]) * Scale;
|
|
|
|
float realHeight = (bounds[3] - bounds[1]) * Scale;
|
2020-04-19 13:28:14 +02:00
|
|
|
// DBG("icon=%s width=%f realwidth=%f\n", IconNameX.c_str(), Width, realWidth);
|
2020-03-22 11:48:13 +01:00
|
|
|
tx = (Width - realWidth) * 0.5f;
|
|
|
|
ty = (Height - realHeight) * 0.5f;
|
|
|
|
}
|
|
|
|
|
2020-04-10 05:11:00 +02:00
|
|
|
nsvgRasterize(rast, IconImage, tx, ty, Scale, Scale, (UINT8*)NewImage.GetPixelPtr(0,0), iWidth, iHeight, iWidth*4);
|
2020-03-25 19:32:44 +01:00
|
|
|
// DBG("%s rastered, blt\n", IconImage);
|
2020-03-22 11:48:13 +01:00
|
|
|
|
|
|
|
nsvgDeleteRasterizer(rast);
|
|
|
|
// nsvg__deleteParser(p2);
|
|
|
|
// nsvgDelete(p2->image);
|
2020-03-29 11:40:13 +02:00
|
|
|
*Image = NewImage;
|
2020-03-16 12:15:25 +01:00
|
|
|
|
2020-03-13 14:34:36 +01:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-03-29 18:17:27 +02:00
|
|
|
EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
2020-03-29 18:17:27 +02:00
|
|
|
EFI_STATUS Status;
|
2020-04-03 22:00:42 +02:00
|
|
|
|
|
|
|
Icons.Empty();
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-03-27 20:47:06 +01:00
|
|
|
// --- Parse theme.svg --- low case
|
2020-04-18 08:39:47 +02:00
|
|
|
NSVGparser *mainParser = nsvgParse((CHAR8*)buffer, 72, 1.f); //the buffer will be modified, it is how nanosvg works
|
|
|
|
SVGParser = (void *)mainParser; //store the pointer for future use
|
|
|
|
NSVGimage *SVGimage = mainParser->image;
|
2019-09-03 11:58:42 +02:00
|
|
|
if (!SVGimage) {
|
|
|
|
DBG("Theme not parsed!\n");
|
|
|
|
return EFI_NOT_STARTED;
|
|
|
|
}
|
|
|
|
|
2020-03-27 20:47:06 +01:00
|
|
|
// --- Get scale as theme design height vs screen height
|
|
|
|
|
2020-04-18 08:39:47 +02:00
|
|
|
// must be svg view-box. This is Design Width and Heigth
|
2019-09-03 11:58:42 +02:00
|
|
|
float vbx = mainParser->viewWidth;
|
|
|
|
float vby = mainParser->viewHeight;
|
2020-04-10 05:11:00 +02:00
|
|
|
DBG("Theme view-bounds: w=%f h=%f units=px\n", vbx, vby); //Theme view-bounds: w=1600.000000 h=900.000000 units=px
|
2020-03-27 20:47:06 +01:00
|
|
|
if (vby > 1.0f) {
|
|
|
|
SVGimage->height = vby;
|
2020-03-29 18:17:27 +02:00
|
|
|
} else {
|
2020-03-27 20:47:06 +01:00
|
|
|
SVGimage->height = 768.f; //default height
|
|
|
|
}
|
2020-03-29 18:17:27 +02:00
|
|
|
float ScaleF = UGAHeight / SVGimage->height;
|
2020-04-10 05:11:00 +02:00
|
|
|
DBG("using scale %f\n", ScaleF); // using scale 0.666667
|
2020-03-31 16:25:07 +02:00
|
|
|
Scale = ScaleF;
|
2020-03-29 18:17:27 +02:00
|
|
|
CentreShift = (vbx * Scale - (float)UGAWidth) * 0.5f;
|
2020-03-27 20:47:06 +01:00
|
|
|
|
2020-03-29 18:17:27 +02:00
|
|
|
Background = XImage(UGAWidth, UGAHeight);
|
|
|
|
if (!BigBack.isEmpty()) {
|
|
|
|
BigBack.setEmpty();
|
2020-03-27 20:47:06 +01:00
|
|
|
}
|
|
|
|
Status = EFI_NOT_FOUND;
|
2020-04-16 13:04:24 +02:00
|
|
|
if (!ThemeX.Daylight) {
|
2020-04-15 22:12:43 +02:00
|
|
|
Status = ParseSVGXIcon(BUILTIN_ICON_BACKGROUND, "Background_night"_XS, &BigBack);
|
2020-03-27 20:47:06 +01:00
|
|
|
}
|
|
|
|
if (EFI_ERROR(Status)) {
|
2020-04-15 22:12:43 +02:00
|
|
|
Status = ParseSVGXIcon(BUILTIN_ICON_BACKGROUND, "Background"_XS, &BigBack);
|
2020-03-27 20:47:06 +01:00
|
|
|
}
|
2020-04-10 05:11:00 +02:00
|
|
|
DBG(" Background parsed [%lld, %lld]\n", BigBack.GetWidth(), BigBack.GetHeight()); //Background parsed [1067, 133]
|
2020-03-27 20:47:06 +01:00
|
|
|
// --- Make Banner
|
2020-03-29 18:17:27 +02:00
|
|
|
Banner.setEmpty(); //for the case of theme switch
|
2020-03-27 20:47:06 +01:00
|
|
|
Status = EFI_NOT_FOUND;
|
2020-04-16 13:04:24 +02:00
|
|
|
if (!ThemeX.Daylight) {
|
2020-04-15 22:12:43 +02:00
|
|
|
Status = ParseSVGXIcon(BUILTIN_ICON_BANNER, "Banner_night"_XS, &Banner);
|
2020-03-27 20:47:06 +01:00
|
|
|
}
|
|
|
|
if (EFI_ERROR(Status)) {
|
2020-04-15 22:12:43 +02:00
|
|
|
Status = ParseSVGXIcon(BUILTIN_ICON_BANNER, "Banner"_XS, &Banner);
|
2020-03-27 20:47:06 +01:00
|
|
|
}
|
2020-04-18 08:39:47 +02:00
|
|
|
// DBG("Banner parsed\n");
|
2020-03-29 18:17:27 +02:00
|
|
|
BanHeight = (int)(Banner.GetHeight() * Scale + 1.f);
|
2020-04-10 05:11:00 +02:00
|
|
|
DBG(" parsed banner->width=%lld height=%lld\n", Banner.GetWidth(), BanHeight); //parsed banner->width=467 height=89
|
2020-03-27 20:47:06 +01:00
|
|
|
|
|
|
|
// --- Make other icons
|
2020-03-28 19:34:23 +01:00
|
|
|
|
2020-04-03 22:00:42 +02:00
|
|
|
for (INTN i = BUILTIN_ICON_FUNC_ABOUT; i <= BUILTIN_CHECKBOX_CHECKED; ++i) {
|
2020-04-18 08:39:47 +02:00
|
|
|
if (i == BUILTIN_ICON_BANNER) { //exclude "logo" as it done as Banner
|
2020-03-27 20:47:06 +01:00
|
|
|
continue;
|
|
|
|
}
|
2020-04-05 23:14:27 +02:00
|
|
|
Icon* NewIcon = new Icon(i, false); //initialize without embedded
|
2020-04-15 22:12:43 +02:00
|
|
|
Status = ParseSVGXIcon(i, NewIcon->Name, &NewIcon->Image);
|
2020-04-18 08:39:47 +02:00
|
|
|
NewIcon->Native = !EFI_ERROR(Status);
|
2020-04-06 11:15:36 +02:00
|
|
|
if (EFI_ERROR(Status) &&
|
|
|
|
(i >= BUILTIN_ICON_VOL_INTERNAL_HFS) &&
|
|
|
|
(i <= BUILTIN_ICON_VOL_INTERNAL_REC)) {
|
2020-04-18 08:39:47 +02:00
|
|
|
NewIcon->Image = GetIconAlt(i, BUILTIN_ICON_VOL_INTERNAL); //copy existing
|
2020-04-06 11:15:36 +02:00
|
|
|
}
|
2020-04-04 07:50:30 +02:00
|
|
|
// DBG("parse %s status %s\n", NewIcon->Name.c_str(), strerror(Status));
|
2020-04-15 22:12:43 +02:00
|
|
|
Status = ParseSVGXIcon(i, NewIcon->Name + "_night"_XS, &NewIcon->ImageNight);
|
2020-04-04 07:50:30 +02:00
|
|
|
// DBG("...night status %s\n", strerror(Status));
|
2020-04-06 11:15:36 +02:00
|
|
|
if (EFI_ERROR(Status) &&
|
|
|
|
(i >= BUILTIN_ICON_VOL_INTERNAL_HFS) &&
|
|
|
|
(i <= BUILTIN_ICON_VOL_INTERNAL_REC)) {
|
2020-04-18 08:39:47 +02:00
|
|
|
NewIcon->ImageNight = GetIconAlt(i, BUILTIN_ICON_VOL_INTERNAL); //copy existing
|
2020-04-06 11:15:36 +02:00
|
|
|
}
|
2020-04-02 21:27:10 +02:00
|
|
|
Icons.AddReference(NewIcon, true);
|
2020-03-28 19:34:23 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 16:03:58 +02:00
|
|
|
//selections
|
2020-04-06 11:15:36 +02:00
|
|
|
SelectionBackgroundPixel.Red = (SelectionColor >> 24) & 0xFF;
|
|
|
|
SelectionBackgroundPixel.Green = (SelectionColor >> 16) & 0xFF;
|
|
|
|
SelectionBackgroundPixel.Blue = (SelectionColor >> 8) & 0xFF;
|
|
|
|
SelectionBackgroundPixel.Reserved = (SelectionColor >> 0) & 0xFF;
|
|
|
|
|
2020-04-02 16:03:58 +02:00
|
|
|
SelectionImages[0] = GetIcon(BUILTIN_SELECTION_BIG);
|
|
|
|
SelectionImages[2] = GetIcon(BUILTIN_SELECTION_SMALL);
|
2020-03-27 20:47:06 +01:00
|
|
|
|
2020-03-28 19:34:23 +01:00
|
|
|
//selection for bootcamp style
|
|
|
|
Status = EFI_NOT_FOUND;
|
2020-04-16 13:04:24 +02:00
|
|
|
if (!ThemeX.Daylight) {
|
2020-04-15 22:12:43 +02:00
|
|
|
Status = ParseSVGXIcon(BUILTIN_ICON_SELECTION, "selection_indicator_night"_XS, &SelectionImages[4]);
|
2020-03-28 19:34:23 +01:00
|
|
|
}
|
|
|
|
if (EFI_ERROR(Status)) {
|
2020-04-15 22:12:43 +02:00
|
|
|
Status = ParseSVGXIcon(BUILTIN_ICON_SELECTION, "selection_indicator"_XS, &SelectionImages[4]);
|
2020-03-28 19:34:23 +01:00
|
|
|
}
|
2020-04-04 05:46:41 +02:00
|
|
|
|
|
|
|
//buttons
|
|
|
|
for (INTN i = BUILTIN_RADIO_BUTTON; i <= BUILTIN_CHECKBOX_CHECKED; ++i) {
|
|
|
|
Buttons[i - BUILTIN_RADIO_BUTTON] = GetIcon(i);
|
|
|
|
}
|
2020-04-03 22:00:42 +02:00
|
|
|
//for (int i=0 ; i<6 ; i+=2 ) {
|
|
|
|
//SelectionImages[i].Draw(i*100, 0);
|
|
|
|
//}
|
|
|
|
|
2020-04-16 06:45:53 +02:00
|
|
|
//TODO parse anime like for PNG themes
|
|
|
|
/*
|
|
|
|
Dict = GetProperty (DictPointer, "Anime");
|
|
|
|
if (Dict != NULL) {
|
|
|
|
INTN Count = GetTagCount (Dict);
|
|
|
|
for (INTN i = 0; i < Count; i++) {
|
|
|
|
FILM *NewFilm = new FILM();
|
|
|
|
if (EFI_ERROR (GetElement (Dict, i, &Dict3))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Dict3 == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Dict2 = GetProperty (Dict3, "ID");
|
|
|
|
NewFilm->SetIndex((UINTN)GetPropertyInteger (Dict2, 1)); //default=main screen
|
|
|
|
|
|
|
|
Dict2 = GetProperty (Dict3, "Path");
|
|
|
|
if (Dict2 != NULL && (Dict2->type == kTagTypeString) && Dict2->string) {
|
|
|
|
NewFilm->Path.takeValueFrom(Dict2->string);
|
|
|
|
}
|
|
|
|
|
|
|
|
Dict2 = GetProperty (Dict3, "Frames");
|
|
|
|
NewFilm->NumFrames = (UINTN)GetPropertyInteger (Dict2, 0);
|
|
|
|
|
|
|
|
Dict2 = GetProperty (Dict3, "FrameTime");
|
|
|
|
NewFilm->FrameTime = (UINTN)GetPropertyInteger (Dict2, 50); //default will be 50ms
|
|
|
|
|
|
|
|
Dict2 = GetProperty (Dict3, "ScreenEdgeX");
|
|
|
|
if (Dict2 != NULL && (Dict2->type == kTagTypeString) && Dict2->string) {
|
|
|
|
if (AsciiStrCmp (Dict2->string, "left") == 0) {
|
|
|
|
NewFilm->ScreenEdgeHorizontal = SCREEN_EDGE_LEFT;
|
|
|
|
} else if (AsciiStrCmp (Dict2->string, "right") == 0) {
|
|
|
|
NewFilm->ScreenEdgeHorizontal = SCREEN_EDGE_RIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Dict2 = GetProperty (Dict3, "ScreenEdgeY");
|
|
|
|
if (Dict2 != NULL && (Dict2->type == kTagTypeString) && Dict2->string) {
|
|
|
|
if (AsciiStrCmp (Dict2->string, "top") == 0) {
|
|
|
|
NewFilm->ScreenEdgeVertical = SCREEN_EDGE_TOP;
|
|
|
|
} else if (AsciiStrCmp (Dict2->string, "bottom") == 0) {
|
|
|
|
NewFilm->ScreenEdgeVertical = SCREEN_EDGE_BOTTOM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//default values are centre
|
|
|
|
|
|
|
|
Dict2 = GetProperty (Dict3, "DistanceFromScreenEdgeX%");
|
|
|
|
NewFilm->FilmX = GetPropertyInteger (Dict2, INITVALUE);
|
|
|
|
|
|
|
|
Dict2 = GetProperty (Dict3, "DistanceFromScreenEdgeY%");
|
|
|
|
NewFilm->FilmY = GetPropertyInteger (Dict2, INITVALUE);
|
|
|
|
|
|
|
|
Dict2 = GetProperty (Dict3, "NudgeX");
|
|
|
|
NewFilm->NudgeX = GetPropertyInteger (Dict2, INITVALUE);
|
|
|
|
|
|
|
|
Dict2 = GetProperty (Dict3, "NudgeY");
|
|
|
|
NewFilm->NudgeY = GetPropertyInteger (Dict2, INITVALUE);
|
|
|
|
|
|
|
|
Dict2 = GetProperty (Dict3, "Once");
|
|
|
|
NewFilm->RunOnce = IsPropertyTrue (Dict2);
|
|
|
|
|
|
|
|
NewFilm->GetFrames(ThemeX); //used properties: ID, Path, NumFrames
|
|
|
|
ThemeX.Cinema.AddFilm(NewFilm);
|
|
|
|
// delete NewFilm; //looks like already deleted
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2020-03-29 18:17:27 +02:00
|
|
|
// nsvgDeleteRasterizer(rast);
|
2020-03-28 19:34:23 +01:00
|
|
|
|
2020-03-29 18:17:27 +02:00
|
|
|
TypeSVG = TRUE;
|
|
|
|
ThemeDesignHeight = (int)SVGimage->height;
|
|
|
|
ThemeDesignWidth = (int)SVGimage->width;
|
|
|
|
if (SelectionOnTop) {
|
|
|
|
row0TileSize = (INTN)(144.f * Scale);
|
|
|
|
row1TileSize = (INTN)(64.f * Scale);
|
|
|
|
MainEntriesSize = (INTN)(128.f * Scale);
|
2020-03-28 19:34:23 +01:00
|
|
|
}
|
2020-04-04 07:50:30 +02:00
|
|
|
// DBG("parsing svg theme finished\n");
|
2020-03-28 19:34:23 +01:00
|
|
|
|
2020-03-27 20:47:06 +01:00
|
|
|
return Status;
|
|
|
|
}
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-04-14 18:52:13 +02:00
|
|
|
EFI_STATUS XTheme::LoadSvgFrame(INTN i, OUT XImage* XFrame)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status = EFI_NOT_FOUND;
|
2020-04-14 21:49:45 +02:00
|
|
|
XString XFrameName = SPrintf("frame_%04lld", i+1);
|
2020-04-15 22:12:43 +02:00
|
|
|
Status = ParseSVGXIcon(BUILTIN_ICON_ANIME, XFrameName, XFrame);
|
2020-04-14 18:52:13 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
DBG("frame '%s' not loaded, status=%s\n", XFrameName.c_str(), strerror(Status));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-03-21 08:34:28 +01:00
|
|
|
// it is not draw, it is render and mainly used in egRenderText
|
2020-03-29 18:17:27 +02:00
|
|
|
// which is used in icns.cpp as an icon replacement if no image found, looks like not used
|
2020-03-21 08:34:28 +01:00
|
|
|
// in menu.cpp 3 places
|
2019-09-03 11:58:42 +02:00
|
|
|
//textType = 0-help 1-message 2-menu 3-test
|
|
|
|
//return text width in pixels
|
2020-04-10 05:11:00 +02:00
|
|
|
//it is not theme member!
|
2020-03-31 17:59:35 +02:00
|
|
|
INTN renderSVGtext(XImage* TextBufferXY_ptr, INTN posX, INTN posY, INTN textType, const XStringW& string, UINTN Cursor)
|
2020-03-20 21:10:08 +01:00
|
|
|
{
|
2020-03-31 17:59:35 +02:00
|
|
|
XImage& TextBufferXY = *TextBufferXY_ptr;
|
2020-03-20 21:10:08 +01:00
|
|
|
INTN Width;
|
2020-04-15 23:04:33 +02:00
|
|
|
// UINTN i;
|
2020-03-20 21:10:08 +01:00
|
|
|
UINTN len;
|
|
|
|
NSVGparser* p;
|
|
|
|
NSVGrasterizer* rast;
|
|
|
|
if (!textFace[textType].valid) {
|
2020-04-15 23:04:33 +02:00
|
|
|
for (decltype(textType) i=0; i<4; i++) {
|
2020-03-20 21:10:08 +01:00
|
|
|
if (textFace[i].valid) {
|
|
|
|
textType = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!textFace[textType].valid) {
|
|
|
|
DBG("valid fontface not found!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
NSVGfont* fontSVG = textFace[textType].font;
|
|
|
|
UINT32 color = textFace[textType].color;
|
2020-03-26 09:18:28 +01:00
|
|
|
INTN Height = (INTN)(textFace[textType].size * ThemeX.Scale);
|
2020-03-20 21:10:08 +01:00
|
|
|
float Scale, sy;
|
|
|
|
float x, y;
|
|
|
|
if (!fontSVG) {
|
2020-03-21 08:34:28 +01:00
|
|
|
DBG("no font for renderSVGtext\n");
|
2020-03-20 21:10:08 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
p = nsvg__createParser();
|
|
|
|
if (!p) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
NSVGtext* text = (NSVGtext*)AllocateZeroPool(sizeof(NSVGtext));
|
|
|
|
if (!text) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
text->font = fontSVG;
|
|
|
|
text->fontColor = color;
|
|
|
|
text->fontSize = (float)Height;
|
|
|
|
nsvg__xformIdentity(text->xform);
|
|
|
|
p->text = text;
|
|
|
|
|
2020-04-09 18:32:46 +02:00
|
|
|
len = string.size();
|
2020-03-20 21:10:08 +01:00
|
|
|
Width = TextBufferXY.GetWidth();
|
2020-04-10 05:11:00 +02:00
|
|
|
if ( fontSVG->unitsPerEm < 1.f ) {
|
2020-03-20 21:10:08 +01:00
|
|
|
fontSVG->unitsPerEm = 1000.f;
|
|
|
|
}
|
|
|
|
float fH = fontSVG->bbox[3] - fontSVG->bbox[1]; //1250
|
|
|
|
if (fH == 0.f) {
|
2020-03-26 18:00:53 +01:00
|
|
|
DBG("wrong font: %f\n", fontSVG->unitsPerEm);
|
2020-03-20 21:10:08 +01:00
|
|
|
DumpFloat2("Font bbox", fontSVG->bbox, 4);
|
2020-04-10 05:11:00 +02:00
|
|
|
fH = (fontSVG->unitsPerEm > 1.f) ? fontSVG->unitsPerEm : 1000.0f; //1000
|
2020-03-20 21:10:08 +01:00
|
|
|
}
|
|
|
|
sy = (float)Height / fH; //(float)fontSVG->unitsPerEm; // 260./1250.
|
|
|
|
Scale = sy;
|
|
|
|
x = (float)posX; //0.f;
|
|
|
|
y = (float)posY + fontSVG->bbox[1] * Scale;
|
|
|
|
p->isText = TRUE;
|
2020-04-15 23:04:33 +02:00
|
|
|
for (UINTN i=0; i < len; i++) {
|
2020-04-09 18:32:46 +02:00
|
|
|
CHAR16 letter = string.wc_str()[i];
|
2020-03-20 21:10:08 +01:00
|
|
|
if (!letter) {
|
|
|
|
break;
|
|
|
|
}
|
2020-04-10 05:11:00 +02:00
|
|
|
// DBG("add letter 0x%X\n", letter);
|
2020-03-20 21:10:08 +01:00
|
|
|
if (i == Cursor) {
|
|
|
|
addLetter(p, 0x5F, x, y, sy, color);
|
|
|
|
}
|
|
|
|
x = addLetter(p, letter, x, y, sy, color);
|
|
|
|
} //end of string
|
|
|
|
|
|
|
|
p->image->realBounds[0] = fontSVG->bbox[0] * Scale;
|
|
|
|
p->image->realBounds[1] = fontSVG->bbox[1] * Scale;
|
|
|
|
p->image->realBounds[2] = fontSVG->bbox[2] * Scale + x; //last bound
|
|
|
|
p->image->realBounds[3] = fontSVG->bbox[3] * Scale;
|
|
|
|
rast = nsvgCreateRasterizer();
|
|
|
|
nsvgRasterize(rast, p->image, 0, 0, 1.f, 1.f, (UINT8*)TextBufferXY.GetPixelPtr(0,0),
|
2020-03-22 11:48:13 +01:00
|
|
|
(int)TextBufferXY.GetWidth(), (int)TextBufferXY.GetHeight(), (int)(Width*4));
|
2020-03-20 21:10:08 +01:00
|
|
|
float RealWidth = p->image->realBounds[2] - p->image->realBounds[0];
|
|
|
|
|
|
|
|
nsvgDeleteRasterizer(rast);
|
|
|
|
// nsvg__deleteParser(p);
|
|
|
|
nsvgDelete(p->image);
|
|
|
|
return (INTN)RealWidth; //x;
|
|
|
|
}
|
2019-09-03 11:58:42 +02:00
|
|
|
VOID testSVG()
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT8 *FileData = NULL;
|
|
|
|
UINTN FileDataLength = 0;
|
|
|
|
|
|
|
|
INTN Width = 400, Height = 400;
|
|
|
|
|
|
|
|
#if TEST_MATH
|
|
|
|
//Test mathematique
|
|
|
|
//#define fabsf(x) ((x >= 0.0f)?x:(-x))
|
|
|
|
#define pr(x) (int)fabsf(x), (int)fabsf((x - (int)x) * 1000000.0f)
|
|
|
|
int i;
|
|
|
|
float x, y1, y2;
|
|
|
|
// CHAR8 Str[128];
|
|
|
|
DBG("Test float: -%d.%06d\n", pr(-0.7612f));
|
|
|
|
for (i=0; i<15; i++) {
|
|
|
|
x=(PI)/30.0f*i;
|
|
|
|
y1=SinF(x);
|
|
|
|
y2=CosF(x);
|
|
|
|
|
|
|
|
DBG("x=%d: %d.%06d ", i*6, pr(x));
|
|
|
|
DBG(" sinx=%c%d.%06d", (y1<0)?'-':' ', pr(y1));
|
|
|
|
DBG(" cosx=%c%d.%06d\n", (y2<0)?'-':' ',pr(y2));
|
|
|
|
y1 = Atan2F(y1, y2);
|
|
|
|
DBG(" atan2x=%c%d.%06d", (y1<0)?'-':' ',pr(y1));
|
|
|
|
y1 = AcosF(y2);
|
|
|
|
DBG(" acos=%c%d.%06d", (y1<0)?'-':' ',pr(y1));
|
|
|
|
y1 = SqrtF(x);
|
|
|
|
DBG(" sqrt=%d.%06d", pr(y1));
|
|
|
|
y1 = CeilF(x);
|
|
|
|
DBG(" ceil=%c%d.%06d\n", (y1<0)?'-':' ',pr(y1));
|
|
|
|
}
|
|
|
|
#undef pr
|
|
|
|
#endif
|
|
|
|
NSVGparser* p;
|
|
|
|
#if TEST_DITHER
|
|
|
|
{
|
|
|
|
EG_IMAGE *RndImage = egCreateImage(256, 256, FALSE);
|
|
|
|
INTN i,j;
|
|
|
|
EG_PIXEL pixel = WhitePixel;
|
|
|
|
for (i=0; i<256; i++) {
|
|
|
|
for (j=0; j<256; j++) {
|
|
|
|
pixel.b = 0x40 + (dither((float)j / 32.0f, 1) * 8);
|
|
|
|
pixel.r = 0x0;
|
|
|
|
pixel.g = 0x0;
|
|
|
|
// if (i==1) {
|
2020-03-25 19:32:44 +01:00
|
|
|
// DBG("r=%X g=%X\n", pixel.r, pixel.g);
|
2019-09-03 11:58:42 +02:00
|
|
|
// }
|
|
|
|
RndImage->PixelData[i * 256 + j] = pixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BltImageAlpha(RndImage,
|
|
|
|
20,
|
|
|
|
20,
|
|
|
|
&MenuBackgroundPixel,
|
|
|
|
16);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if TEST_SVG_IMAGE
|
|
|
|
NSVGrasterizer* rast = nsvgCreateRasterizer();
|
2020-04-01 14:57:32 +02:00
|
|
|
// EG_IMAGE *NewImage;
|
2019-09-03 11:58:42 +02:00
|
|
|
NSVGimage *SVGimage;
|
|
|
|
float Scale, ScaleX, ScaleY;
|
|
|
|
|
|
|
|
// load file
|
|
|
|
Status = egLoadFile(SelfRootDir, L"Sample.svg", &FileData, &FileDataLength);
|
|
|
|
if (!EFI_ERROR(Status)) {
|
|
|
|
//Parse XML to vector data
|
|
|
|
|
|
|
|
p = nsvgParse((CHAR8*)FileData, 72, 1.f);
|
|
|
|
SVGimage = p->image;
|
|
|
|
DBG("Test image width=%d heigth=%d\n", (int)(SVGimage->width), (int)(SVGimage->height));
|
|
|
|
// FreePool(FileData);
|
|
|
|
/*
|
|
|
|
if (p->patterns && p->patterns->image) {
|
|
|
|
BltImageAlpha((EG_IMAGE*)(p->patterns->image),
|
|
|
|
40,
|
|
|
|
40,
|
|
|
|
&MenuBackgroundPixel,
|
|
|
|
16);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// Rasterize
|
2020-04-01 14:57:32 +02:00
|
|
|
XImage NewImage(Width, Height);
|
2019-09-03 11:58:42 +02:00
|
|
|
if (SVGimage->width <= 0) SVGimage->width = (float)Width;
|
|
|
|
if (SVGimage->height <= 0) SVGimage->height = (float)Height;
|
|
|
|
|
|
|
|
ScaleX = Width / SVGimage->width;
|
|
|
|
ScaleY = Height / SVGimage->height;
|
|
|
|
Scale = (ScaleX > ScaleY)?ScaleY:ScaleX;
|
|
|
|
float tx = 0; //-SVGimage->realBounds[0] * Scale;
|
|
|
|
float ty = 0; //-SVGimage->realBounds[1] * Scale;
|
2020-04-19 13:23:23 +02:00
|
|
|
DBG("timing rasterize start tx=%f ty=%f\n", tx, ty); //the aim is measure duration
|
2020-04-01 14:57:32 +02:00
|
|
|
nsvgRasterize(rast, SVGimage, tx,ty,Scale,Scale, (UINT8*)NewImage.GetPixelPtr(0,0), (int)Width, (int)Height, (int)Width*4);
|
|
|
|
DBG("timing rasterize end\n");
|
|
|
|
NewImage.Draw((UGAWidth - Width) / 2,
|
|
|
|
(UGAHeight - Height) / 2);
|
2019-09-03 11:58:42 +02:00
|
|
|
FreePool(FileData);
|
|
|
|
FileData = NULL;
|
2020-04-01 14:57:32 +02:00
|
|
|
//
|
2020-03-10 14:00:02 +01:00
|
|
|
// nsvg__deleteParser(p);
|
2019-09-03 11:58:42 +02:00
|
|
|
nsvgDeleteRasterizer(rast);
|
2020-03-06 15:02:06 +01:00
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-03-06 15:02:06 +01:00
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
#endif
|
|
|
|
//Test text
|
|
|
|
Height = 80;
|
|
|
|
Width = UGAWidth-200;
|
2020-04-04 07:50:30 +02:00
|
|
|
// DBG("create test textbuffer\n");
|
2020-03-21 08:34:28 +01:00
|
|
|
XImage TextBufferXY(Width, Height);
|
2019-09-03 11:58:42 +02:00
|
|
|
Status = egLoadFile(SelfRootDir, L"Font.svg", &FileData, &FileDataLength);
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG("test Font.svg loaded status=%s\n", strerror(Status));
|
2019-09-03 11:58:42 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
|
|
|
p = nsvgParse((CHAR8*)FileData, 72, 1.f);
|
|
|
|
if (!p) {
|
|
|
|
DBG("font not parsed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// NSVGfont* fontSVG = p->font;
|
|
|
|
textFace[3].font = p->font;
|
|
|
|
textFace[3].color = NSVG_RGBA(0x80, 0xFF, 0, 255);
|
|
|
|
textFace[3].size = Height;
|
2020-03-25 19:32:44 +01:00
|
|
|
// DBG("font parsed family=%s\n", p->font->fontFamily);
|
2019-09-03 11:58:42 +02:00
|
|
|
FreePool(FileData);
|
|
|
|
// Scale = Height / fontSVG->unitsPerEm;
|
2020-04-10 12:04:21 +02:00
|
|
|
|
2020-03-31 17:59:35 +02:00
|
|
|
renderSVGtext(&TextBufferXY, 0, 0, 3, XStringW().takeValueFrom("Clover Кловер"), 1);
|
2019-09-03 11:58:42 +02:00
|
|
|
// DBG("text ready to blit\n");
|
2020-03-21 08:34:28 +01:00
|
|
|
TextBufferXY.Draw((UGAWidth - Width) / 2,
|
2020-03-25 18:49:01 +01:00
|
|
|
(UGAHeight - Height) / 2);
|
2019-09-03 11:58:42 +02:00
|
|
|
// nsvg__deleteParser(p);
|
|
|
|
// DBG("draw finished\n");
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
}
|