From 74dc4e0c620572e6aaf8497f252d987d31652d10 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 2 Apr 2019 13:21:14 +0400 Subject: [PATCH] Allow disabling new animations. --- .../SourceFiles/ui/effects/animations.cpp | 25 +++++++++++-------- Telegram/SourceFiles/ui/effects/animations.h | 5 +++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/ui/effects/animations.cpp b/Telegram/SourceFiles/ui/effects/animations.cpp index ecc9e4c9c..d16340821 100644 --- a/Telegram/SourceFiles/ui/effects/animations.cpp +++ b/Telegram/SourceFiles/ui/effects/animations.cpp @@ -59,12 +59,11 @@ Manager::Manager() { } void Manager::start(not_null animation) { + _forceImmediateUpdate = true; if (_updating) { _starting.emplace_back(animation.get()); } else { - if (empty(_active)) { - updateQueued(); - } + schedule(); _active.emplace_back(animation.get()); } } @@ -93,9 +92,11 @@ void Manager::update() { return; } const auto now = crl::now(); - if (_lastUpdateTime + kIgnoreUpdatesTimeout >= now) { + if (!_forceImmediateUpdate + && (_lastUpdateTime + kIgnoreUpdatesTimeout >= now)) { return; } + _forceImmediateUpdate = false; schedule(); _updating = true; @@ -129,13 +130,17 @@ void Manager::schedule() { _scheduled = true; Ui::PostponeCall([=] { _scheduled = false; - - const auto next = _lastUpdateTime + kAnimationTimeout; - const auto now = crl::now(); - if (now < next) { - _timerId = startTimer(next - now, Qt::PreciseTimer); - } else { + if (_forceImmediateUpdate) { + _forceImmediateUpdate = false; updateQueued(); + } else { + const auto next = _lastUpdateTime + kAnimationTimeout; + const auto now = crl::now(); + if (now < next) { + _timerId = startTimer(next - now, Qt::PreciseTimer); + } else { + updateQueued(); + } } }); } diff --git a/Telegram/SourceFiles/ui/effects/animations.h b/Telegram/SourceFiles/ui/effects/animations.h index 5fdcb0bb9..2ca6562e8 100644 --- a/Telegram/SourceFiles/ui/effects/animations.h +++ b/Telegram/SourceFiles/ui/effects/animations.h @@ -161,6 +161,7 @@ private: int _timerId = 0; bool _updating = false; bool _scheduled = false; + bool _forceImmediateUpdate = false; std::vector _active; std::vector _starting; rpl::lifetime _lifetime; @@ -274,7 +275,9 @@ inline void Simple::start( that = _data.get(), callback = Prepare(std::forward(callback)) ](crl::time now) { - const auto time = (now - that->animation.started()); + const auto time = anim::Disabled() + ? that->duration + : (now - that->animation.started()); const auto finished = (time >= that->duration); const auto progress = finished ? that->delta