mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
- remove common lib - split settings, remove common-md - move ipc interop/kb_layout to interop - rename core -> settings, settings -> old_settings - os-detect header-only; interop -> PowerToysInterop - split notifications, move single-use headers where they're used - winstore lib - rename com utils - rename Updating and Telemetry projects - rename core -> settings-ui and remove examples folder - rename settings-ui folder + consisent common/version include
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#include "pch.h"
|
|
#include "animation.h"
|
|
|
|
Animation::Animation(double duration, double start, double stop) :
|
|
duration(duration), start_value(start), end_value(stop), start(std::chrono::high_resolution_clock::now()) {}
|
|
|
|
void Animation::reset()
|
|
{
|
|
start = std::chrono::high_resolution_clock::now();
|
|
}
|
|
void Animation::reset(double duration)
|
|
{
|
|
this->duration = duration;
|
|
reset();
|
|
}
|
|
void Animation::reset(double duration, double start, double stop)
|
|
{
|
|
start_value = start;
|
|
end_value = stop;
|
|
reset(duration);
|
|
}
|
|
|
|
static double ease_out_expo(double t)
|
|
{
|
|
return 1 - pow(2, -8 * t);
|
|
}
|
|
|
|
double Animation::apply_animation_function(double t, AnimFunctions apply_function)
|
|
{
|
|
switch (apply_function)
|
|
{
|
|
case EASE_OUT_EXPO:
|
|
return ease_out_expo(t);
|
|
case LINEAR:
|
|
default:
|
|
return t;
|
|
}
|
|
}
|
|
|
|
double Animation::value(AnimFunctions apply_function) const
|
|
{
|
|
auto anim_duration = std::chrono::high_resolution_clock::now() - start;
|
|
double t = std::chrono::duration<double>(anim_duration).count() / duration;
|
|
if (t >= 1)
|
|
return end_value;
|
|
return start_value + (end_value - start_value) * apply_animation_function(t, apply_function);
|
|
}
|
|
bool Animation::done() const
|
|
{
|
|
return std::chrono::high_resolution_clock::now() - start >= std::chrono::duration<double>(duration);
|
|
}
|