2016-05-12 16:05:20 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-05-12 16:05:20 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-05-12 16:05:20 +00:00
|
|
|
*/
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "window/window_slide_animation.h"
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "styles/style_window.h"
|
2017-10-03 17:41:44 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
namespace Window {
|
2016-05-12 16:05:20 +00:00
|
|
|
|
2022-02-23 10:53:27 +00:00
|
|
|
void SlideAnimation::paintContents(Painter &p) const {
|
|
|
|
const auto retina = style::DevicePixelRatio();
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2022-05-19 07:33:13 +00:00
|
|
|
const auto slideLeft = (_direction == SlideDirection::FromLeft);
|
|
|
|
const auto progress = _animation.value(slideLeft ? 0. : 1.);
|
2017-10-03 17:41:44 +00:00
|
|
|
if (_withFade) {
|
2022-05-19 07:33:13 +00:00
|
|
|
const auto dt = slideLeft
|
2017-10-03 17:41:44 +00:00
|
|
|
? (1. - progress)
|
|
|
|
: progress;
|
2022-05-19 07:33:13 +00:00
|
|
|
const auto easeOut = anim::easeOutCirc(1., dt);
|
|
|
|
const auto easeIn = anim::easeInCirc(1., dt);
|
|
|
|
const auto arrivingAlpha = easeIn;
|
|
|
|
const auto departingAlpha = 1. - easeOut;
|
|
|
|
const auto leftWidthFull = _cacheUnder.width() / retina;
|
|
|
|
const auto rightWidthFull = _cacheOver.width() / retina;
|
|
|
|
const auto leftCoord = slideLeft
|
|
|
|
? anim::interpolate(-leftWidthFull, 0, easeOut)
|
|
|
|
: anim::interpolate(0, -leftWidthFull, easeIn);
|
|
|
|
const auto leftAlpha = (slideLeft ? arrivingAlpha : departingAlpha);
|
|
|
|
const auto rightCoord = slideLeft
|
|
|
|
? anim::interpolate(0, rightWidthFull, easeIn)
|
|
|
|
: anim::interpolate(rightWidthFull, 0, easeOut);
|
|
|
|
const auto rightAlpha = (slideLeft ? departingAlpha : arrivingAlpha);
|
|
|
|
|
|
|
|
const auto leftWidth = (leftWidthFull + leftCoord);
|
|
|
|
const auto rightWidth = rightWidthFull - rightCoord;
|
|
|
|
|
2017-10-03 17:41:44 +00:00
|
|
|
if (leftWidth > 0) {
|
|
|
|
p.setOpacity(leftAlpha);
|
2022-05-19 07:33:13 +00:00
|
|
|
p.drawPixmap(
|
|
|
|
0,
|
|
|
|
_topSkip,
|
|
|
|
_cacheUnder,
|
|
|
|
(_cacheUnder.width() - leftWidth * retina),
|
|
|
|
_topSkip * retina,
|
|
|
|
leftWidth * retina,
|
|
|
|
_cacheUnder.height() - _topSkip * retina);
|
2017-10-03 17:41:44 +00:00
|
|
|
}
|
|
|
|
if (rightWidth > 0) {
|
|
|
|
p.setOpacity(rightAlpha);
|
2022-05-19 07:33:13 +00:00
|
|
|
p.drawPixmap(
|
|
|
|
rightCoord,
|
|
|
|
_topSkip,
|
|
|
|
_cacheOver,
|
|
|
|
0,
|
|
|
|
_topSkip * retina,
|
|
|
|
rightWidth * retina,
|
|
|
|
_cacheOver.height() - _topSkip * retina);
|
2017-10-03 17:41:44 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-05-19 07:33:13 +00:00
|
|
|
const auto coordUnder = anim::interpolate(
|
|
|
|
0,
|
|
|
|
-st::slideShift,
|
|
|
|
progress);
|
|
|
|
const auto coordOver = anim::interpolate(
|
|
|
|
_cacheOver.width() / retina,
|
|
|
|
0,
|
|
|
|
progress);
|
2017-10-03 17:41:44 +00:00
|
|
|
if (coordOver) {
|
2022-05-19 07:33:13 +00:00
|
|
|
p.drawPixmap(
|
|
|
|
QRect(0, 0, coordOver, _cacheUnder.height() / retina),
|
|
|
|
_cacheUnder,
|
|
|
|
QRect(
|
|
|
|
-coordUnder * retina,
|
|
|
|
0,
|
|
|
|
coordOver * retina,
|
|
|
|
_cacheUnder.height()));
|
2017-10-03 17:41:44 +00:00
|
|
|
p.setOpacity(progress);
|
2022-05-19 07:33:13 +00:00
|
|
|
p.fillRect(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
coordOver, _cacheUnder.height() / retina,
|
|
|
|
st::slideFadeOutBg);
|
2017-10-03 17:41:44 +00:00
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
2022-05-19 07:33:13 +00:00
|
|
|
p.drawPixmap(
|
|
|
|
QRect(QPoint(coordOver, 0), _cacheOver.size() / retina),
|
|
|
|
_cacheOver,
|
|
|
|
QRect(QPoint(), _cacheOver.size()));
|
2016-11-11 08:59:55 +00:00
|
|
|
p.setOpacity(progress);
|
2022-05-19 07:33:13 +00:00
|
|
|
st::slideShadow.fill(
|
|
|
|
p,
|
|
|
|
QRect(
|
|
|
|
coordOver - st::slideShadow.width(),
|
|
|
|
0,
|
|
|
|
st::slideShadow.width(),
|
|
|
|
_cacheOver.height() / retina));
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlideAnimation::setDirection(SlideDirection direction) {
|
|
|
|
_direction = direction;
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:33:13 +00:00
|
|
|
void SlideAnimation::setPixmaps(
|
|
|
|
const QPixmap &oldContentCache,
|
|
|
|
const QPixmap &newContentCache) {
|
2016-05-12 16:05:20 +00:00
|
|
|
_cacheUnder = oldContentCache;
|
|
|
|
_cacheOver = newContentCache;
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
void SlideAnimation::setTopBarShadow(bool enabled) {
|
|
|
|
_topBarShadowEnabled = enabled;
|
|
|
|
}
|
|
|
|
|
2022-02-23 10:53:27 +00:00
|
|
|
void SlideAnimation::setTopSkip(int skip) {
|
|
|
|
_topSkip = skip;
|
|
|
|
}
|
|
|
|
|
2017-10-03 17:41:44 +00:00
|
|
|
void SlideAnimation::setWithFade(bool withFade) {
|
|
|
|
_withFade = withFade;
|
|
|
|
}
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
void SlideAnimation::setRepaintCallback(RepaintCallback &&callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_repaintCallback = std::move(callback);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SlideAnimation::setFinishedCallback(FinishedCallback &&callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_finishedCallback = std::move(callback);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SlideAnimation::start() {
|
2022-05-19 07:33:13 +00:00
|
|
|
const auto fromLeft = (_direction == SlideDirection::FromLeft);
|
|
|
|
if (fromLeft) {
|
|
|
|
std::swap(_cacheUnder, _cacheOver);
|
|
|
|
}
|
2017-10-03 14:57:11 +00:00
|
|
|
_animation.start(
|
|
|
|
[this] { animationCallback(); },
|
|
|
|
fromLeft ? 1. : 0.,
|
|
|
|
fromLeft ? 0. : 1.,
|
|
|
|
st::slideDuration,
|
|
|
|
transition());
|
2016-11-11 08:59:55 +00:00
|
|
|
_repaintCallback();
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 08:59:55 +00:00
|
|
|
void SlideAnimation::animationCallback() {
|
|
|
|
_repaintCallback();
|
|
|
|
if (!_animation.animating()) {
|
|
|
|
if (_finishedCallback) {
|
|
|
|
_finishedCallback();
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-19 12:03:51 +00:00
|
|
|
|
|
|
|
} // namespace Window
|