aboutsummaryrefslogtreecommitdiff
path: root/transitionworkerthread.cpp
blob: e002be6ae3abaeab9be5c47a0b1fe448fe7e6ebc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <chrono>
#include <thread>

#include "transitionworkerthread.h"

// The full duration (usecs) of the restoration animation
static const double DURATION = 250000;

// The amount to increase 't' per time step
static const double TICK_SIZE = 1.0 / 60.0;

// The time to wait (usecs) before the next animation tick
static const std::chrono::microseconds TICK_TIME(DURATION * TICK_SIZE);

TransitionWorkerThread::TransitionWorkerThread(TransitionControl *control)
    : m_control(control)
{
}

TransitionWorkerThread::TransitionWorkerThread(TransitionControl *control,
                                               const QEasingCurve &easing)
    : m_control(control)
    , m_easing(easing)
{
}

void TransitionWorkerThread::run()
{
    double t = m_control->t();

    while (t + TICK_SIZE < 1.0) {
        t += TICK_SIZE;
        m_control->setT(m_easing.valueForProgress(t));
        std::this_thread::sleep_for(TICK_TIME);
    }

    m_control->setT(1.0);
}