Keep blank miku in cache
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
237a82b1bc
commit
991a99d0b3
1 changed files with 11 additions and 9 deletions
|
@ -41,7 +41,7 @@ struct CardinalBlankModule : Module {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CardinalBlankImage : Widget {
|
struct CardinalBlankImage : Widget {
|
||||||
int imageId = -2;
|
std::shared_ptr<Image> image;
|
||||||
int imageWidth = 0;
|
int imageWidth = 0;
|
||||||
int imageHeight = 0;
|
int imageHeight = 0;
|
||||||
bool hasModule;
|
bool hasModule;
|
||||||
|
@ -53,26 +53,28 @@ struct CardinalBlankImage : Widget {
|
||||||
|
|
||||||
void draw(const DrawArgs& args) override
|
void draw(const DrawArgs& args) override
|
||||||
{
|
{
|
||||||
if (imageId == -2)
|
Image* img = image.get();
|
||||||
{
|
|
||||||
imageId = nvgCreateImage(args.vg, asset::plugin(pluginInstance, "res/Miku/Miku.png").c_str(), 0);
|
|
||||||
|
|
||||||
if (imageId != -1)
|
if (img == nullptr)
|
||||||
nvgImageSize(args.vg, imageId, &imageWidth, &imageHeight);
|
{
|
||||||
|
image = APP->window->loadImage(asset::plugin(pluginInstance, "res/Miku/Miku.png"));
|
||||||
|
|
||||||
|
if ((img = image.get()) != nullptr)
|
||||||
|
nvgImageSize(args.vg, img->handle, &imageWidth, &imageHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageId != -1 && imageWidth != 0 && imageHeight != 0)
|
if (img != nullptr && imageWidth != 0 && imageHeight != 0)
|
||||||
{
|
{
|
||||||
const float pixelRatio = hasModule ? APP->window->pixelRatio : 1.0f;
|
const float pixelRatio = hasModule ? APP->window->pixelRatio : 1.0f;
|
||||||
const float boxscale = std::min(box.size.x / imageWidth, box.size.y / imageHeight);
|
const float boxscale = std::min(box.size.x / imageWidth, box.size.y / imageHeight);
|
||||||
const float imgHeight = (imageHeight / pixelRatio) * boxscale;
|
const float imgHeight = (imageHeight / pixelRatio) * boxscale;
|
||||||
nvgBeginPath(args.vg);
|
nvgBeginPath(args.vg);
|
||||||
nvgRect(args.vg, 0, 0, box.size.x, box.size.y);
|
nvgRect(args.vg, 0, box.size.y * 0.5f - imgHeight * 0.5f, box.size.x, imgHeight);
|
||||||
nvgFillPaint(args.vg, nvgImagePattern(args.vg,
|
nvgFillPaint(args.vg, nvgImagePattern(args.vg,
|
||||||
0,
|
0,
|
||||||
(box.size.y / pixelRatio) * 0.5f - imgHeight * 0.5f,
|
(box.size.y / pixelRatio) * 0.5f - imgHeight * 0.5f,
|
||||||
box.size.x / pixelRatio,
|
box.size.x / pixelRatio,
|
||||||
imgHeight, 0, imageId, 1.0f));
|
imgHeight, 0, img->handle, 1.0f));
|
||||||
nvgFill(args.vg);
|
nvgFill(args.vg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue