hyprlock/src/renderer/widgets/Background.cpp

41 lines
1.2 KiB
C++
Raw Normal View History

2024-02-19 00:08:03 +01:00
#include "Background.hpp"
#include "../Renderer.hpp"
CBackground::CBackground(const Vector2D& viewport_, const std::string& resourceID_, const CColor& color_) : viewport(viewport_), resourceID(resourceID_), color(color_) {
2024-02-19 00:08:03 +01:00
;
}
2024-02-19 17:26:08 +01:00
bool CBackground::draw(const SRenderData& data) {
if (resourceID.empty()) {
CBox monbox = {0, 0, viewport.x, viewport.y};
CColor col = color;
col.a *= data.opacity;
g_pRenderer->renderRect(monbox, col, 0);
return data.opacity < 1.0;
}
2024-02-19 00:08:03 +01:00
if (!asset)
asset = g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID);
if (!asset)
return false;
2024-02-20 01:26:13 +01:00
CBox texbox = {{}, asset->texture.m_vSize};
2024-02-19 00:08:03 +01:00
2024-02-20 01:26:13 +01:00
Vector2D size = asset->texture.m_vSize;
float scaleX = viewport.x / asset->texture.m_vSize.x;
2024-02-20 17:02:40 +01:00
float scaleY = viewport.y / asset->texture.m_vSize.y;
2024-02-20 01:26:13 +01:00
texbox.w *= std::max(scaleX, scaleY);
texbox.h *= std::max(scaleX, scaleY);
if (scaleX > scaleY)
texbox.y = -(texbox.h - viewport.y) / 2.f;
else
texbox.x = -(texbox.w - viewport.x) / 2.f;
g_pRenderer->renderTexture(texbox, asset->texture, data.opacity);
2024-02-19 00:08:03 +01:00
2024-02-19 17:26:08 +01:00
return data.opacity < 1.0;
2024-02-19 00:08:03 +01:00
}