From e7f02de5c46fbaeaf855cfb49c3ecda154752f8e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 30 May 2026 13:39:31 +0300 Subject: [PATCH] Added star particles to premium cover top bar behind premium star. --- .../ui/effects/premium_top_bar.cpp | 72 +++++++++++++------ .../SourceFiles/ui/effects/premium_top_bar.h | 2 + 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/ui/effects/premium_top_bar.cpp b/Telegram/SourceFiles/ui/effects/premium_top_bar.cpp index db2e7e650b..beb3c6f0d9 100644 --- a/Telegram/SourceFiles/ui/effects/premium_top_bar.cpp +++ b/Telegram/SourceFiles/ui/effects/premium_top_bar.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/painter.h" #include "ui/effects/premium_graphics.h" #include "ui/effects/premium_star.h" +#include "ui/effects/premium_star_particles.h" #include "ui/widgets/labels.h" #include "ui/wrap/fade_wrap.h" #include "ui/rect.h" @@ -29,6 +30,8 @@ constexpr auto kMinAcceptableContrast = 4.5; // 1.14; constexpr auto kStar3dScale = 2.; +constexpr auto kStarParticlesFieldScale = 2.2; + [[nodiscard]] QImage ScaleTo(QImage image) { using namespace style; const auto size = image.size(); @@ -123,6 +126,13 @@ TopBar::TopBar( : MiniStarsType::BiStars) { if (descriptor.use3dStar && Star::Supported()) { _star3d = CreateChild(this); + _starParticles3d = std::make_unique([=]( + const QRect &area) { + update(area); + }); + _star3d->flungStrength() | rpl::on_next([=](float64 strength) { + _starParticles3d->fling(strength); + }, lifetime()); } std::move( @@ -183,13 +193,14 @@ TopBar::TopBar( _star3d->setColors( QColor(255, 255, 255), QColor(0xE3, 0xEC, 0xFA)); + _starParticles3d->setColor(QColor(255, 255, 255)); } else { const auto stops = descriptor.gradientStops ? (*descriptor.gradientStops) : Ui::Premium::ButtonGradientStops(); - _star3d->setColors( - stops.front().second, - stops.back().second); + const auto middle = stops[stops.size() / 2].second; + _star3d->setColors(stops.front().second, middle); + _starParticles3d->setColor(middle); } } auto event = QResizeEvent(size(), size()); @@ -218,6 +229,9 @@ void TopBar::setPaused(bool paused) { if (_star3d) { _star3d->setPaused(paused); } + if (_starParticles3d) { + _starParticles3d->setPaused(paused); + } } void TopBar::setTextPosition(int x, int y) { @@ -289,28 +303,40 @@ void TopBar::paintEvent(QPaintEvent *e) { TopBarAbstract::paintEdges(p); } - p.setOpacity(_progress.body); - p.translate(_starRect.center()); - p.scale(_progress.body, _progress.body); - p.translate(-_starRect.center()); - if (_progress.top) { - _ministars.paint(p); - } - if (_lottie) { - _lottie->paint( - p, - _starRect.left() - + (_starRect.width() - _lottie->width()) / 2 - - st::lineWidth * 6, - _starRect.top()); - if (!_lottie->animating() && _lottie->frameIndex() > 0) { - _lottie->animate( - [=] { update(_starRect.toRect() + Margins(st::lineWidth)); }, - 0, - _lottie->framesCount() - 1); + if (_starParticles3d) { + if (_progress.top) { + auto field = Rect(_starRect.size() * kStarParticlesFieldScale); + field.moveCenter(rect::center(_starRect)); + p.setOpacity(_progress.body); + _starParticles3d->paint(p, field); + p.setOpacity(1.); } + } else { + p.setOpacity(_progress.body); + p.translate(rect::center(_starRect)); + p.scale(_progress.body, _progress.body); + p.translate(-rect::center(_starRect)); + if (_progress.top) { + _ministars.paint(p); + } + if (_lottie) { + _lottie->paint( + p, + _starRect.left() + + (_starRect.width() - _lottie->width()) / 2 + - st::lineWidth * 6, + _starRect.top()); + if (!_lottie->animating() && _lottie->frameIndex() > 0) { + _lottie->animate( + [=] { + update(_starRect.toRect() + Margins(st::lineWidth)); + }, + 0, + _lottie->framesCount() - 1); + } + } + p.resetTransform(); } - p.resetTransform(); if (!_dollar.isNull()) { diff --git a/Telegram/SourceFiles/ui/effects/premium_top_bar.h b/Telegram/SourceFiles/ui/effects/premium_top_bar.h index 927563a13b..9a2ad2313a 100644 --- a/Telegram/SourceFiles/ui/effects/premium_top_bar.h +++ b/Telegram/SourceFiles/ui/effects/premium_top_bar.h @@ -30,6 +30,7 @@ class Icon; namespace Ui::Premium { class Star; +class StarParticles; class TopBarAbstract : public RpWidget { public: @@ -106,6 +107,7 @@ private: QImage _dollar; std::unique_ptr _lottie; Star *_star3d = nullptr; + std::unique_ptr _starParticles3d; struct { float64 top = 0.;