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

@ -70,3 +70,12 @@ float CAnimatedVariable::getPercent() {
const auto DURATIONPASSED = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - animationBegin).count(); 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); 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 "../defines.hpp"
#include <any> #include <any>
enum ANIMATEDVARTYPE enum ANIMATEDVARTYPE {
{
AVARTYPE_INVALID = -1, AVARTYPE_INVALID = -1,
AVARTYPE_FLOAT, AVARTYPE_FLOAT,
AVARTYPE_VECTOR, AVARTYPE_VECTOR,
AVARTYPE_COLOR AVARTYPE_COLOR
}; };
enum AVARDAMAGEPOLICY enum AVARDAMAGEPOLICY {
{
AVARDAMAGE_INVALID = -1, AVARDAMAGE_INVALID = -1,
AVARDAMAGE_ENTIRE = 0, AVARDAMAGE_ENTIRE = 0,
AVARDAMAGE_BORDER, AVARDAMAGE_BORDER,
@ -190,6 +188,9 @@ class CAnimatedVariable {
/* returns the spent (completion) % */ /* returns the spent (completion) % */
float getPercent(); float getPercent();
/* returns the current curve value */
float getCurveValue();
/* sets a function to be ran when the animation finishes. /* sets a function to be ran when the animation finishes.
if an animation is not running, runs instantly. if an animation is not running, runs instantly.
if "remove" is set to true, will remove the callback when ran. */ 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(); const auto EXTENTS = PDECO->getWindowDecorationExtents();
wlr_box dmg = {PWINDOW->m_vRealPosition.vec().x - EXTENTS.topLeft.x, PWINDOW->m_vRealPosition.vec().y - EXTENTS.topLeft.y, 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().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x,
PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y}; PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y};
if (!*PSHADOWIGNOREWINDOW) { if (!*PSHADOWIGNOREWINDOW) {
// easy, damage the entire box // easy, damage the entire box
@ -458,3 +458,9 @@ std::string CAnimationManager::styleValidInConfigVar(const std::string& config,
return ""; 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); void onWindowPostCreateClose(CWindow*, bool close = false);
bool bezierExists(const std::string&); bool bezierExists(const std::string&);
CBezierCurve* getBezier(const std::string&);
std::string styleValidInConfigVar(const std::string&, 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 PSPECIALWORKSPACE = g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID);
const auto SPECIALANIMPROGRS = 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; const bool ANIMOUT = !PMONITOR->specialWorkspaceID;