summaryrefslogtreecommitdiffstats
path: root/src/animation
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@qt.io>2017-11-15 11:32:28 +0100
committerChristian Stromme <christian.stromme@qt.io>2018-01-23 10:34:58 +0000
commita73937ac90169d77f2797633738fee27f71ad35a (patch)
tree4fee7341a8d23f5a14377a1967747751221f3935 /src/animation
parentd6d1a9367f7a1e7b4dbe5c0400ae2148ed30fc6d (diff)
Add convenience functions to convert between seconds and NSs
Makes it easier to read and to re-use. Change-Id: I74be7a623d0c2495ff2f6a42ac495ab469bb4d60 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/animation')
-rw-r--r--src/animation/backend/animationutils_p.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/animation/backend/animationutils_p.h b/src/animation/backend/animationutils_p.h
index a0ab218d4..94038eecc 100644
--- a/src/animation/backend/animationutils_p.h
+++ b/src/animation/backend/animationutils_p.h
@@ -56,6 +56,7 @@
#include <QtCore/qbitarray.h>
#include <QtCore/qdebug.h>
+#include <qmath.h>
QT_BEGIN_NAMESPACE
@@ -243,6 +244,9 @@ struct AnimationCallbackAndValue
QVariant value;
};
+inline constexpr double toSecs(qint64 nsecs) { return nsecs / 1.0e9; }
+inline qint64 toNsecs(double seconds) { return qRound64(seconds * 1.0e9); }
+
template<typename Animator>
AnimatorEvaluationData evaluationDataForAnimator(Animator animator, Clock* clock, qint64 nsSincePreviousFrame)
{
@@ -251,7 +255,7 @@ AnimatorEvaluationData evaluationDataForAnimator(Animator animator, Clock* clock
data.currentLoop = animator->currentLoop();
data.playbackRate = clock != nullptr ? clock->playbackRate() : 1.0;
// Convert global time from nsec to sec
- data.elapsedTime = double(nsSincePreviousFrame) / 1.0e9;
+ data.elapsedTime = toSecs(nsSincePreviousFrame);
data.currentTime = animator->lastLocalTime();
return data;
}