hyprlock/src/renderer/widgets/Shadowable.cpp
Abhinav Anil 1c92c6109c
renderer: add fade out animation and property to disable (#188)
* renderer, Nix/HM module: add fade out animation and prop

* fix: fade duration and disable on non hyprland session

* fix: revert needsFrame condition, update duration to 500ms

* fix: make shadows obey widget opacity
2024-03-14 13:23:41 +00:00

42 lines
No EOL
1.3 KiB
C++

#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() {
if (passes == 0)
return;
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) {
if (passes == 0)
return true;
if (!shadowFB.isAllocated() || ignoreDraw)
return true;
CBox box = {0, 0, viewport.x, viewport.y};
g_pRenderer->renderTexture(box, shadowFB.m_cTex, data.opacity, 0, WL_OUTPUT_TRANSFORM_NORMAL);
return true;
}