autoRepeat added
This commit is contained in:
parent
45f9e7c7f6
commit
c4006f655b
@ -11,6 +11,8 @@
|
||||
#include <qquickwindow.h>
|
||||
#include <qvector.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
#include <qdebug.h>
|
||||
#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()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user