File indexing completed on 2024-11-10 04:56:41

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2011 Thomas Lübking <thomas.luebking@web.de>
0006     SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #include "effect/anidata_p.h"
0012 #include "effect/effecthandler.h"
0013 
0014 namespace KWin
0015 {
0016 
0017 QDebug operator<<(QDebug dbg, const KWin::AniData &a)
0018 {
0019     dbg.nospace() << a.debugInfo();
0020     return dbg.space();
0021 }
0022 
0023 FullScreenEffectLock::FullScreenEffectLock(Effect *effect)
0024 {
0025     effects->setActiveFullScreenEffect(effect);
0026 }
0027 
0028 FullScreenEffectLock::~FullScreenEffectLock()
0029 {
0030     effects->setActiveFullScreenEffect(nullptr);
0031 }
0032 
0033 AniData::AniData()
0034     : attribute(AnimationEffect::Opacity)
0035     , customCurve(0) // Linear
0036     , meta(0)
0037     , frozenTime(-1)
0038     , startTime(0)
0039     , waitAtSource(false)
0040     , keepAlive(true)
0041 {
0042 }
0043 
0044 AniData::AniData(AnimationEffect::Attribute a, int meta_, const FPx2 &to_,
0045                  int delay, const FPx2 &from_, bool waitAtSource_,
0046                  const std::shared_ptr<FullScreenEffectLock> &fullScreenEffectLock, bool keepAlive,
0047                  GLShader *shader)
0048     : attribute(a)
0049     , from(from_)
0050     , to(to_)
0051     , meta(meta_)
0052     , frozenTime(-1)
0053     , startTime(AnimationEffect::clock() + delay)
0054     , fullScreenEffectLock(fullScreenEffectLock)
0055     , waitAtSource(waitAtSource_)
0056     , keepAlive(keepAlive)
0057     , shader(shader)
0058 {
0059 }
0060 
0061 bool AniData::isActive() const
0062 {
0063     if (!timeLine.done()) {
0064         return true;
0065     }
0066 
0067     if (timeLine.direction() == TimeLine::Backward) {
0068         return !(terminationFlags & AnimationEffect::TerminateAtSource);
0069     }
0070 
0071     return !(terminationFlags & AnimationEffect::TerminateAtTarget);
0072 }
0073 
0074 static QString attributeString(KWin::AnimationEffect::Attribute attribute)
0075 {
0076     switch (attribute) {
0077     case KWin::AnimationEffect::Opacity:
0078         return QStringLiteral("Opacity");
0079     case KWin::AnimationEffect::Brightness:
0080         return QStringLiteral("Brightness");
0081     case KWin::AnimationEffect::Saturation:
0082         return QStringLiteral("Saturation");
0083     case KWin::AnimationEffect::Scale:
0084         return QStringLiteral("Scale");
0085     case KWin::AnimationEffect::Translation:
0086         return QStringLiteral("Translation");
0087     case KWin::AnimationEffect::Rotation:
0088         return QStringLiteral("Rotation");
0089     case KWin::AnimationEffect::Position:
0090         return QStringLiteral("Position");
0091     case KWin::AnimationEffect::Size:
0092         return QStringLiteral("Size");
0093     case KWin::AnimationEffect::Clip:
0094         return QStringLiteral("Clip");
0095     default:
0096         return QStringLiteral(" ");
0097     }
0098 }
0099 
0100 QString AniData::debugInfo() const
0101 {
0102     return (QLatin1String("Animation: ") + attributeString(attribute)
0103             + QLatin1String("\n     From: ") + from.toString()
0104             + QLatin1String("\n       To: ") + to.toString()
0105             + QLatin1String("\n  Started: ") + QString::number(AnimationEffect::clock() - startTime) + QLatin1String("ms ago\n")
0106             + QLatin1String(" Duration: ") + QString::number(timeLine.duration().count()) + QLatin1String("ms\n")
0107             + QLatin1String("   Passed: ") + QString::number(timeLine.elapsed().count()) + QLatin1String("ms\n"));
0108 }
0109 
0110 } // namespace KWin