From 34caf6967ea924e83f07947ddcfefa97659aaa57 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 16 Oct 2025 11:43:25 +0300 Subject: [PATCH] Slightly optimized calculating of userpic geometry in profile top bar. --- .../info/profile/info_profile_top_bar.cpp | 45 ++++++++++--------- .../info/profile/info_profile_top_bar.h | 18 +++++--- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp b/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp index ffa86f7e25..053fa31775 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp @@ -831,8 +831,7 @@ QRect TopBar::userpicGeometry() const { return QRect(x, y, size, size); } -void TopBar::paintUserpic(QPainter &p) { - const auto geometry = userpicGeometry(); +void TopBar::paintUserpic(QPainter &p, const QRect &geometry) { if (_topicIconView) { _topicIconView->paintInRect(p, geometry); return; @@ -886,6 +885,8 @@ void TopBar::paintUserpic(QPainter &p) { void TopBar::paintEvent(QPaintEvent *e) { auto p = QPainter(this); + const auto geometry = userpicGeometry(); + if (_hasBackground && _cachedGradient.isNull()) { _cachedGradient = Ui::CreateTopBgGradient( QSize(width(), maximumHeight()), @@ -918,13 +919,13 @@ void TopBar::paintEvent(QPaintEvent *e) { } if (_patternEmoji && _patternEmoji->ready()) { - paintAnimatedPattern(p, rect()); + paintAnimatedPattern(p, rect(), geometry); } - paintPinnedToTopGifts(p, rect()); + paintPinnedToTopGifts(p, rect(), geometry); } - paintUserpic(p); - paintStoryOutline(p); + paintUserpic(p, geometry); + paintStoryOutline(p, geometry); } void TopBar::setupButtons( @@ -1184,21 +1185,25 @@ void TopBar::setupShowLastSeen(not_null controller) { }); } -void TopBar::setupAnimatedPattern() { - _animatedPoints = GenerateAnimatedPattern(userpicGeometry()); +void TopBar::setupAnimatedPattern(const QRect &userpicGeometry) { + _animatedPoints = GenerateAnimatedPattern(userpicGeometry.isNull() + ? TopBar::userpicGeometry() + : userpicGeometry); } -void TopBar::paintAnimatedPattern(QPainter &p, const QRect &rect) { +void TopBar::paintAnimatedPattern( + QPainter &p, + const QRect &rect, + const QRect &userpicGeometry) { if (!_patternEmoji || !_patternEmoji->ready()) { return; } { // TODO make it better. - const auto currentUserpicRect = userpicGeometry(); - if (_lastUserpicRect != currentUserpicRect) { - _lastUserpicRect = currentUserpicRect; - setupAnimatedPattern(); + if (_lastUserpicRect != userpicGeometry) { + _lastUserpicRect = userpicGeometry; + setupAnimatedPattern(userpicGeometry); } } @@ -1228,7 +1233,7 @@ void TopBar::paintAnimatedPattern(QPainter &p, const QRect &rect) { // const auto collapse = std::clamp((collapseDiff - 0.2) / 0.8, 0., 1.); const auto collapse = progress; - const auto userpicCenter = userpicGeometry().center(); + const auto userpicCenter = rect::center(userpicGeometry); const auto yOffset = 12 * (1. - progress); const auto imageSize = _basePatternImage.size() / style::DevicePixelRatio(); @@ -1429,7 +1434,10 @@ void TopBar::setupNewGifts(const std::vector &gifts) { }, _giftsLoadingLifetime); } -void TopBar::paintPinnedToTopGifts(QPainter &p, const QRect &rect) { +void TopBar::paintPinnedToTopGifts( + QPainter &p, + const QRect &rect, + const QRect &userpicRect) { if (_pinnedToTopGifts.empty()) { return; } @@ -1439,7 +1447,6 @@ void TopBar::paintPinnedToTopGifts(QPainter &p, const QRect &rect) { : (_giftsAppearing ? _progress.current() * _giftsAppearing->value(0.) : _progress.current()); - const auto userpicRect = _lastUserpicRect; const auto acx = userpicRect.x() + userpicRect.width() / 2.; const auto acy = userpicRect.y() + userpicRect.height() / 2.; const auto aw = userpicRect.width(); @@ -1544,7 +1551,7 @@ void TopBar::paintPinnedToTopGifts(QPainter &p, const QRect &rect) { p.setOpacity(1.); } -void TopBar::setupStoryOutline() { +void TopBar::setupStoryOutline(const QRect &geometry) { const auto user = _peer->asUser(); if (!user) { return; @@ -1621,7 +1628,7 @@ void TopBar::updateStoryOutline(std::optional edgeColor) { } } -void TopBar::paintStoryOutline(QPainter &p) { +void TopBar::paintStoryOutline(QPainter &p, const QRect &geometry) { if (!_hasStories || _storySegments.empty()) { return; } @@ -1637,8 +1644,6 @@ void TopBar::paintStoryOutline(QPainter &p) { } p.setOpacity(alpha); - - const auto geometry = userpicGeometry(); const auto outlineWidth = style::ConvertFloatScale(4.0); const auto padding = style::ConvertFloatScale(3.0); const auto outlineRect = QRectF(geometry).adjusted( diff --git a/Telegram/SourceFiles/info/profile/info_profile_top_bar.h b/Telegram/SourceFiles/info/profile/info_profile_top_bar.h index 98262ade9a..478f1026b5 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_top_bar.h +++ b/Telegram/SourceFiles/info/profile/info_profile_top_bar.h @@ -117,7 +117,7 @@ private: [[nodiscard]] int statusMostLeft() const; [[nodiscard]] QRect userpicGeometry() const; void updateUserpicButtonGeometry(); - void paintUserpic(QPainter &p); + void paintUserpic(QPainter &p, const QRect &geometry); void updateVideoUserpic(); void showTopBarMenu(not_null controller, bool check); void fillTopBarMenu( @@ -131,16 +131,22 @@ private: void setupShowLastSeen(not_null controller); void setupUniqueBadgeTooltip(); void hideBadgeTooltip(); - void setupAnimatedPattern(); - void paintAnimatedPattern(QPainter &p, const QRect &rect); + void setupAnimatedPattern(const QRect &userpicGeometry = QRect()); + void paintAnimatedPattern( + QPainter &p, + const QRect &rect, + const QRect &userpicGeometry); void setupPinnedToTopGifts(); void setupNewGifts(const std::vector &gifts); - void paintPinnedToTopGifts(QPainter &p, const QRect &rect); + void paintPinnedToTopGifts( + QPainter &p, + const QRect &rect, + const QRect &userpicGeometry); void adjustColors(const std::optional &edgeColor); void updateCollectibleStatus(); - void setupStoryOutline(); + void setupStoryOutline(const QRect &geometry = QRect()); void updateStoryOutline(std::optional edgeColor); - void paintStoryOutline(QPainter &p); + void paintStoryOutline(QPainter &p, const QRect &geometry); const not_null _peer; Data::ForumTopic *_topic = nullptr;