2016-09-28 10:15:03 +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"
|
|
|
|
#include "ui/effects/radial_animation.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
RadialAnimation::RadialAnimation(AnimationCallbacks &&callbacks)
|
2016-12-05 11:01:08 +00:00
|
|
|
: a_arcStart(0, FullArcLength)
|
2016-09-28 10:15:03 +00:00
|
|
|
, _animation(std_::move(callbacks)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadialAnimation::start(float64 prg) {
|
|
|
|
_firstStart = _lastStart = _lastTime = getms();
|
|
|
|
int32 iprg = qRound(qMax(prg, 0.0001) * AlmostFullArcLength), iprgstrict = qRound(prg * AlmostFullArcLength);
|
2016-12-05 11:01:08 +00:00
|
|
|
a_arcEnd = anim::value(iprgstrict, iprg);
|
2016-09-28 10:15:03 +00:00
|
|
|
_animation.start();
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void RadialAnimation::update(float64 prg, bool finished, TimeMs ms) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto iprg = qRound(qMax(prg, 0.0001) * AlmostFullArcLength);
|
|
|
|
if (iprg != qRound(a_arcEnd.to())) {
|
2016-09-28 10:15:03 +00:00
|
|
|
a_arcEnd.start(iprg);
|
|
|
|
_lastStart = _lastTime;
|
|
|
|
}
|
|
|
|
_lastTime = ms;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto dt = float64(ms - _lastStart);
|
|
|
|
auto fulldt = float64(ms - _firstStart);
|
2016-09-28 10:15:03 +00:00
|
|
|
_opacity = qMin(fulldt / st::radialDuration, 1.);
|
|
|
|
if (!finished) {
|
|
|
|
a_arcEnd.update(1. - (st::radialDuration / (st::radialDuration + dt)), anim::linear);
|
|
|
|
} else if (dt >= st::radialDuration) {
|
2016-12-05 11:01:08 +00:00
|
|
|
a_arcEnd.update(1., anim::linear);
|
2016-09-28 10:15:03 +00:00
|
|
|
stop();
|
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto r = dt / st::radialDuration;
|
2016-09-28 10:15:03 +00:00
|
|
|
a_arcEnd.update(r, anim::linear);
|
|
|
|
_opacity *= 1 - r;
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
auto fromstart = fulldt / st::radialPeriod;
|
2016-09-28 10:15:03 +00:00
|
|
|
a_arcStart.update(fromstart - std::floor(fromstart), anim::linear);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadialAnimation::stop() {
|
|
|
|
_firstStart = _lastStart = _lastTime = 0;
|
2016-12-05 11:01:08 +00:00
|
|
|
a_arcEnd = anim::value();
|
2016-09-28 10:15:03 +00:00
|
|
|
_animation.stop();
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void RadialAnimation::step(TimeMs ms) {
|
2016-09-28 10:15:03 +00:00
|
|
|
_animation.step(ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadialAnimation::draw(Painter &p, const QRect &inner, int32 thickness, const style::color &color) {
|
|
|
|
float64 o = p.opacity();
|
|
|
|
p.setOpacity(o * _opacity);
|
|
|
|
|
|
|
|
QPen pen(color->p), was(p.pen());
|
|
|
|
pen.setWidth(thickness);
|
2016-11-28 13:42:37 +00:00
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
2016-09-28 10:15:03 +00:00
|
|
|
p.setPen(pen);
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto len = MinArcLength + qRound(a_arcEnd.current());
|
|
|
|
auto from = QuarterArcLength - qRound(a_arcStart.current()) - len;
|
2016-09-28 10:15:03 +00:00
|
|
|
if (rtl()) {
|
|
|
|
from = QuarterArcLength - (from - QuarterArcLength) - len;
|
|
|
|
if (from < 0) from += FullArcLength;
|
|
|
|
}
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawArc(inner, from, len);
|
|
|
|
}
|
2016-09-28 10:15:03 +00:00
|
|
|
|
|
|
|
p.setPen(was);
|
|
|
|
p.setOpacity(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Ui
|