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
|
|
|
|
|
|
|
void SlideAnimation::paintContents(Painter &p, const QRect &update) const {
|
2016-05-19 12:03:51 +00:00
|
|
|
int retina = cIntRetinaFactor();
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
auto progress = _animation.value((_direction == SlideDirection::FromLeft) ? 0. : 1.);
|
2017-10-03 17:41:44 +00:00
|
|
|
if (_withFade) {
|
|
|
|
p.fillRect(update, st::boxBg);
|
|
|
|
|
|
|
|
auto slideLeft = (_direction == SlideDirection::FromLeft);
|
|
|
|
auto dt = slideLeft
|
|
|
|
? (1. - progress)
|
|
|
|
: progress;
|
|
|
|
auto easeOut = anim::easeOutCirc(1., dt);
|
|
|
|
auto easeIn = anim::easeInCirc(1., dt);
|
|
|
|
auto arrivingAlpha = easeIn;
|
|
|
|
auto departingAlpha = 1. - easeOut;
|
|
|
|
auto leftWidthFull = _cacheUnder.width() / cIntRetinaFactor();
|
|
|
|
auto rightWidthFull = _cacheOver.width() / cIntRetinaFactor();
|
|
|
|
auto leftCoord = (slideLeft ? anim::interpolate(-leftWidthFull, 0, easeOut) : anim::interpolate(0, -leftWidthFull, easeIn));
|
|
|
|
auto leftAlpha = (slideLeft ? arrivingAlpha : departingAlpha);
|
|
|
|
auto rightCoord = (slideLeft ? anim::interpolate(0, rightWidthFull, easeIn) : anim::interpolate(rightWidthFull, 0, easeOut));
|
|
|
|
auto rightAlpha = (slideLeft ? departingAlpha : arrivingAlpha);
|
|
|
|
|
|
|
|
auto leftWidth = (leftWidthFull + leftCoord);
|
|
|
|
if (leftWidth > 0) {
|
|
|
|
p.setOpacity(leftAlpha);
|
|
|
|
p.drawPixmap(0, 0, leftWidth, _cacheUnder.height() / retina, _cacheUnder, (_cacheUnder.width() - leftWidth * cIntRetinaFactor()), 0, leftWidth * cIntRetinaFactor(), _cacheUnder.height());
|
|
|
|
}
|
|
|
|
auto rightWidth = rightWidthFull - rightCoord;
|
|
|
|
if (rightWidth > 0) {
|
|
|
|
p.setOpacity(rightAlpha);
|
|
|
|
p.drawPixmap(rightCoord, 0, _cacheOver, 0, 0, rightWidth * cIntRetinaFactor(), _cacheOver.height());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
auto coordUnder = anim::interpolate(0, -st::slideShift, progress);
|
|
|
|
auto coordOver = anim::interpolate(_cacheOver.width() / cIntRetinaFactor(), 0, progress);
|
|
|
|
if (coordOver) {
|
|
|
|
p.drawPixmap(QRect(0, 0, coordOver, _cacheUnder.height() / retina), _cacheUnder, QRect(-coordUnder * retina, 0, coordOver * retina, _cacheUnder.height()));
|
|
|
|
p.setOpacity(progress);
|
|
|
|
p.fillRect(0, 0, coordOver, _cacheUnder.height() / retina, st::slideFadeOutBg);
|
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
|
|
|
p.drawPixmap(QRect(coordOver, 0, _cacheOver.width() / retina, _cacheOver.height() / retina), _cacheOver, QRect(0, 0, _cacheOver.width(), _cacheOver.height()));
|
2016-11-11 08:59:55 +00:00
|
|
|
p.setOpacity(progress);
|
2017-10-03 17:41:44 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlideAnimation::setPixmaps(const QPixmap &oldContentCache, const QPixmap &newContentCache) {
|
|
|
|
_cacheUnder = oldContentCache;
|
|
|
|
_cacheOver = newContentCache;
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
void SlideAnimation::setTopBarShadow(bool enabled) {
|
|
|
|
_topBarShadowEnabled = enabled;
|
|
|
|
}
|
|
|
|
|
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() {
|
2016-11-11 08:59:55 +00:00
|
|
|
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
|