use curves for special dim anim

This commit is contained in:
Vaxry 2022-12-29 12:30:43 +01:00
parent 759490689c
commit 5d095bb9e1
5 changed files with 24 additions and 7 deletions

View File

@ -69,4 +69,13 @@ int CAnimatedVariable::getDurationLeftMs() {
float CAnimatedVariable::getPercent() {
const auto DURATIONPASSED = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - animationBegin).count();
return std::clamp((DURATIONPASSED / 100.f) / m_pConfig->pValues->internalSpeed, 0.f, 1.f);
}
float CAnimatedVariable::getCurveValue() {
const auto SPENT = getPercent();
if (SPENT >= 1.f)
return 1.f;
return g_pAnimationManager->getBezier(m_pConfig->pValues->internalBezier)->getYForPoint(SPENT);
}

View File

@ -3,16 +3,14 @@
#include "../defines.hpp"
#include <any>
enum ANIMATEDVARTYPE
{
enum ANIMATEDVARTYPE {
AVARTYPE_INVALID = -1,
AVARTYPE_FLOAT,
AVARTYPE_VECTOR,
AVARTYPE_COLOR
};
enum AVARDAMAGEPOLICY
{
enum AVARDAMAGEPOLICY {
AVARDAMAGE_INVALID = -1,
AVARDAMAGE_ENTIRE = 0,
AVARDAMAGE_BORDER,
@ -190,6 +188,9 @@ class CAnimatedVariable {
/* returns the spent (completion) % */
float getPercent();
/* returns the current curve value */
float getCurveValue();
/* sets a function to be ran when the animation finishes.
if an animation is not running, runs instantly.
if "remove" is set to true, will remove the callback when ran. */

View File

@ -201,8 +201,8 @@ void CAnimationManager::tick() {
const auto EXTENTS = PDECO->getWindowDecorationExtents();
wlr_box dmg = {PWINDOW->m_vRealPosition.vec().x - EXTENTS.topLeft.x, PWINDOW->m_vRealPosition.vec().y - EXTENTS.topLeft.y,
PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x,
PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y};
PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x,
PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y};
if (!*PSHADOWIGNOREWINDOW) {
// easy, damage the entire box
@ -458,3 +458,9 @@ std::string CAnimationManager::styleValidInConfigVar(const std::string& config,
return "";
}
CBezierCurve* CAnimationManager::getBezier(const std::string& name) {
const auto BEZIER = std::find_if(m_mBezierCurves.begin(), m_mBezierCurves.end(), [&](const auto& other) { return other.first == name; });
return BEZIER == m_mBezierCurves.end() ? &m_mBezierCurves["default"] : &BEZIER->second;
}

View File

@ -18,6 +18,7 @@ class CAnimationManager {
void onWindowPostCreateClose(CWindow*, bool close = false);
bool bezierExists(const std::string&);
CBezierCurve* getBezier(const std::string&);
std::string styleValidInConfigVar(const std::string&, const std::string&);

View File

@ -506,7 +506,7 @@ void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) {
const auto PSPECIALWORKSPACE = g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID);
const auto SPECIALANIMPROGRS =
PSPECIALWORKSPACE->m_vRenderOffset.isBeingAnimated() ? PSPECIALWORKSPACE->m_vRenderOffset.getPercent() : PSPECIALWORKSPACE->m_fAlpha.getPercent();
PSPECIALWORKSPACE->m_vRenderOffset.isBeingAnimated() ? PSPECIALWORKSPACE->m_vRenderOffset.getCurveValue() : PSPECIALWORKSPACE->m_fAlpha.getCurveValue();
const bool ANIMOUT = !PMONITOR->specialWorkspaceID;