forked from MadFishTheOne/qtpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimationutils.h
41 lines (36 loc) · 828 Bytes
/
animationutils.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
35
36
37
38
39
40
41
#ifndef ANIMATIONUTILS_H
#define ANIMATIONUTILS_H
namespace AnimationUtils
{
template<class T>
T animate(T currentPosition, T targetPosition, T step, bool& needAnotherStep)
{
T result = currentPosition;
if(result < targetPosition)
{
result += step;
if(result > targetPosition)
result = targetPosition;
else
needAnotherStep = true;
}
else
{
result -= step;
if(result < targetPosition)
result = targetPosition;
else
needAnotherStep = true;
}
return result;
}
template<class T>
T animateExponentially(T currentPosition, T targetPosition, qreal factor, T minimalStep, bool& needAnotherStep)
{
T step = static_cast<T>(abs(targetPosition - currentPosition)*factor);
if(step < minimalStep)
step = minimalStep;
return animate(currentPosition, targetPosition, step, needAnotherStep);
}
}
#endif