2021-11-23 18:48:03 +01:00
|
|
|
#include "AnimationUtil.hpp"
|
|
|
|
#include "../windowManager.hpp"
|
|
|
|
|
|
|
|
void AnimationUtil::move() {
|
|
|
|
|
|
|
|
static std::chrono::time_point lastFrame = std::chrono::high_resolution_clock::now();
|
|
|
|
const double DELTA = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - lastFrame).count();
|
|
|
|
|
|
|
|
const double ANIMATIONSPEED = ((double)1 / (double)ConfigManager::getFloat("anim.speed")) * DELTA;
|
|
|
|
|
|
|
|
|
|
|
|
bool updateRequired = false;
|
|
|
|
// Now we are (or should be, lul) thread-safe.
|
|
|
|
for (auto& window : g_pWindowManager->windows) {
|
|
|
|
// check if window needs an animation.
|
2021-12-06 19:43:01 +01:00
|
|
|
window.setIsAnimated(false);
|
2021-11-23 18:48:03 +01:00
|
|
|
|
2021-11-24 18:53:56 +01:00
|
|
|
if (ConfigManager::getInt("anim.enabled") == 0 || window.getIsFloating()) {
|
2021-11-23 18:48:03 +01:00
|
|
|
// Disabled animations. instant warps.
|
|
|
|
|
|
|
|
if (VECTORDELTANONZERO(window.getRealPosition(), window.getEffectivePosition())
|
|
|
|
|| VECTORDELTANONZERO(window.getRealSize(), window.getEffectiveSize())) {
|
|
|
|
window.setDirty(true);
|
|
|
|
updateRequired = true;
|
|
|
|
}
|
|
|
|
|
2021-12-06 19:10:38 +01:00
|
|
|
window.setRealPosition(window.getEffectivePosition());
|
|
|
|
window.setRealSize(window.getEffectiveSize());
|
|
|
|
|
2021-11-23 18:48:03 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VECTORDELTANONZERO(window.getRealPosition(), window.getEffectivePosition())) {
|
|
|
|
Debug::log(LOG, "Updating position animations for " + std::to_string(window.getDrawable()) + " delta: " + std::to_string(ANIMATIONSPEED));
|
2021-12-06 19:43:01 +01:00
|
|
|
window.setIsAnimated(true);
|
2021-11-23 18:48:03 +01:00
|
|
|
|
|
|
|
// we need to update it.
|
|
|
|
window.setDirty(true);
|
|
|
|
updateRequired = true;
|
|
|
|
|
|
|
|
const auto EFFPOS = window.getEffectivePosition();
|
|
|
|
const auto REALPOS = window.getRealPosition();
|
|
|
|
|
|
|
|
window.setRealPosition(Vector2D(parabolic(REALPOS.x, EFFPOS.x, ANIMATIONSPEED), parabolic(REALPOS.y, EFFPOS.y, ANIMATIONSPEED)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VECTORDELTANONZERO(window.getRealSize(), window.getEffectiveSize())) {
|
|
|
|
Debug::log(LOG, "Updating size animations for " + std::to_string(window.getDrawable()) + " delta: " + std::to_string(ANIMATIONSPEED));
|
2021-12-06 19:43:01 +01:00
|
|
|
window.setIsAnimated(true);
|
2021-11-23 18:48:03 +01:00
|
|
|
|
|
|
|
// we need to update it.
|
|
|
|
window.setDirty(true);
|
|
|
|
updateRequired = true;
|
|
|
|
|
|
|
|
const auto REALSIZ = window.getRealSize();
|
|
|
|
const auto EFFSIZ = window.getEffectiveSize();
|
|
|
|
|
|
|
|
window.setRealSize(Vector2D(parabolic(REALSIZ.x, EFFSIZ.x, ANIMATIONSPEED), parabolic(REALSIZ.y, EFFSIZ.y, ANIMATIONSPEED)));
|
|
|
|
}
|
2021-12-06 19:43:01 +01:00
|
|
|
|
|
|
|
// set not animated if already done here
|
|
|
|
if (!VECTORDELTANONZERO(window.getRealPosition(), window.getEffectivePosition())
|
|
|
|
&& !VECTORDELTANONZERO(window.getRealSize(), window.getEffectiveSize())) {
|
|
|
|
window.setIsAnimated(false);
|
|
|
|
}
|
2021-11-23 18:48:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (updateRequired)
|
|
|
|
emptyEvent(); // send a fake request to update dirty windows
|
|
|
|
|
|
|
|
lastFrame = std::chrono::high_resolution_clock::now();
|
|
|
|
}
|