From 417f5684dc4f31995b2b35e07c8c9dd9051b0a62 Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Thu, 3 Aug 2017 16:10:55 +0200
Subject: [PATCH] Add ability to disable animations.

---
 Telegram/SourceFiles/ui/animation.cpp | 9 +++++++++
 Telegram/SourceFiles/ui/animation.h   | 5 ++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Telegram/SourceFiles/ui/animation.cpp b/Telegram/SourceFiles/ui/animation.cpp
index 54cbb453a..ea1e64194 100644
--- a/Telegram/SourceFiles/ui/animation.cpp
+++ b/Telegram/SourceFiles/ui/animation.cpp
@@ -40,6 +40,7 @@ ReaderPointer::~ReaderPointer() {
 namespace {
 
 AnimationManager *_manager = nullptr;
+bool AnimationsDisabled = false;
 
 } // namespace
 
@@ -109,6 +110,14 @@ void registerClipManager(Media::Clip::Manager *manager) {
 	manager->connect(manager, SIGNAL(callback(Media::Clip::Reader*,qint32,qint32)), _manager, SLOT(clipCallback(Media::Clip::Reader*,qint32,qint32)));
 }
 
+bool Disabled() {
+	return AnimationsDisabled;
+}
+
+void SetDisabled(bool disabled) {
+	AnimationsDisabled = disabled;
+}
+
 } // anim
 
 void BasicAnimation::start() {
diff --git a/Telegram/SourceFiles/ui/animation.h b/Telegram/SourceFiles/ui/animation.h
index 0893ac164..e6ebe4a12 100644
--- a/Telegram/SourceFiles/ui/animation.h
+++ b/Telegram/SourceFiles/ui/animation.h
@@ -417,6 +417,9 @@ QPainterPath path(QPointF (&from)[N]) {
 	return result;
 }
 
+bool Disabled();
+void SetDisabled(bool disabled);
+
 };
 
 class BasicAnimation;
@@ -668,7 +671,7 @@ private:
 			, updateCallback(std::move(updateCallback)) {
 		}
 		void step(float64 ms, bool timer) {
-			auto dt = (ms >= duration) ? 1. : (ms / duration);
+			auto dt = (ms >= duration || anim::Disabled()) ? 1. : (ms / duration);
 			if (dt >= 1) {
 				value.finish();
 				a_animation.stop();