From fcb2950ce82b5027a60223b59ed9a3893004bf9d Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 24 Sep 2019 09:53:35 +0300 Subject: [PATCH] Use slide animation from lib_ui. --- .../ui/effects/slide_animation.cpp | 53 ------------------ .../SourceFiles/ui/effects/slide_animation.h | 55 ------------------- Telegram/gyp/telegram/sources.txt | 2 - Telegram/lib_ui | 2 +- 4 files changed, 1 insertion(+), 111 deletions(-) delete mode 100644 Telegram/SourceFiles/ui/effects/slide_animation.cpp delete mode 100644 Telegram/SourceFiles/ui/effects/slide_animation.h diff --git a/Telegram/SourceFiles/ui/effects/slide_animation.cpp b/Telegram/SourceFiles/ui/effects/slide_animation.cpp deleted file mode 100644 index 1dd099d75f..0000000000 --- a/Telegram/SourceFiles/ui/effects/slide_animation.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "ui/effects/slide_animation.h" - -namespace Ui { - -void SlideAnimation::setSnapshots(QPixmap leftSnapshot, QPixmap rightSnapshot) { - _leftSnapshot = std::move(leftSnapshot); - _rightSnapshot = std::move(rightSnapshot); - Assert(!_leftSnapshot.isNull()); - Assert(!_rightSnapshot.isNull()); - _leftSnapshot.setDevicePixelRatio(cRetinaFactor()); - _rightSnapshot.setDevicePixelRatio(cRetinaFactor()); -} - -void SlideAnimation::paintFrame(Painter &p, int x, int y, int outerWidth) { - auto dt = _animation.value(1.); - if (!animating()) return; - - auto easeOut = anim::easeOutCirc(1., dt); - auto easeIn = anim::easeInCirc(1., dt); - auto arrivingAlpha = easeIn; - auto departingAlpha = 1. - easeOut; - auto leftCoord = (_slideLeft ? anim::interpolate(-_leftSnapshotWidth, 0, easeOut) : anim::interpolate(0, -_leftSnapshotWidth, easeIn)); - auto leftAlpha = (_slideLeft ? arrivingAlpha : departingAlpha); - auto rightCoord = (_slideLeft ? anim::interpolate(0, _rightSnapshotWidth, easeIn) : anim::interpolate(_rightSnapshotWidth, 0, easeOut)); - auto rightAlpha = (_slideLeft ? departingAlpha : arrivingAlpha); - - if (_overflowHidden) { - auto leftWidth = (_leftSnapshotWidth + leftCoord); - if (leftWidth > 0) { - p.setOpacity(leftAlpha); - p.drawPixmap(x, y, leftWidth, _leftSnapshotHeight, _leftSnapshot, (_leftSnapshot.width() - leftWidth * cIntRetinaFactor()), 0, leftWidth * cIntRetinaFactor(), _leftSnapshot.height()); - } - auto rightWidth = _rightSnapshotWidth - rightCoord; - if (rightWidth > 0) { - p.setOpacity(rightAlpha); - p.drawPixmap(x + rightCoord, y, _rightSnapshot, 0, 0, rightWidth * cIntRetinaFactor(), _rightSnapshot.height()); - } - } else { - p.setOpacity(leftAlpha); - p.drawPixmap(x + leftCoord, y, _leftSnapshot); - p.setOpacity(rightAlpha); - p.drawPixmap(x + rightCoord, y, _rightSnapshot); - } -} - -} // namespace Ui diff --git a/Telegram/SourceFiles/ui/effects/slide_animation.h b/Telegram/SourceFiles/ui/effects/slide_animation.h deleted file mode 100644 index 055434fcaf..0000000000 --- a/Telegram/SourceFiles/ui/effects/slide_animation.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -#include "ui/effects/animations.h" - -namespace Ui { - -class SlideAnimation { -public: - void setSnapshots(QPixmap leftSnapshot, QPixmap rightSnapshot); - - void setOverflowHidden(bool hidden) { - _overflowHidden = hidden; - } - - template - void start(bool slideLeft, Lambda &&updateCallback, float64 duration); - - void paintFrame(Painter &p, int x, int y, int outerWidth); - - bool animating() const { - return _animation.animating(); - } - -private: - Ui::Animations::Simple _animation; - QPixmap _leftSnapshot; - QPixmap _rightSnapshot; - bool _slideLeft = false; - bool _overflowHidden = true; - int _leftSnapshotWidth = 0; - int _leftSnapshotHeight = 0; - int _rightSnapshotWidth = 0; - -}; - -template -void SlideAnimation::start(bool slideLeft, Lambda &&updateCallback, float64 duration) { - _slideLeft = slideLeft; - if (_slideLeft) { - std::swap(_leftSnapshot, _rightSnapshot); - } - _leftSnapshotWidth = _leftSnapshot.width() / cIntRetinaFactor(); - _leftSnapshotHeight = _leftSnapshot.height() / cIntRetinaFactor(); - _rightSnapshotWidth = _rightSnapshot.width() / cIntRetinaFactor(); - _animation.start(std::forward(updateCallback), 0., 1., duration); -} - -} // namespace Ui diff --git a/Telegram/gyp/telegram/sources.txt b/Telegram/gyp/telegram/sources.txt index e8017f382a..79e7a42b1f 100644 --- a/Telegram/gyp/telegram/sources.txt +++ b/Telegram/gyp/telegram/sources.txt @@ -728,8 +728,6 @@ <(src_loc)/ui/effects/round_checkbox.h <(src_loc)/ui/effects/send_action_animations.cpp <(src_loc)/ui/effects/send_action_animations.h -<(src_loc)/ui/effects/slide_animation.cpp -<(src_loc)/ui/effects/slide_animation.h <(src_loc)/ui/image/image.cpp <(src_loc)/ui/image/image.h <(src_loc)/ui/image/image_location.cpp diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 00393b7b3b..f7c3e22cc9 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 00393b7b3ba113a216d3704d47e0ca1cb97d0e6e +Subproject commit f7c3e22cc9d51e4bce0fe82e9eaa10cedc7bf5d5