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 | TimeLine::TimeLine(int duration, Direction direction) | ||||
1928 | : m_duration(duration) | ||||
1929 | , m_direction(direction) | ||||
1930 | { | ||||
1931 | Q_ASSERT(m_duration > 0); | ||||
1932 | } | ||||
1933 | | ||||
1934 | qreal TimeLine::progress() const | ||||
1935 | { | ||||
1936 | return static_cast<qreal>(m_elapsed) / m_duration; | ||||
1937 | } | ||||
1938 | | ||||
1939 | qreal TimeLine::value() const | ||||
1940 | { | ||||
1941 | const qreal t = progress(); | ||||
1942 | return m_easingCurve.valueForProgress( | ||||
1943 | m_direction == Backward ? 1.0 - t : t); | ||||
1944 | } | ||||
1945 | | ||||
1946 | void TimeLine::update(int delta) | ||||
1947 | { | ||||
1948 | Q_ASSERT(delta >= 0); | ||||
1949 | if (m_done) { | ||||
1950 | return; | ||||
1951 | } | ||||
graesslin: TimeLine::~TimeLine() = default; | |||||
1952 | m_elapsed += delta; | ||||
1953 | if (m_elapsed >= m_duration) { | ||||
1954 | m_done = true; | ||||
1955 | m_elapsed = m_duration; | ||||
1956 | } | ||||
1957 | } | ||||
1958 | | ||||
1959 | int TimeLine::elapsed() const | ||||
1960 | { | ||||
1961 | return m_elapsed; | ||||
1962 | } | ||||
1963 | | ||||
1964 | void TimeLine::setElapsed(int elapsed) | ||||
1965 | { | ||||
1966 | Q_ASSERT(elapsed >= 0); | ||||
1967 | if (elapsed == m_elapsed) { | ||||
1968 | return; | ||||
1969 | } | ||||
1970 | reset(); | ||||
1971 | update(elapsed); | ||||
1972 | } | ||||
1973 | | ||||
1974 | int TimeLine::duration() const | ||||
1975 | { | ||||
1976 | return m_duration; | ||||
1977 | } | ||||
1978 | | ||||
1979 | void TimeLine::setDuration(int duration) | ||||
1980 | { | ||||
1981 | Q_ASSERT(duration > 0); | ||||
1982 | if (duration == m_duration) { | ||||
1983 | return; | ||||
1984 | } | ||||
1985 | m_elapsed = qRound(progress() * duration); | ||||
1986 | m_duration = duration; | ||||
1987 | if (m_elapsed == m_duration) { | ||||
1988 | m_done = true; | ||||
1989 | } | ||||
1990 | } | ||||
1991 | | ||||
1992 | TimeLine::Direction TimeLine::direction() const | ||||
1993 | { | ||||
1994 | return m_direction; | ||||
1995 | } | ||||
1996 | | ||||
1997 | void TimeLine::setDirection(TimeLine::Direction direction) | ||||
1998 | { | ||||
1999 | if (m_direction == direction) { | ||||
2000 | return; | ||||
2001 | } | ||||
2002 | if (m_elapsed > 0) { | ||||
2003 | m_elapsed = m_duration - m_elapsed; | ||||
2004 | } | ||||
2005 | m_direction = direction; | ||||
2006 | } | ||||
2007 | | ||||
2008 | void TimeLine::toggleDirection() | ||||
2009 | { | ||||
2010 | setDirection(m_direction == Forward ? Backward : Forward); | ||||
2011 | } | ||||
2012 | | ||||
2013 | QEasingCurve TimeLine::easingCurve() const | ||||
2014 | { | ||||
2015 | return m_easingCurve; | ||||
2016 | } | ||||
2017 | | ||||
2018 | void TimeLine::setEasingCurve(const QEasingCurve &easingCurve) | ||||
2019 | { | ||||
2020 | m_easingCurve = easingCurve; | ||||
2021 | } | ||||
2022 | | ||||
2023 | void TimeLine::setEasingCurve(QEasingCurve::Type type) | ||||
2024 | { | ||||
2025 | m_easingCurve.setType(type); | ||||
2026 | } | ||||
2027 | | ||||
2028 | bool TimeLine::running() const | ||||
2029 | { | ||||
2030 | return m_elapsed != 0 && m_elapsed != m_duration; | ||||
2031 | } | ||||
2032 | | ||||
2033 | bool TimeLine::done() const | ||||
2034 | { | ||||
2035 | return m_done; | ||||
2036 | } | ||||
2037 | | ||||
2038 | void TimeLine::reset() | ||||
2039 | { | ||||
2040 | m_elapsed = 0; | ||||
2041 | m_done = false; | ||||
2042 | } | ||||
2043 | | ||||
1922 | } // namespace | 2044 | } // namespace | ||
1923 | 2045 | |
TimeLine::~TimeLine() = default;