Diffusion KWin ee88951b17c8

[libkwineffects] Add TimeLine helper

Authored by zzag on Jun 28 2018, 6:13 PM.

Description

[libkwineffects] Add TimeLine helper

Summary:
Most effects use QTimeLine in the following manner

if (...) {
    m_timeline->setCurrentTime(m_timeline->currentTime() + time);
} else {
    m_timeline->setCurrentTime(m_timeline->currentTime() - time);
}

Because effects do not rely on a timer that QTimeLine has, they can't
toggle direction of the QTimeLine, which makes somewhat harder to write
effects. In some cases that's obvious what condition to use to figure
out whether to add or subtract time, but there are cases when it's
not. In addition to that, setCurrentTime allows to have negative
currentTime, which in some cases causes bugs.

And overall, the way effects use QTimeLine is really hack-ish. It makes
more sense just to use an integer accumulator(like the Fall Apart
effect is doing) than to use QTimeLine.

Another problem with QTimeLine is that it's a QObject and some effects
do

class WindowInfo
{
public:
    ~WindowInfo();

    QTimeLine *timeLine;
};

WindowInfo::~WindowInfo()
{
    delete timeLine;
}

// ...

QHash<EffectWindow*, WindowInfo> m_windows;

which is unsafe.

This change adds the TimeLine class. The TimeLine class is a timeline
helper that designed specifically for needs of effects.

Demo

TimeLine timeLine(1000, TimeLine::Forward);
timeLine.setEasingCurve(QEasingCurve::Linear);

timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // false

timeLine.update(420);
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false

timeLine.toggleDirection();
timeLine.value(); // 0.42
timeLine.running(); // true
timeLine.done(); // false

timeLine.update(100);
timeLine.value(); // 0.32
timeLine.running(); // true
timeLine.done(); // false

timeLine.update(1000);
timeLine.value(); // 0.0
timeLine.running(); // false
timeLine.done(); // true

Test Plan: Ran tests.

Reviewers: KWin, davidedmundson, graesslin

Reviewed By: KWin, davidedmundson, graesslin

Subscribers: romangg, graesslin, anthonyfieroni, davidedmundson, kwin

Tags: KWin

Differential Revision: https://phabricator.kde.org/D13740

Details

Committed
zzagJun 30 2018, 6:58 AM
Reviewer
KWin
Differential Revision
D13740: [libkwineffects] Add TimeLine helper
Parents
R108:27cd0bc5d07d: Remove unneeded QT definitions
Branches
Unknown
Tags
Unknown