Changeset View
Changeset View
Standalone View
Standalone View
libkwineffects/kwinanimationeffect.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) 2011 Thomas Lübking <thomas.luebking@web.de> | 5 | Copyright (C) 2011 Thomas Lübking <thomas.luebking@web.de> | ||
6 | Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
6 | 7 | | |||
7 | This program is free software; you can redistribute it and/or modify | 8 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | 9 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2 of the License, or | 10 | the Free Software Foundation; either version 2 of the License, or | ||
10 | (at your option) any later version. | 11 | (at your option) any later version. | ||
11 | 12 | | |||
12 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 296 Lines • ▼ Show 20 Line(s) | 303 | if (anim->id == animationId) { | |||
310 | 311 | | |||
311 | return true; | 312 | return true; | ||
312 | } | 313 | } | ||
313 | } | 314 | } | ||
314 | } | 315 | } | ||
315 | return false; // no animation found | 316 | return false; // no animation found | ||
316 | } | 317 | } | ||
317 | 318 | | |||
319 | bool AnimationEffect::redirect(quint64 animationId, Direction direction, TerminationPolicy terminationPolicy) | ||||
320 | { | ||||
321 | Q_D(AnimationEffect); | ||||
322 | | ||||
323 | if (animationId == d->m_justEndedAnimation) { | ||||
324 | return false; | ||||
325 | } | ||||
326 | | ||||
327 | for (auto entryIt = d->m_animations.begin(); entryIt != d->m_animations.end(); ++entryIt) { | ||||
328 | auto animIt = std::find_if(entryIt->first.begin(), entryIt->first.end(), | ||||
329 | [animationId] (AniData &anim) { | ||||
330 | return anim.id == animationId; | ||||
331 | } | ||||
332 | ); | ||||
333 | if (animIt == entryIt->first.end()) { | ||||
334 | continue; | ||||
335 | } | ||||
336 | | ||||
337 | switch (direction) { | ||||
338 | case Direction::Forward: | ||||
339 | animIt->timeLine.setDirection(TimeLine::Forward); | ||||
340 | break; | ||||
341 | | ||||
342 | case Direction::Backward: | ||||
343 | animIt->timeLine.setDirection(TimeLine::Backward); | ||||
344 | break; | ||||
345 | | ||||
346 | default: | ||||
davidedmundson: It's better to not specify a default for a finite list.
This way you get a compile warning if… | |||||
I did this deliberately because one can go either forward or backward, but I don't insist on this one. Should I delete this part of code? zzag: I did this deliberately because one can go either forward or backward, but I don't insist on… | |||||
347 | Q_UNREACHABLE(); | ||||
348 | break; | ||||
349 | } | ||||
350 | | ||||
351 | animIt->terminationPolicy = terminationPolicy; | ||||
352 | | ||||
353 | return true; | ||||
354 | } | ||||
355 | | ||||
356 | return false; | ||||
357 | } | ||||
358 | | ||||
318 | bool AnimationEffect::cancel(quint64 animationId) | 359 | bool AnimationEffect::cancel(quint64 animationId) | ||
319 | { | 360 | { | ||
320 | Q_D(AnimationEffect); | 361 | Q_D(AnimationEffect); | ||
321 | if (animationId == d->m_justEndedAnimation) | 362 | if (animationId == d->m_justEndedAnimation) | ||
322 | return true; // this is just ending, do not try to cancel it but fake success | 363 | return true; // this is just ending, do not try to cancel it but fake success | ||
323 | for (AniMap::iterator entry = d->m_animations.begin(), mapEnd = d->m_animations.end(); entry != mapEnd; ++entry) { | 364 | for (AniMap::iterator entry = d->m_animations.begin(), mapEnd = d->m_animations.end(); entry != mapEnd; ++entry) { | ||
324 | for (QList<AniData>::iterator anim = entry->first.begin(), animEnd = entry->first.end(); anim != animEnd; ++anim) { | 365 | for (QList<AniData>::iterator anim = entry->first.begin(), animEnd = entry->first.end(); anim != animEnd; ++anim) { | ||
325 | if (anim->id == animationId) { | 366 | if (anim->id == animationId) { | ||
Show All 33 Lines | 399 | if (!anim->waitAtSource) { | |||
359 | ++anim; | 400 | ++anim; | ||
360 | ++animCounter; | 401 | ++animCounter; | ||
361 | continue; | 402 | continue; | ||
362 | } | 403 | } | ||
363 | } else { | 404 | } else { | ||
364 | anim->timeLine.update(std::chrono::milliseconds(time)); | 405 | anim->timeLine.update(std::chrono::milliseconds(time)); | ||
365 | } | 406 | } | ||
366 | 407 | | |||
367 | if (!anim->timeLine.done() || anim->keepAtTarget) { | 408 | if (anim->isActive()) { | ||
368 | // if (anim->attribute != Brightness && anim->attribute != Saturation && anim->attribute != Opacity) | 409 | // if (anim->attribute != Brightness && anim->attribute != Saturation && anim->attribute != Opacity) | ||
369 | // transformed = true; | 410 | // transformed = true; | ||
370 | d->m_animated = true; | 411 | d->m_animated = true; | ||
371 | ++anim; | 412 | ++anim; | ||
372 | ++animCounter; | 413 | ++animCounter; | ||
373 | } else { | 414 | } else { | ||
374 | EffectWindow *oldW = entry.key(); | 415 | EffectWindow *oldW = entry.key(); | ||
375 | d->m_justEndedAnimation = anim->id; | 416 | d->m_justEndedAnimation = anim->id; | ||
▲ Show 20 Lines • Show All 613 Lines • Show Last 20 Lines |
It's better to not specify a default for a finite list.
This way you get a compile warning if someone added a 3rd direction.