Changeset View
Changeset View
Standalone View
Standalone View
libkwineffects/kwineffects.cpp
1 | /******************************************************************** | 1 | /******************************************************************** | ||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | 2 | KWin - the KDE window manager | ||
3 | This file is part of the KDE project. | 3 | This file is part of the KDE project. | ||
4 | 4 | | |||
5 | Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org> | 5 | Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org> | ||
6 | Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com> | 6 | Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com> | ||
7 | Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
7 | 8 | | |||
8 | This program is free software; you can redistribute it and/or modify | 9 | This program is free software; you can redistribute it and/or modify | ||
9 | it under the terms of the GNU General Public License as published by | 10 | it under the terms of the GNU General Public License as published by | ||
10 | the Free Software Foundation; either version 2 of the License, or | 11 | the Free Software Foundation; either version 2 of the License, or | ||
11 | (at your option) any later version. | 12 | (at your option) any later version. | ||
12 | 13 | | |||
13 | This program is distributed in the hope that it will be useful, | 14 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 1899 Lines • ▼ Show 20 Line(s) | 1914 | { | |||
1914 | return d->screenProjectionMatrix; | 1915 | return d->screenProjectionMatrix; | ||
1915 | } | 1916 | } | ||
1916 | 1917 | | |||
1917 | void EffectFrame::setScreenProjectionMatrix(const QMatrix4x4 &spm) | 1918 | void EffectFrame::setScreenProjectionMatrix(const QMatrix4x4 &spm) | ||
1918 | { | 1919 | { | ||
1919 | d->screenProjectionMatrix = spm; | 1920 | d->screenProjectionMatrix = spm; | ||
1920 | } | 1921 | } | ||
1921 | 1922 | | |||
1923 | /*************************************************************** | ||||
1924 | TimeLine | ||||
1925 | ***************************************************************/ | ||||
1926 | | ||||
1927 | class Q_DECL_HIDDEN TimeLine::Data : public QSharedData | ||||
1928 | { | ||||
1929 | public: | ||||
1930 | std::chrono::milliseconds duration; | ||||
1931 | Direction direction; | ||||
1932 | QEasingCurve easingCurve; | ||||
1933 | | ||||
1934 | std::chrono::milliseconds elapsed = std::chrono::milliseconds::zero(); | ||||
1935 | bool done = false; | ||||
1936 | }; | ||||
1937 | | ||||
1938 | TimeLine::TimeLine(std::chrono::milliseconds duration, Direction direction) | ||||
1939 | : d(new Data) | ||||
1940 | { | ||||
1941 | Q_ASSERT(duration > std::chrono::milliseconds::zero()); | ||||
1942 | d->duration = duration; | ||||
1943 | d->direction = direction; | ||||
1944 | } | ||||
1945 | | ||||
1946 | TimeLine::TimeLine(const TimeLine &other) | ||||
1947 | : d(other.d) | ||||
1948 | { | ||||
1949 | } | ||||
1950 | | ||||
1951 | TimeLine::~TimeLine() = default; | ||||
graesslin: TimeLine::~TimeLine() = default; | |||||
1952 | | ||||
1953 | qreal TimeLine::progress() const | ||||
1954 | { | ||||
1955 | return static_cast<qreal>(d->elapsed.count()) / d->duration.count(); | ||||
1956 | } | ||||
1957 | | ||||
1958 | qreal TimeLine::value() const | ||||
1959 | { | ||||
1960 | const qreal t = progress(); | ||||
1961 | return d->easingCurve.valueForProgress( | ||||
1962 | d->direction == Backward ? 1.0 - t : t); | ||||
1963 | } | ||||
1964 | | ||||
1965 | void TimeLine::update(std::chrono::milliseconds delta) | ||||
1966 | { | ||||
1967 | Q_ASSERT(delta >= std::chrono::milliseconds::zero()); | ||||
1968 | if (d->done) { | ||||
1969 | return; | ||||
1970 | } | ||||
1971 | d->elapsed += delta; | ||||
1972 | if (d->elapsed >= d->duration) { | ||||
1973 | d->done = true; | ||||
1974 | d->elapsed = d->duration; | ||||
1975 | } | ||||
1976 | } | ||||
1977 | | ||||
1978 | std::chrono::milliseconds TimeLine::elapsed() const | ||||
1979 | { | ||||
1980 | return d->elapsed; | ||||
1981 | } | ||||
1982 | | ||||
1983 | void TimeLine::setElapsed(std::chrono::milliseconds elapsed) | ||||
1984 | { | ||||
1985 | Q_ASSERT(elapsed >= std::chrono::milliseconds::zero()); | ||||
1986 | if (elapsed == d->elapsed) { | ||||
1987 | return; | ||||
1988 | } | ||||
1989 | reset(); | ||||
1990 | update(elapsed); | ||||
1991 | } | ||||
1992 | | ||||
1993 | std::chrono::milliseconds TimeLine::duration() const | ||||
1994 | { | ||||
1995 | return d->duration; | ||||
1996 | } | ||||
1997 | | ||||
1998 | void TimeLine::setDuration(std::chrono::milliseconds duration) | ||||
1999 | { | ||||
2000 | Q_ASSERT(duration > std::chrono::milliseconds::zero()); | ||||
2001 | if (duration == d->duration) { | ||||
2002 | return; | ||||
2003 | } | ||||
2004 | d->elapsed = std::chrono::milliseconds(qRound(progress() * duration.count())); | ||||
2005 | d->duration = duration; | ||||
2006 | if (d->elapsed == d->duration) { | ||||
2007 | d->done = true; | ||||
2008 | } | ||||
2009 | } | ||||
2010 | | ||||
2011 | TimeLine::Direction TimeLine::direction() const | ||||
2012 | { | ||||
2013 | return d->direction; | ||||
2014 | } | ||||
2015 | | ||||
2016 | void TimeLine::setDirection(TimeLine::Direction direction) | ||||
2017 | { | ||||
2018 | if (d->direction == direction) { | ||||
2019 | return; | ||||
2020 | } | ||||
2021 | if (d->elapsed > std::chrono::milliseconds::zero()) { | ||||
2022 | d->elapsed = d->duration - d->elapsed; | ||||
2023 | } | ||||
2024 | d->direction = direction; | ||||
2025 | } | ||||
2026 | | ||||
2027 | void TimeLine::toggleDirection() | ||||
2028 | { | ||||
2029 | setDirection(d->direction == Forward ? Backward : Forward); | ||||
2030 | } | ||||
2031 | | ||||
2032 | QEasingCurve TimeLine::easingCurve() const | ||||
2033 | { | ||||
2034 | return d->easingCurve; | ||||
2035 | } | ||||
2036 | | ||||
2037 | void TimeLine::setEasingCurve(const QEasingCurve &easingCurve) | ||||
2038 | { | ||||
2039 | d->easingCurve = easingCurve; | ||||
2040 | } | ||||
2041 | | ||||
2042 | void TimeLine::setEasingCurve(QEasingCurve::Type type) | ||||
2043 | { | ||||
2044 | d->easingCurve.setType(type); | ||||
2045 | } | ||||
2046 | | ||||
2047 | bool TimeLine::running() const | ||||
2048 | { | ||||
2049 | return d->elapsed != std::chrono::milliseconds::zero() | ||||
2050 | && d->elapsed != d->duration; | ||||
2051 | } | ||||
2052 | | ||||
2053 | bool TimeLine::done() const | ||||
2054 | { | ||||
2055 | return d->done; | ||||
2056 | } | ||||
2057 | | ||||
2058 | void TimeLine::reset() | ||||
2059 | { | ||||
2060 | d->elapsed = std::chrono::milliseconds::zero(); | ||||
2061 | d->done = false; | ||||
2062 | } | ||||
2063 | | ||||
2064 | TimeLine &TimeLine::operator=(const TimeLine &other) | ||||
2065 | { | ||||
2066 | d = other.d; | ||||
2067 | return *this; | ||||
2068 | } | ||||
2069 | | ||||
1922 | } // namespace | 2070 | } // namespace | ||
1923 | 2071 | |
TimeLine::~TimeLine() = default;