forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.h
34 lines (29 loc) · 865 Bytes
/
animation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once
#include <chrono>
/*
Usage:
When creating animation constructor takes one parameter - how long
should the animation take in seconds.
Call reset() when starting animation.
When rendering, call value() to get value from 0 to 1 - depending on animation
progress.
*/
class Animation
{
public:
enum AnimFunctions
{
LINEAR = 0,
EASE_OUT_EXPO
};
Animation(double duration = 1, double start = 0, double stop = 1);
void reset();
void reset(double duration);
void reset(double duration, double start, double stop);
double value(AnimFunctions apply_function) const;
bool done() const;
private:
static double apply_animation_function(double t, AnimFunctions apply_function);
std::chrono::high_resolution_clock::time_point start;
double start_value, end_value, duration;
};