hyprlock/src/renderer/widgets/Shadowable.cpp

42 lines
1.3 KiB
C++
Raw Normal View History

2024-03-05 21:24:11 +01:00
#include "Shadowable.hpp"
#include "../Renderer.hpp"
CShadowable::CShadowable(IWidget* widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_) : widget(widget_), viewport(viewport_) {
size = std::any_cast<Hyprlang::INT>(props.at("shadow_size"));
passes = std::any_cast<Hyprlang::INT>(props.at("shadow_passes"));
color = std::any_cast<Hyprlang::INT>(props.at("shadow_color"));
boostA = std::any_cast<Hyprlang::FLOAT>(props.at("shadow_boost"));
}
void CShadowable::markShadowDirty() {
2024-03-05 21:28:29 +01:00
if (passes == 0)
return;
2024-03-05 21:24:11 +01:00
if (!shadowFB.isAllocated())
shadowFB.alloc(viewport.x, viewport.y, true);
g_pRenderer->pushFb(shadowFB.m_iFb);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
ignoreDraw = true;
widget->draw(IWidget::SRenderData{.opacity = 1.0});
ignoreDraw = false;
g_pRenderer->blurFB(shadowFB, CRenderer::SBlurParams{.size = size, .passes = passes, .colorize = color, .boostA = boostA});
g_pRenderer->popFb();
}
bool CShadowable::draw(const IWidget::SRenderData& data) {
2024-03-05 21:28:29 +01:00
if (passes == 0)
2024-03-05 21:31:31 +01:00
return true;
2024-03-05 21:28:29 +01:00
2024-03-05 21:24:11 +01:00
if (!shadowFB.isAllocated() || ignoreDraw)
return true;
CBox box = {0, 0, viewport.x, viewport.y};
g_pRenderer->renderTexture(box, shadowFB.m_cTex, 1.0, 0, WL_OUTPUT_TRANSFORM_NORMAL);
return true;
}