mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Slightly optimized drawing of ministars in premium settings.
This commit is contained in:
parent
ce40ecc7f9
commit
b43f8fcff7
3 changed files with 34 additions and 22 deletions
|
@ -1359,6 +1359,9 @@ void Premium::setupContent() {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
}, box->lifetime());
|
}, box->lifetime());
|
||||||
|
|
||||||
|
box->boxClosing(
|
||||||
|
) | rpl::start_with_next(hidden, box->lifetime());
|
||||||
|
|
||||||
if (controller->session().premium()) {
|
if (controller->session().premium()) {
|
||||||
box->addButton(tr::lng_close(), [=] {
|
box->addButton(tr::lng_close(), [=] {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
|
@ -1370,9 +1373,6 @@ void Premium::setupContent() {
|
||||||
[] { return u"double_limits"_q; }
|
[] { return u"double_limits"_q; }
|
||||||
});
|
});
|
||||||
|
|
||||||
box->boxClosing(
|
|
||||||
) | rpl::start_with_next(hidden, box->lifetime());
|
|
||||||
|
|
||||||
box->setShowFinishedCallback([=] {
|
box->setShowFinishedCallback([=] {
|
||||||
button->startGlareAnimation();
|
button->startGlareAnimation();
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,7 +36,6 @@ MiniStars::MiniStars(Fn<void(const QRect &r)> updateCallback, bool opaque)
|
||||||
, _animation([=](crl::time now) {
|
, _animation([=](crl::time now) {
|
||||||
if (now > _nextBirthTime && !_paused) {
|
if (now > _nextBirthTime && !_paused) {
|
||||||
createStar(now);
|
createStar(now);
|
||||||
_nextBirthTime = now + randomInterval(_lifeLength);
|
|
||||||
}
|
}
|
||||||
if (_rectToUpdate.isValid()) {
|
if (_rectToUpdate.isValid()) {
|
||||||
updateCallback(base::take(_rectToUpdate));
|
updateCallback(base::take(_rectToUpdate));
|
||||||
|
@ -44,7 +43,10 @@ MiniStars::MiniStars(Fn<void(const QRect &r)> updateCallback, bool opaque)
|
||||||
}) {
|
}) {
|
||||||
if (anim::Disabled()) {
|
if (anim::Disabled()) {
|
||||||
const auto from = _deathTime.from + _deathTime.length;
|
const auto from = _deathTime.from + _deathTime.length;
|
||||||
for (auto i = -from; i < 0; i += randomInterval(_lifeLength)) {
|
auto r = bytes::vector(from);
|
||||||
|
base::RandomFill(r.data(), r.size());
|
||||||
|
|
||||||
|
for (auto i = -from; i < 0; i += randomInterval(_lifeLength, r[-i])) {
|
||||||
createStar(i);
|
createStar(i);
|
||||||
}
|
}
|
||||||
updateCallback(_rectToUpdate);
|
updateCallback(_rectToUpdate);
|
||||||
|
@ -53,8 +55,10 @@ MiniStars::MiniStars(Fn<void(const QRect &r)> updateCallback, bool opaque)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int MiniStars::randomInterval(const Interval &interval) const {
|
int MiniStars::randomInterval(
|
||||||
return interval.from + base::RandomIndex(interval.length);
|
const Interval &interval,
|
||||||
|
const bytes::type &random) const {
|
||||||
|
return interval.from + (uchar(random) % interval.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
crl::time MiniStars::timeNow() const {
|
crl::time MiniStars::timeNow() const {
|
||||||
|
@ -64,8 +68,9 @@ crl::time MiniStars::timeNow() const {
|
||||||
void MiniStars::paint(QPainter &p, const QRectF &rect) {
|
void MiniStars::paint(QPainter &p, const QRectF &rect) {
|
||||||
const auto center = rect.center();
|
const auto center = rect.center();
|
||||||
const auto opacity = p.opacity();
|
const auto opacity = p.opacity();
|
||||||
|
const auto now = timeNow();
|
||||||
for (const auto &ministar : _ministars) {
|
for (const auto &ministar : _ministars) {
|
||||||
const auto progress = (timeNow() - ministar.birthTime)
|
const auto progress = (now - ministar.birthTime)
|
||||||
/ float64(ministar.deathTime - ministar.birthTime);
|
/ float64(ministar.deathTime - ministar.birthTime);
|
||||||
if (progress > 1.) {
|
if (progress > 1.) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -122,21 +127,27 @@ void MiniStars::setPaused(bool paused) {
|
||||||
_paused = paused;
|
_paused = paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MiniStars::angle() const {
|
|
||||||
const auto &interval = _availableAngles[
|
|
||||||
base::RandomIndex(_availableAngles.size())];
|
|
||||||
return base::RandomIndex(interval.length) + interval.from;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MiniStars::createStar(crl::time now) {
|
void MiniStars::createStar(crl::time now) {
|
||||||
|
constexpr auto kRandomSize = 8;
|
||||||
|
auto random = bytes::vector(kRandomSize);
|
||||||
|
base::RandomFill(random.data(), random.size());
|
||||||
|
|
||||||
|
auto i = 0;
|
||||||
|
auto next = [&] { return random[i++]; };
|
||||||
|
|
||||||
|
_nextBirthTime = now + randomInterval(_lifeLength, next());
|
||||||
|
|
||||||
|
const auto &angleInterval = _availableAngles[
|
||||||
|
uchar(next()) % _availableAngles.size()];
|
||||||
|
|
||||||
auto ministar = MiniStar{
|
auto ministar = MiniStar{
|
||||||
.birthTime = now,
|
.birthTime = now,
|
||||||
.deathTime = now + randomInterval(_deathTime),
|
.deathTime = now + randomInterval(_deathTime, next()),
|
||||||
.angle = angle(),
|
.angle = randomInterval(angleInterval, next()),
|
||||||
.size = float64(randomInterval(_size)),
|
.size = float64(randomInterval(_size, next())),
|
||||||
.alpha = float64(randomInterval(_alpha)) / 100.,
|
.alpha = float64(randomInterval(_alpha, next())) / 100.,
|
||||||
.sinFactor = randomInterval(_sinFactor) / 100.
|
.sinFactor = randomInterval(_sinFactor, next()) / 100.
|
||||||
* (base::RandomIndex(2) == 1 ? 1. : -1.),
|
* ((uchar(next()) % 2) == 1 ? 1. : -1.),
|
||||||
};
|
};
|
||||||
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) {
|
||||||
|
|
|
@ -39,9 +39,10 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
void createStar(crl::time now);
|
void createStar(crl::time now);
|
||||||
[[nodiscard]] int angle() const;
|
|
||||||
[[nodiscard]] crl::time timeNow() const;
|
[[nodiscard]] crl::time timeNow() const;
|
||||||
[[nodiscard]] int randomInterval(const Interval &interval) const;
|
[[nodiscard]] int randomInterval(
|
||||||
|
const Interval &interval,
|
||||||
|
const gsl::byte &random) const;
|
||||||
|
|
||||||
const std::vector<Interval> _availableAngles;
|
const std::vector<Interval> _availableAngles;
|
||||||
const Interval _lifeLength;
|
const Interval _lifeLength;
|
||||||
|
|
Loading…
Add table
Reference in a new issue