From 0147975faf939db389bebaa95e3a12e5e5a8753f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:16:02 +0200 Subject: New animation system --- src/managers/AnimationManager.cpp | 142 +++++++++++++------------------------- src/managers/AnimationManager.hpp | 3 + src/managers/InputManager.cpp | 12 ++-- src/managers/KeybindManager.cpp | 20 +++--- src/managers/XWaylandManager.cpp | 4 +- 5 files changed, 70 insertions(+), 111 deletions(-) (limited to 'src/managers') diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index f77c3d7c..d4a71f37 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -8,115 +8,71 @@ void CAnimationManager::tick() { if (!g_pConfigManager->getInt("animations:enabled")) animationsDisabled = true; - const bool WINDOWSENABLED = g_pConfigManager->getInt("animations:windows") && !animationsDisabled; - const bool BORDERSENABLED = g_pConfigManager->getInt("animations:borders") && !animationsDisabled; - const bool FADEENABLED = g_pConfigManager->getInt("animations:fadein") && !animationsDisabled; const float ANIMSPEED = g_pConfigManager->getFloat("animations:speed"); - // Process speeds - const float WINDOWSPEED = g_pConfigManager->getFloat("animations:windows_speed") == 0 ? ANIMSPEED : g_pConfigManager->getFloat("animations:windows_speed"); - const float BORDERSPEED = g_pConfigManager->getFloat("animations:borders_speed") == 0 ? ANIMSPEED : g_pConfigManager->getFloat("animations:borders_speed"); - const float FADESPEED = g_pConfigManager->getFloat("animations:fadein_speed") == 0 ? ANIMSPEED : g_pConfigManager->getFloat("animations:fadein_speed"); - - const auto BORDERACTIVECOL = CColor(g_pConfigManager->getInt("general:col.active_border")); - const auto BORDERINACTIVECOL = CColor(g_pConfigManager->getInt("general:col.inactive_border")); - const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size"); - for (auto& w : g_pCompositor->m_lWindows) { - - // get the box before transforms, for damage tracking later - wlr_box WLRBOXPREV = { w.m_vRealPosition.x - BORDERSIZE - 1, w.m_vRealPosition.y - BORDERSIZE - 1, w.m_vRealSize.x + 2 * BORDERSIZE + 2, w.m_vRealSize.y + 2 * BORDERSIZE + 2}; - bool needsDamage = false; - - // process fadeinout - if (FADEENABLED) { - const auto GOALALPHA = w.m_bIsMapped ? 255.f : 0.f; - w.m_bFadingOut = false; - - if (!deltazero(w.m_fAlpha, GOALALPHA)) { - if (deltaSmallToFlip(w.m_fAlpha, GOALALPHA)) { - w.m_fAlpha = GOALALPHA; - } else { - if (w.m_fAlpha > GOALALPHA) - w.m_bFadingOut = true; - w.m_fAlpha = parabolic(w.m_fAlpha, GOALALPHA, FADESPEED); - } - - needsDamage = true; - } - - } else { - const auto GOALALPHA = w.m_bIsMapped ? 255.f : 0.f; - - if (!deltazero(GOALALPHA, w.m_fAlpha)) { - if (w.m_bIsMapped) - w.m_fAlpha = 255.f; - else { - w.m_fAlpha = 0.f; - w.m_bFadingOut = false; - } - - needsDamage = true; - } - } - - // process fadein/out for unmapped windows, but nothing else. - // we can't use windowValidMapped because we want to animate hidden windows too. - if (!g_pCompositor->windowExists(&w) || !w.m_bIsMapped || !g_pXWaylandManager->getWindowSurface(&w)){ - if (needsDamage) { - g_pHyprRenderer->damageWindow(&w); // only window, it didnt move cuz its unmappy - } - + for (auto& av : m_lAnimatedVariables) { + // first, we check if it's disabled, if so, warp + if (av->m_pEnabled == 0 || animationsDisabled) { + av->warp(); continue; } - // process the borders - const auto RENDERHINTS = g_pLayoutManager->getCurrentLayout()->requestRenderHints(&w); - - const auto& COLOR = RENDERHINTS.isBorderColor ? RENDERHINTS.borderColor : g_pCompositor->isWindowActive(&w) ? BORDERACTIVECOL : BORDERINACTIVECOL; + // get speed + const auto SPEED = *av->m_pSpeed == 0 ? ANIMSPEED : *av->m_pSpeed; - if (BORDERSENABLED) { - if (!deltazero(COLOR, w.m_cRealBorderColor)) { - if (deltaSmallToFlip(COLOR, w.m_cRealBorderColor)) { - w.m_cRealBorderColor = COLOR; - } else { - w.m_cRealBorderColor = parabolic(BORDERSPEED, w.m_cRealBorderColor, COLOR); + // window stuff + const auto PWINDOW = (CWindow*)av->m_pWindow; + bool needsDamage = false; + wlr_box WLRBOXPREV = {PWINDOW->m_vRealPosition.vec().x - BORDERSIZE - 1, PWINDOW->m_vRealPosition.vec().y - BORDERSIZE - 1, PWINDOW->m_vRealSize.vec().x + 2 * BORDERSIZE + 2, PWINDOW->m_vRealSize.vec().y + 2 * BORDERSIZE + 2}; + + // TODO: curves + + // parabolic with a switch unforto + // TODO: maybe do something cleaner + switch (av->m_eVarType) { + case AVARTYPE_FLOAT: { + if (!deltazero(av->m_fValue, av->m_fGoal)) { + if (deltaSmallToFlip(av->m_fValue, av->m_fGoal)) { + av->warp(); + } else { + av->m_fValue = parabolic(av->m_fValue, av->m_fGoal, SPEED); + } + + needsDamage = true; } - needsDamage = true; + break; } - } else { - if (!deltazero(w.m_cRealBorderColor, COLOR)) - needsDamage = true; - w.m_cRealBorderColor = COLOR; - } - - // process the window - if (WINDOWSENABLED) { - if (!deltazero(w.m_vRealPosition, w.m_vEffectivePosition) || !deltazero(w.m_vRealSize, w.m_vEffectiveSize)) { - if (deltaSmallToFlip(w.m_vRealPosition, w.m_vEffectivePosition) && deltaSmallToFlip(w.m_vRealSize, w.m_vEffectiveSize)) { - w.m_vRealPosition = w.m_vEffectivePosition; - w.m_vRealSize = w.m_vEffectiveSize; - g_pXWaylandManager->setWindowSize(&w, w.m_vRealSize); - } else { - // if it is to be animated, animate it. - w.m_vRealPosition = Vector2D(parabolic(w.m_vRealPosition.x, w.m_vEffectivePosition.x, WINDOWSPEED), parabolic(w.m_vRealPosition.y, w.m_vEffectivePosition.y, WINDOWSPEED)); - w.m_vRealSize = Vector2D(parabolic(w.m_vRealSize.x, w.m_vEffectiveSize.x, WINDOWSPEED), parabolic(w.m_vRealSize.y, w.m_vEffectiveSize.y, WINDOWSPEED)); + case AVARTYPE_VECTOR: { + if (!deltazero(av->m_vValue, av->m_vGoal)) { + if (deltaSmallToFlip(av->m_vValue, av->m_vGoal)) { + av->warp(); + } else { + av->m_vValue.x = parabolic(av->m_vValue.x, av->m_vGoal.x, SPEED); + av->m_vValue.y = parabolic(av->m_vValue.y, av->m_vGoal.y, SPEED); + } + needsDamage = true; } - - needsDamage = true; + break; + } + case AVARTYPE_COLOR: { + if (!deltazero(av->m_cValue, av->m_cGoal)) { + if (deltaSmallToFlip(av->m_cValue, av->m_cGoal)) { + av->warp(); + } else { + av->m_cValue = parabolic(SPEED, av->m_cValue, av->m_cGoal); + } + needsDamage = true; + } + break; } - } else { - if (!deltazero(w.m_vRealPosition, w.m_vEffectivePosition) || !deltazero(w.m_vRealSize, w.m_vEffectiveSize)) - needsDamage = true; - - w.m_vRealPosition = w.m_vEffectivePosition; - w.m_vRealSize = w.m_vEffectiveSize; } + // invalidate the window if (needsDamage) { g_pHyprRenderer->damageBox(&WLRBOXPREV); - g_pHyprRenderer->damageWindow(&w); + g_pHyprRenderer->damageWindow(PWINDOW); } } } diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index 8d2c86b6..14d6c3ac 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -2,12 +2,15 @@ #include "../defines.hpp" #include +#include "../helpers/AnimatedVariable.hpp" class CAnimationManager { public: void tick(); + std::list m_lAnimatedVariables; + private: bool deltaSmallToFlip(const Vector2D& a, const Vector2D& b); bool deltaSmallToFlip(const CColor& a, const CColor& b); diff --git a/src/managers/InputManager.cpp b/src/managers/InputManager.cpp index 219acdac..4166fd22 100644 --- a/src/managers/InputManager.cpp +++ b/src/managers/InputManager.cpp @@ -57,11 +57,11 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); for (auto w = g_pCompositor->m_lWindows.rbegin(); w != g_pCompositor->m_lWindows.rend(); ++w) { - wlr_box box = {w->m_vRealPosition.x, w->m_vRealPosition.y, w->m_vRealSize.x, w->m_vRealSize.y}; + wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; if (w->m_iWorkspaceID == pFoundWindow->m_iWorkspaceID && w->m_bIsMapped && w->m_bCreatedOverFullscreen && wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y)) { foundSurface = g_pXWaylandManager->getWindowSurface(&(*w)); if (foundSurface) - surfacePos = w->m_vRealPosition; + surfacePos = w->m_vRealPosition.vec(); break; } } @@ -70,7 +70,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (pFoundWindow->m_bIsX11) { foundSurface = g_pXWaylandManager->getWindowSurface(pFoundWindow); if (foundSurface) - surfacePos = pFoundWindow->m_vRealPosition; + surfacePos = pFoundWindow->m_vRealPosition.vec(); } else { foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); } @@ -91,7 +91,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); } else { foundSurface = g_pXWaylandManager->getWindowSurface(pFoundWindow); - surfacePos = pFoundWindow->m_vRealPosition; + surfacePos = pFoundWindow->m_vRealPosition.vec(); } } @@ -143,7 +143,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (g_pCompositor->m_pLastWindow == CONSTRAINTWINDOW) { // todo: this is incorrect, but it will work in most cases for now // i made this cuz i wanna play minecraft lol - Vector2D deltaToMiddle = (CONSTRAINTWINDOW->m_vRealPosition + CONSTRAINTWINDOW->m_vRealSize / 2.f) - mouseCoords; + Vector2D deltaToMiddle = (CONSTRAINTWINDOW->m_vRealPosition.vec() + CONSTRAINTWINDOW->m_vRealSize.vec() / 2.f) - mouseCoords; wlr_cursor_move(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, deltaToMiddle.x, deltaToMiddle.y); } } @@ -389,7 +389,7 @@ void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* co if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { if (PWINDOW) { wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, - constraint->current.cursor_hint.x + PWINDOW->m_vRealPosition.x, constraint->current.cursor_hint.y + PWINDOW->m_vRealPosition.y); + constraint->current.cursor_hint.x + PWINDOW->m_vRealPosition.vec().x, constraint->current.cursor_hint.y + PWINDOW->m_vRealPosition.vec().y); wlr_seat_pointer_warp(constraint->seat, constraint->current.cursor_hint.x, constraint->current.cursor_hint.y); } diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 06fdf5f4..500b6b88 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -143,8 +143,8 @@ void CKeybindManager::toggleActiveFloating(std::string args) { if (g_pCompositor->windowValidMapped(ACTIVEWINDOW)) { ACTIVEWINDOW->m_bIsFloating = !ACTIVEWINDOW->m_bIsFloating; - ACTIVEWINDOW->m_vRealPosition = ACTIVEWINDOW->m_vRealPosition + Vector2D(5, 5); - ACTIVEWINDOW->m_vSize = ACTIVEWINDOW->m_vRealPosition - Vector2D(10, 10); + ACTIVEWINDOW->m_vRealPosition.setValue(ACTIVEWINDOW->m_vRealPosition.vec() + Vector2D(5, 5)); + ACTIVEWINDOW->m_vSize = ACTIVEWINDOW->m_vRealPosition.vec() - Vector2D(10, 10); g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(ACTIVEWINDOW); } @@ -311,18 +311,18 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { PWINDOW->m_vPosition = Vector2D(-42069, -42069); // Save the real position and size because the layout might set its own - const auto PSAVEDSIZE = PWINDOW->m_vRealSize; - const auto PSAVEDPOS = PWINDOW->m_vRealPosition; + const auto PSAVEDSIZE = PWINDOW->m_vRealSize.vec(); + const auto PSAVEDPOS = PWINDOW->m_vRealPosition.vec(); g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); // and restore it - PWINDOW->m_vRealPosition = PSAVEDPOS; - PWINDOW->m_vRealSize = PSAVEDSIZE; + PWINDOW->m_vRealPosition.setValue(PSAVEDPOS); + PWINDOW->m_vRealSize.setValue(PSAVEDSIZE); if (PWINDOW->m_bIsFloating) { - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition; - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition; - PWINDOW->m_vEffectivePosition = PWINDOW->m_vRealPosition; - PWINDOW->m_vPosition = PWINDOW->m_vRealPosition; + PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vRealPosition.vec() - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition); + PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vRealPosition.vec() + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition); + PWINDOW->m_vEffectivePosition = PWINDOW->m_vRealPosition.vec(); + PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.vec(); } } diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index fcb72ef5..9efefc75 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -117,7 +117,7 @@ void CHyprXWaylandManager::sendCloseWindow(CWindow* pWindow) { void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, const Vector2D& size) { if (pWindow->m_bIsX11) - wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pWindow->m_vRealPosition.x, pWindow->m_vRealPosition.y, size.x, size.y); + wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pWindow->m_vRealPosition.vec().x, pWindow->m_vRealPosition.vec().y, size.x, size.y); else wlr_xdg_toplevel_set_size(pWindow->m_uSurface.xdg->toplevel, size.x, size.y); } @@ -172,7 +172,7 @@ void CHyprXWaylandManager::moveXWaylandWindow(CWindow* pWindow, const Vector2D& return; if (pWindow->m_bIsX11) { - wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.x, pWindow->m_vRealSize.y); + wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.vec().x, pWindow->m_vRealSize.vec().y); } } -- cgit v1.2.3 From f84294fe07d3442ca62302de491717ef6355e902 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:35:34 +0200 Subject: fixed fullscreen, removed effective vars from windows --- src/managers/KeybindManager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/managers') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 500b6b88..8a503005 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -321,7 +321,6 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { if (PWINDOW->m_bIsFloating) { PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vRealPosition.vec() - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition); PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vRealPosition.vec() + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition); - PWINDOW->m_vEffectivePosition = PWINDOW->m_vRealPosition.vec(); PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.vec(); } } @@ -338,7 +337,7 @@ void CKeybindManager::moveFocusTo(std::string args) { auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) { g_pCompositor->focusWindow(PWINDOWTOCHANGETO); - Vector2D middle = PWINDOWTOCHANGETO->m_vEffectivePosition + PWINDOWTOCHANGETO->m_vEffectiveSize / 2.f; + Vector2D middle = PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f; wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y); }; -- cgit v1.2.3 From 77002eeea0d10661c2b90345bf6c5b9888afcff6 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:36:03 +0200 Subject: fix warn --- src/managers/AnimationManager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/managers') diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index d4a71f37..58613042 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -67,6 +67,9 @@ void CAnimationManager::tick() { } break; } + default: { + ; + } } // invalidate the window -- cgit v1.2.3 From 3ebe7d79722c1bdc333b236960ff136ab607a02c Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:47:16 +0200 Subject: Added bezier curves --- src/managers/AnimationManager.cpp | 116 +++++++++++++++++++++++--------------- src/managers/AnimationManager.hpp | 10 +++- 2 files changed, 80 insertions(+), 46 deletions(-) (limited to 'src/managers') diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 58613042..4d1ab9f8 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -1,6 +1,24 @@ #include "AnimationManager.hpp" #include "../Compositor.hpp" +CAnimationManager::CAnimationManager() { + std::vector points = {Vector2D(0, 0.75f), Vector2D(0.25f, 1.f)}; + m_mBezierCurves["default"].setup(&points); +} + +void CAnimationManager::removeAllBeziers() { + m_mBezierCurves.clear(); + + // add the default one + std::vector points = {Vector2D(0, 0.75f), Vector2D(0.25f, 1.f)}; + m_mBezierCurves["default"].setup(&points); +} + +void CAnimationManager::addBezierWithName(std::string name, const Vector2D& p1, const Vector2D& p2) { + std::vector points = {p1, p2}; + m_mBezierCurves[name].setup(&points); +} + void CAnimationManager::tick() { bool animationsDisabled = false; @@ -9,61 +27,88 @@ void CAnimationManager::tick() { animationsDisabled = true; const float ANIMSPEED = g_pConfigManager->getFloat("animations:speed"); - const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size"); + const auto BEZIERSTR = g_pConfigManager->getString("animations:curve"); - for (auto& av : m_lAnimatedVariables) { - // first, we check if it's disabled, if so, warp - if (av->m_pEnabled == 0 || animationsDisabled) { - av->warp(); - continue; - } + auto DEFAULTBEZIER = m_mBezierCurves.find(BEZIERSTR); + if (DEFAULTBEZIER == m_mBezierCurves.end()) + DEFAULTBEZIER = m_mBezierCurves.find("default"); + for (auto& av : m_lAnimatedVariables) { // get speed const auto SPEED = *av->m_pSpeed == 0 ? ANIMSPEED : *av->m_pSpeed; // window stuff const auto PWINDOW = (CWindow*)av->m_pWindow; - bool needsDamage = false; wlr_box WLRBOXPREV = {PWINDOW->m_vRealPosition.vec().x - BORDERSIZE - 1, PWINDOW->m_vRealPosition.vec().y - BORDERSIZE - 1, PWINDOW->m_vRealSize.vec().x + 2 * BORDERSIZE + 2, PWINDOW->m_vRealSize.vec().y + 2 * BORDERSIZE + 2}; - // TODO: curves + // check if it's disabled, if so, warp + if (av->m_pEnabled == 0 || animationsDisabled) { + av->warp(); + g_pHyprRenderer->damageBox(&WLRBOXPREV); + g_pHyprRenderer->damageWindow(PWINDOW); + continue; + } - // parabolic with a switch unforto + // beziers are with a switch unforto // TODO: maybe do something cleaner + + // get the spent % (0 - 1) + const auto DURATIONPASSED = std::chrono::duration_cast(std::chrono::system_clock::now() - av->animationBegin).count(); + const float SPENT = std::clamp((DURATIONPASSED / 100.f) / SPEED, 0.f, 1.f); + switch (av->m_eVarType) { case AVARTYPE_FLOAT: { if (!deltazero(av->m_fValue, av->m_fGoal)) { - if (deltaSmallToFlip(av->m_fValue, av->m_fGoal)) { + const auto DELTA = av->m_fGoal - av->m_fBegun; + const auto BEZIER = m_mBezierCurves.find(*av->m_pBezier); + + if (BEZIER != m_mBezierCurves.end()) + av->m_fValue = av->m_fBegun + BEZIER->second.getYForPoint(SPENT) * DELTA; + else + av->m_fValue = av->m_fBegun + DEFAULTBEZIER->second.getYForPoint(SPENT) * DELTA; + + if (SPENT >= 1.f) { av->warp(); - } else { - av->m_fValue = parabolic(av->m_fValue, av->m_fGoal, SPEED); } - - needsDamage = true; + } else { + continue; // dont process } break; } case AVARTYPE_VECTOR: { if (!deltazero(av->m_vValue, av->m_vGoal)) { - if (deltaSmallToFlip(av->m_vValue, av->m_vGoal)) { + const auto DELTA = av->m_vGoal - av->m_vBegun; + const auto BEZIER = m_mBezierCurves.find(*av->m_pBezier); + + if (BEZIER != m_mBezierCurves.end()) + av->m_vValue = av->m_vBegun + DELTA * BEZIER->second.getYForPoint(SPENT); + else + av->m_vValue = av->m_vBegun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT); + + if (SPENT >= 1.f) { av->warp(); - } else { - av->m_vValue.x = parabolic(av->m_vValue.x, av->m_vGoal.x, SPEED); - av->m_vValue.y = parabolic(av->m_vValue.y, av->m_vGoal.y, SPEED); } - needsDamage = true; + } else { + continue; // dont process } break; } case AVARTYPE_COLOR: { if (!deltazero(av->m_cValue, av->m_cGoal)) { - if (deltaSmallToFlip(av->m_cValue, av->m_cGoal)) { + const auto DELTA = av->m_cGoal - av->m_cBegun; + const auto BEZIER = m_mBezierCurves.find(*av->m_pBezier); + + if (BEZIER != m_mBezierCurves.end()) + av->m_cValue = av->m_cBegun + DELTA * BEZIER->second.getYForPoint(SPENT); + else + av->m_cValue = av->m_cBegun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT); + + if (SPENT >= 1.f) { av->warp(); - } else { - av->m_cValue = parabolic(SPEED, av->m_cValue, av->m_cGoal); } - needsDamage = true; + } else { + continue; // dont process } break; } @@ -72,11 +117,9 @@ void CAnimationManager::tick() { } } - // invalidate the window - if (needsDamage) { - g_pHyprRenderer->damageBox(&WLRBOXPREV); - g_pHyprRenderer->damageWindow(PWINDOW); - } + // damage the window + g_pHyprRenderer->damageBox(&WLRBOXPREV); + g_pHyprRenderer->damageWindow(PWINDOW); } } @@ -102,19 +145,4 @@ bool CAnimationManager::deltazero(const float& a, const float& b) { bool CAnimationManager::deltazero(const CColor& a, const CColor& b) { return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; -} - -double CAnimationManager::parabolic(const double from, const double to, const double incline) { - return from + ((to - from) / incline); -} - -CColor CAnimationManager::parabolic(const double incline, const CColor& from, const CColor& to) { - CColor newColor; - - newColor.r = parabolic(from.r, to.r, incline); - newColor.g = parabolic(from.g, to.g, incline); - newColor.b = parabolic(from.b, to.b, incline); - newColor.a = parabolic(from.a, to.a, incline); - - return newColor; } \ No newline at end of file diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index 14d6c3ac..ab0d8357 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -2,12 +2,18 @@ #include "../defines.hpp" #include +#include #include "../helpers/AnimatedVariable.hpp" +#include "../helpers/BezierCurve.hpp" class CAnimationManager { public: + CAnimationManager(); + void tick(); + void addBezierWithName(std::string, const Vector2D&, const Vector2D&); + void removeAllBeziers(); std::list m_lAnimatedVariables; @@ -18,8 +24,8 @@ private: bool deltazero(const Vector2D& a, const Vector2D& b); bool deltazero(const CColor& a, const CColor& b); bool deltazero(const float& a, const float& b); - double parabolic(const double, const double, const double); - CColor parabolic(const double, const CColor&, const CColor&); + + std::unordered_map m_mBezierCurves; }; inline std::unique_ptr g_pAnimationManager; \ No newline at end of file -- cgit v1.2.3 From 6d8016185abd9b11ad851967eb9e71092d6c0bf2 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:54:03 +0200 Subject: default curve more close to parabolic --- src/managers/AnimationManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/managers') diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 4d1ab9f8..59f46804 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -2,7 +2,7 @@ #include "../Compositor.hpp" CAnimationManager::CAnimationManager() { - std::vector points = {Vector2D(0, 0.75f), Vector2D(0.25f, 1.f)}; + std::vector points = {Vector2D(0, 0.75f), Vector2D(0.15f, 1.f)}; m_mBezierCurves["default"].setup(&points); } @@ -10,7 +10,7 @@ void CAnimationManager::removeAllBeziers() { m_mBezierCurves.clear(); // add the default one - std::vector points = {Vector2D(0, 0.75f), Vector2D(0.25f, 1.f)}; + std::vector points = {Vector2D(0, 0.75f), Vector2D(0.15f, 1.f)}; m_mBezierCurves["default"].setup(&points); } -- cgit v1.2.3