Make it possible for animation driver to specify the advance time delta
This commit is contained in:
parent
774527dd1e
commit
539602d43a
@ -201,16 +201,17 @@ void QUnifiedTimer::ensureTimerUpdate()
|
|||||||
{
|
{
|
||||||
QUnifiedTimer *inst = QUnifiedTimer::instance(false);
|
QUnifiedTimer *inst = QUnifiedTimer::instance(false);
|
||||||
if (inst && inst->isPauseTimerActive)
|
if (inst && inst->isPauseTimerActive)
|
||||||
inst->updateAnimationsTime();
|
inst->updateAnimationsTime(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QUnifiedTimer::updateAnimationsTime()
|
void QUnifiedTimer::updateAnimationsTime(qint64 timeStep)
|
||||||
{
|
{
|
||||||
//setCurrentTime can get this called again while we're the for loop. At least with pauseAnimations
|
//setCurrentTime can get this called again while we're the for loop. At least with pauseAnimations
|
||||||
if(insideTick)
|
if(insideTick)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qint64 totalElapsed = time.elapsed();
|
qint64 totalElapsed = timeStep >= 0 ? timeStep : time.elapsed();
|
||||||
|
|
||||||
// ignore consistentTiming in case the pause timer is active
|
// ignore consistentTiming in case the pause timer is active
|
||||||
int delta = (consistentTiming && !isPauseTimerActive) ?
|
int delta = (consistentTiming && !isPauseTimerActive) ?
|
||||||
timingInterval : totalElapsed - lastTick;
|
timingInterval : totalElapsed - lastTick;
|
||||||
@ -303,7 +304,7 @@ void QUnifiedTimer::timerEvent(QTimerEvent *event)
|
|||||||
|
|
||||||
if (event->timerId() == animationTimer.timerId()) {
|
if (event->timerId() == animationTimer.timerId()) {
|
||||||
// update current time on all top level animations
|
// update current time on all top level animations
|
||||||
updateAnimationsTime();
|
updateAnimationsTime(-1);
|
||||||
restartAnimationTimer();
|
restartAnimationTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,37 +463,56 @@ QAnimationDriver::~QAnimationDriver()
|
|||||||
uninstall();
|
uninstall();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
Advances the animation based on the current time. This function should
|
|
||||||
be continuously called by the driver while the animation is running.
|
|
||||||
|
|
||||||
\internal
|
|
||||||
|
/*!
|
||||||
|
Advances the animation based to the specified \a timeStep. This function should
|
||||||
|
be continuously called by the driver subclasses while the animation is running.
|
||||||
|
|
||||||
|
If \a timeStep is positive, it will be used as the current time in the
|
||||||
|
calculations; otherwise, the current clock time will be used.
|
||||||
*/
|
*/
|
||||||
void QAnimationDriver::advance()
|
|
||||||
|
void QAnimationDriver::advanceAnimation(qint64 timeStep)
|
||||||
{
|
{
|
||||||
QUnifiedTimer *instance = QUnifiedTimer::instance();
|
QUnifiedTimer *instance = QUnifiedTimer::instance();
|
||||||
|
|
||||||
// update current time on all top level animations
|
// update current time on all top level animations
|
||||||
instance->updateAnimationsTime();
|
instance->updateAnimationsTime(timeStep);
|
||||||
instance->restartAnimationTimer();
|
instance->restartAnimationTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Advances the animation. This function should be continously called
|
||||||
|
by the driver while the animation is running.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void QAnimationDriver::advance()
|
||||||
|
{
|
||||||
|
advanceAnimation(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Installs this animation driver. The animation driver is thread local and
|
Installs this animation driver. The animation driver is thread local and
|
||||||
will only apply for the thread its installed in.
|
will only apply for the thread its installed in.
|
||||||
|
|
||||||
\internal
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void QAnimationDriver::install()
|
void QAnimationDriver::install()
|
||||||
{
|
{
|
||||||
QUnifiedTimer *timer = QUnifiedTimer::instance(true);
|
QUnifiedTimer *timer = QUnifiedTimer::instance(true);
|
||||||
timer->installAnimationDriver(this);
|
timer->installAnimationDriver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Uninstalls this animation driver.
|
Uninstalls this animation driver.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void QAnimationDriver::uninstall()
|
void QAnimationDriver::uninstall()
|
||||||
{
|
{
|
||||||
QUnifiedTimer *timer = QUnifiedTimer::instance(true);
|
QUnifiedTimer *timer = QUnifiedTimer::instance(true);
|
||||||
@ -509,7 +529,7 @@ void QAnimationDriver::start()
|
|||||||
{
|
{
|
||||||
Q_D(QAnimationDriver);
|
Q_D(QAnimationDriver);
|
||||||
if (!d->running) {
|
if (!d->running) {
|
||||||
started();
|
emit started();
|
||||||
d->running = true;
|
d->running = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -519,16 +539,28 @@ void QAnimationDriver::stop()
|
|||||||
{
|
{
|
||||||
Q_D(QAnimationDriver);
|
Q_D(QAnimationDriver);
|
||||||
if (d->running) {
|
if (d->running) {
|
||||||
stopped();
|
emit stopped();
|
||||||
d->running = false;
|
d->running = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn qint64 QAnimationDriver::elapsed() const
|
||||||
|
|
||||||
|
Returns the number of milliseconds since the animations was started.
|
||||||
|
*/
|
||||||
|
|
||||||
|
qint64 QAnimationDriver::elapsed() const
|
||||||
|
{
|
||||||
|
return QUnifiedTimer::instance()->time.elapsed();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn QAnimationDriver::started()
|
\fn QAnimationDriver::started()
|
||||||
|
|
||||||
This function is called by the animation framework to notify the driver
|
This signal is emitted by the animation framework to notify the driver
|
||||||
that it should start running.
|
that continous animation has started.
|
||||||
|
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
@ -536,8 +568,8 @@ void QAnimationDriver::stop()
|
|||||||
/*!
|
/*!
|
||||||
\fn QAnimationDriver::stopped()
|
\fn QAnimationDriver::stopped()
|
||||||
|
|
||||||
This function is called by the animation framework to notify the driver
|
This signal is emitted by the animation framework to notify the driver
|
||||||
that it should stop running.
|
that continous animation has stopped.
|
||||||
|
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
|
@ -143,24 +143,29 @@ public:
|
|||||||
QAnimationDriver(QObject *parent = 0);
|
QAnimationDriver(QObject *parent = 0);
|
||||||
~QAnimationDriver();
|
~QAnimationDriver();
|
||||||
|
|
||||||
void advance();
|
virtual void advance();
|
||||||
|
|
||||||
void install();
|
void install();
|
||||||
void uninstall();
|
void uninstall();
|
||||||
|
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
|
|
||||||
|
qint64 elapsed() const;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void started();
|
||||||
|
void stopped();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void started() {};
|
void advanceAnimation(qint64 timeStep = -1);
|
||||||
virtual void stopped() {};
|
virtual void start();
|
||||||
|
virtual void stop();
|
||||||
|
|
||||||
QAnimationDriver(QAnimationDriverPrivate &dd, QObject *parent = 0);
|
QAnimationDriver(QAnimationDriverPrivate &dd, QObject *parent = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class QUnifiedTimer;
|
friend class QUnifiedTimer;
|
||||||
|
|
||||||
void start();
|
|
||||||
void stop();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ public:
|
|||||||
bool canUninstallAnimationDriver(QAnimationDriver *driver);
|
bool canUninstallAnimationDriver(QAnimationDriver *driver);
|
||||||
|
|
||||||
void restartAnimationTimer();
|
void restartAnimationTimer();
|
||||||
void updateAnimationsTime();
|
void updateAnimationsTime(qint64 timeStep);
|
||||||
|
|
||||||
//useful for profiling/debugging
|
//useful for profiling/debugging
|
||||||
int runningAnimationCount() { return animations.count(); }
|
int runningAnimationCount() { return animations.count(); }
|
||||||
@ -194,6 +194,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend class QDefaultAnimationDriver;
|
friend class QDefaultAnimationDriver;
|
||||||
|
friend class QAnimationDriver;
|
||||||
|
|
||||||
QAnimationDriver *driver;
|
QAnimationDriver *driver;
|
||||||
QDefaultAnimationDriver defaultDriver;
|
QDefaultAnimationDriver defaultDriver;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user