autoRepeat added

This commit is contained in:
Uwe Rathmann 2020-08-09 10:43:52 +02:00
parent 45f9e7c7f6
commit c4006f655b
2 changed files with 36 additions and 8 deletions

View File

@ -11,6 +11,8 @@
#include <qquickwindow.h> #include <qquickwindow.h>
#include <qvector.h> #include <qvector.h>
#include <cmath>
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
#include <qdebug.h> #include <qdebug.h>
#endif #endif
@ -264,6 +266,11 @@ void QskAnimator::setWindow( QQuickWindow* window )
} }
} }
void QskAnimator::setAutoRepeat( bool on )
{
m_autoRepeat = on;
}
void QskAnimator::setDuration( int ms ) void QskAnimator::setDuration( int ms )
{ {
m_duration = ms; m_duration = ms;
@ -298,7 +305,7 @@ const QEasingCurve& QskAnimator::easingCurve() const
return m_easingCurve; return m_easingCurve;
} }
int QskAnimator::elapsed() const qint64 QskAnimator::elapsed() const
{ {
if ( !isRunning() ) if ( !isRunning() )
return -1; return -1;
@ -340,14 +347,25 @@ void QskAnimator::update()
const qint64 driverTime = qskAnimatorDriver->referenceTime(); const qint64 driverTime = qskAnimatorDriver->referenceTime();
double progress = ( driverTime - m_startTime ) / double( m_duration ); if ( m_autoRepeat )
if ( progress > 1.0 ) {
progress = 1.0; 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 ) if ( progress > 1.0 )
stop(); progress = 1.0;
advance( m_easingCurve.valueForProgress( progress ) );
if ( progress >= 1.0 )
stop();
}
} }
void QskAnimator::setup() void QskAnimator::setup()

View File

@ -29,11 +29,14 @@ class QSK_EXPORT QskAnimator
const QEasingCurve& easingCurve() const; const QEasingCurve& easingCurve() const;
void setAutoRepeat( bool );
bool autoRepeat() const;
void setDuration( int ms ); void setDuration( int ms );
int duration() const; int duration() const;
bool isRunning() const; bool isRunning() const;
int elapsed() const; qint64 elapsed() const;
void start(); void start();
void stop(); void stop();
@ -62,6 +65,8 @@ class QSK_EXPORT QskAnimator
int m_duration; int m_duration;
QEasingCurve m_easingCurve; QEasingCurve m_easingCurve;
qint64 m_startTime; // quint32 might be enough qint64 m_startTime; // quint32 might be enough
bool m_autoRepeat = false;
}; };
inline bool QskAnimator::isRunning() const inline bool QskAnimator::isRunning() const
@ -74,4 +79,9 @@ inline int QskAnimator::duration() const
return m_duration; return m_duration;
} }
inline bool QskAnimator::autoRepeat() const
{
return m_autoRepeat;
}
#endif #endif