Added support of disabled animation in premium settings.

This commit is contained in:
23rd 2022-05-29 01:22:36 +03:00
parent de08e1d9a9
commit 7749fadf11

View file

@ -220,9 +220,6 @@ public:
void paint(Painter &p, const QRectF &rect); void paint(Painter &p, const QRectF &rect);
private: private:
void createStar(crl::time now);
int angle() const;
struct MiniStar { struct MiniStar {
crl::time birthTime = 0; crl::time birthTime = 0;
crl::time deathTime = 0; crl::time deathTime = 0;
@ -235,6 +232,12 @@ private:
int from = 0; int from = 0;
int length = 0; int length = 0;
}; };
void createStar(crl::time now);
[[nodiscard]] int angle() const;
[[nodiscard]] crl::time timeNow() const;
[[nodiscard]] int randomInterval(const Interval &interval) const;
const std::vector<Interval> _availableAngles; const std::vector<Interval> _availableAngles;
const Interval _lifeLength; const Interval _lifeLength;
const Interval _deathTime; const Interval _deathTime;
@ -273,20 +276,34 @@ MiniStars::MiniStars(Fn<void()> updateCallback)
, _animation([=](crl::time now) { , _animation([=](crl::time now) {
if (now > _nextBirthTime) { if (now > _nextBirthTime) {
createStar(now); createStar(now);
_nextBirthTime = now _nextBirthTime = now + randomInterval(_lifeLength);
+ _lifeLength.from
+ base::RandomIndex(_lifeLength.length);
} }
updateCallback(); updateCallback();
}) { }) {
_animation.start(); if (anim::Disabled()) {
const auto from = _deathTime.from + _deathTime.length;
for (auto i = -from; i < 0; i += randomInterval(_lifeLength)) {
createStar(i);
}
updateCallback();
} else {
_animation.start();
}
}
int MiniStars::randomInterval(const Interval &interval) const {
return interval.from + base::RandomIndex(interval.length);
}
crl::time MiniStars::timeNow() const {
return anim::Disabled() ? 0 : crl::now();
} }
void MiniStars::paint(Painter &p, const QRectF &rect) { void MiniStars::paint(Painter &p, const QRectF &rect) {
const auto center = rect.center(); const auto center = rect.center();
const auto opacity = p.opacity(); const auto opacity = p.opacity();
for (const auto &ministar : _ministars) { for (const auto &ministar : _ministars) {
const auto progress = (crl::now() - ministar.birthTime) const auto progress = (timeNow() - ministar.birthTime)
/ float64(ministar.deathTime - ministar.birthTime); / float64(ministar.deathTime - ministar.birthTime);
if (progress > 1.) { if (progress > 1.) {
continue; continue;
@ -330,13 +347,10 @@ int MiniStars::angle() const {
void MiniStars::createStar(crl::time now) { void MiniStars::createStar(crl::time now) {
auto ministar = MiniStar{ auto ministar = MiniStar{
.birthTime = now, .birthTime = now,
.deathTime = now .deathTime = now + randomInterval(_deathTime),
+ _deathTime.from
+ base::RandomIndex(_deathTime.length),
.angle = angle(), .angle = angle(),
.size = float64(_size.from + base::RandomIndex(_size.length)), .size = float64(randomInterval(_size)),
.alpha = float64(_alpha.from + base::RandomIndex(_alpha.length)) .alpha = float64(randomInterval(_alpha)) / 100.,
/ 100.,
}; };
for (auto i = 0; i < _ministars.size(); i++) { for (auto i = 0; i < _ministars.size(); i++) {
if (ministar.birthTime > _ministars[i].deathTime) { if (ministar.birthTime > _ministars[i].deathTime) {