From c4006f655b58b78ca9430d585e9d7850f13a6caa Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Sun, 9 Aug 2020 10:43:52 +0200 Subject: [PATCH] autoRepeat added --- src/controls/QskAnimator.cpp | 32 +++++++++++++++++++++++++------- src/controls/QskAnimator.h | 12 +++++++++++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/controls/QskAnimator.cpp b/src/controls/QskAnimator.cpp index 61c7eb53..0d663dee 100644 --- a/src/controls/QskAnimator.cpp +++ b/src/controls/QskAnimator.cpp @@ -11,6 +11,8 @@ #include #include +#include + #ifndef QT_NO_DEBUG_STREAM #include #endif @@ -264,6 +266,11 @@ void QskAnimator::setWindow( QQuickWindow* window ) } } +void QskAnimator::setAutoRepeat( bool on ) +{ + m_autoRepeat = on; +} + void QskAnimator::setDuration( int ms ) { m_duration = ms; @@ -298,7 +305,7 @@ const QEasingCurve& QskAnimator::easingCurve() const return m_easingCurve; } -int QskAnimator::elapsed() const +qint64 QskAnimator::elapsed() const { if ( !isRunning() ) return -1; @@ -340,14 +347,25 @@ void QskAnimator::update() const qint64 driverTime = qskAnimatorDriver->referenceTime(); - double progress = ( driverTime - m_startTime ) / double( m_duration ); - if ( progress > 1.0 ) - progress = 1.0; + if ( m_autoRepeat ) + { + double progress = std::fmod(( driverTime - m_startTime ), m_duration ); + progress /= m_duration; - advance( m_easingCurve.valueForProgress( progress ) ); + advance( m_easingCurve.valueForProgress( progress ) ); + } + else + { + double progress = ( driverTime - m_startTime ) / double( m_duration ); - if ( progress >= 1.0 ) - stop(); + if ( progress > 1.0 ) + progress = 1.0; + + advance( m_easingCurve.valueForProgress( progress ) ); + + if ( progress >= 1.0 ) + stop(); + } } void QskAnimator::setup() diff --git a/src/controls/QskAnimator.h b/src/controls/QskAnimator.h index 751ea792..317555a8 100644 --- a/src/controls/QskAnimator.h +++ b/src/controls/QskAnimator.h @@ -29,11 +29,14 @@ class QSK_EXPORT QskAnimator const QEasingCurve& easingCurve() const; + void setAutoRepeat( bool ); + bool autoRepeat() const; + void setDuration( int ms ); int duration() const; bool isRunning() const; - int elapsed() const; + qint64 elapsed() const; void start(); void stop(); @@ -62,6 +65,8 @@ class QSK_EXPORT QskAnimator int m_duration; QEasingCurve m_easingCurve; qint64 m_startTime; // quint32 might be enough + + bool m_autoRepeat = false; }; inline bool QskAnimator::isRunning() const @@ -74,4 +79,9 @@ inline int QskAnimator::duration() const return m_duration; } +inline bool QskAnimator::autoRepeat() const +{ + return m_autoRepeat; +} + #endif