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
|
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
2016-05-19 12:03:51 +00:00
|
|
|
#include "window/slide_animation.h"
|
|
|
|
|
|
|
|
namespace Window {
|
2016-05-12 16:05:20 +00:00
|
|
|
|
|
|
|
SlideAnimation::SlideAnimation()
|
2016-05-19 12:03:51 +00:00
|
|
|
: _animation(animation(this, &SlideAnimation::step)) {
|
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-05-12 16:05:20 +00:00
|
|
|
_animation.step(getms());
|
2016-05-19 12:38:09 +00:00
|
|
|
if (a_coordOver.current() > 0) {
|
|
|
|
p.drawPixmap(QRect(0, 0, a_coordOver.current(), _cacheUnder.height() / retina), _cacheUnder, QRect(-a_coordUnder.current() * retina, 0, a_coordOver.current() * retina, _cacheUnder.height()));
|
|
|
|
p.setOpacity(a_progress.current() * st::slideFadeOut);
|
|
|
|
p.fillRect(0, 0, a_coordOver.current(), _cacheUnder.height() / retina, st::black);
|
|
|
|
p.setOpacity(1);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
2016-05-19 12:38:09 +00:00
|
|
|
p.drawPixmap(QRect(a_coordOver.current(), 0, _cacheOver.width() / retina, _cacheOver.height() / retina), _cacheOver, QRect(0, 0, _cacheOver.width(), _cacheOver.height()));
|
|
|
|
p.setOpacity(a_progress.current());
|
|
|
|
p.drawPixmap(QRect(a_coordOver.current() - st::slideShadow.pxWidth(), 0, st::slideShadow.pxWidth(), _cacheOver.height() / retina), App::sprite(), st::slideShadow.rect());
|
2016-05-19 12:03:51 +00:00
|
|
|
|
|
|
|
if (_topBarShadowEnabled) {
|
|
|
|
p.setOpacity(1);
|
|
|
|
p.fillRect(0, st::topBarHeight, _cacheOver.width() / retina, st::lineWidth, st::shadowColor);
|
|
|
|
}
|
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) {
|
|
|
|
_repaintCallback = std_::move(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlideAnimation::setFinishedCallback(FinishedCallback &&callback) {
|
|
|
|
_finishedCallback = std_::move(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlideAnimation::start() {
|
2016-05-14 16:57:06 +00:00
|
|
|
int delta = st::slideShift;
|
2016-05-12 16:05:20 +00:00
|
|
|
if (_direction == SlideDirection::FromLeft) {
|
2016-05-19 12:38:09 +00:00
|
|
|
a_progress = anim::fvalue(1, 0);
|
|
|
|
std::swap(_cacheUnder, _cacheOver);
|
|
|
|
a_coordUnder = anim::ivalue(-delta, 0);
|
|
|
|
a_coordOver = anim::ivalue(0, _cacheOver.width() / cIntRetinaFactor());
|
2016-05-12 16:05:20 +00:00
|
|
|
} else {
|
2016-05-19 12:38:09 +00:00
|
|
|
a_progress = anim::fvalue(0, 1);
|
2016-05-12 16:05:20 +00:00
|
|
|
a_coordUnder = anim::ivalue(0, -delta);
|
2016-05-19 12:38:09 +00:00
|
|
|
a_coordOver = anim::ivalue(_cacheOver.width() / cIntRetinaFactor(), 0);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
_animation.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlideAnimation::step(float64 ms, bool timer) {
|
2016-05-19 12:03:51 +00:00
|
|
|
float64 dt = ms / st::slideDuration;
|
2016-05-12 16:05:20 +00:00
|
|
|
if (dt >= 1) {
|
|
|
|
dt = 1;
|
|
|
|
if (timer) {
|
|
|
|
_animation.stop();
|
|
|
|
a_coordUnder.finish();
|
|
|
|
a_coordOver.finish();
|
|
|
|
|
|
|
|
_finishedCallback.call();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:38:09 +00:00
|
|
|
a_coordUnder.update(dt, st::slideFunction);
|
|
|
|
a_coordOver.update(dt, st::slideFunction);
|
|
|
|
a_progress.update(dt, st::slideFunction);
|
2016-05-12 16:05:20 +00:00
|
|
|
if (timer) {
|
|
|
|
_repaintCallback.call();
|
|
|
|
}
|
|
|
|
}
|
2016-05-19 12:03:51 +00:00
|
|
|
|
|
|
|
} // namespace Window
|