2016-05-12 16:05:20 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
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"
|
|
|
|
|
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();
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
// Animation callback can destroy "this", so we don't pass "ms".
|
|
|
|
auto progress = _animation.current((_direction == SlideDirection::FromLeft) ? 0. : 1.);
|
2016-11-11 08:59:55 +00:00
|
|
|
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);
|
2016-05-19 12:38:09 +00:00
|
|
|
p.setOpacity(1);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
2016-11-11 08:59:55 +00:00
|
|
|
p.drawPixmap(QRect(coordOver, 0, _cacheOver.width() / retina, _cacheOver.height() / retina), _cacheOver, QRect(0, 0, _cacheOver.width(), _cacheOver.height()));
|
|
|
|
p.setOpacity(progress);
|
|
|
|
st::slideShadow.fill(p, QRect(coordOver - st::slideShadow.width(), 0, st::slideShadow.width(), _cacheOver.height() / retina));
|
2016-05-19 12:03:51 +00:00
|
|
|
|
|
|
|
if (_topBarShadowEnabled) {
|
|
|
|
p.setOpacity(1);
|
2016-12-21 15:05:58 +00:00
|
|
|
p.fillRect(0, st::topBarHeight, _cacheOver.width() / retina, st::lineWidth, st::shadowFg);
|
2016-05-19 12:03:51 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
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 delta = st::slideShift;
|
|
|
|
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
|