From 8a58ded58268b1f597678004c44afbe34d8028d8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 14 May 2024 13:31:30 +0400 Subject: [PATCH] Show effect loading animation. --- Telegram/SourceFiles/menu/menu_send.cpp | 41 ++++++++++++++++++++++--- Telegram/SourceFiles/ui/chat/chat.style | 3 ++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/menu/menu_send.cpp b/Telegram/SourceFiles/menu/menu_send.cpp index b56491bcb..450c50d55 100644 --- a/Telegram/SourceFiles/menu/menu_send.cpp +++ b/Telegram/SourceFiles/menu/menu_send.cpp @@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_style.h" #include "ui/chat/chat_theme.h" #include "ui/effects/path_shift_gradient.h" +#include "ui/effects/radial_animation.h" #include "ui/effects/ripple_animation.h" #include "ui/text/text_utilities.h" #include "ui/widgets/buttons.h" @@ -103,6 +104,7 @@ private: void setupSend(Details details); void createLottie(); + bool checkIconBecameLoaded(); [[nodiscard]] bool checkReady(); const EffectId _effectId = 0; @@ -130,6 +132,8 @@ private: QRect _inner; QImage _bg; QPoint _itemShift; + QRect _iconRect; + std::unique_ptr _loading; rpl::lifetime _readyCheckLifetime; @@ -289,6 +293,28 @@ void EffectPreview::paintEvent(QPaintEvent *e) { _item->draw(p, context); p.translate(-_itemShift); + checkIconBecameLoaded(); + if (_icon.isNull()) { + if (!_loading) { + _loading = std::make_unique([=] { + update(); + }, st::effectPreviewLoading); + _loading->start(st::defaultInfiniteRadialAnimation.linearPeriod); + } + const auto loading = _iconRect.marginsRemoved( + { st::lineWidth, st::lineWidth, st::lineWidth, st::lineWidth }); + auto hq = PainterHighQualityEnabler(p); + Ui::InfiniteRadialAnimation::Draw( + p, + _loading->computeState(), + loading.topLeft(), + loading.size(), + width(), + _chatStyle->msgInDateFg(), + st::effectPreviewLoading.thickness); + } else { + _loading = nullptr; + } if (_lottie && _lottie->ready()) { const auto factor = style::DevicePixelRatio(); auto request = Lottie::FrameRequest(); @@ -364,6 +390,7 @@ void EffectPreview::setupItem() { shift + icon.x() + (icon.width() - size.width()) / 2, icon.y() + (icon.height() - size.height()) / 2); _itemShift = _inner.topLeft() - position; + _iconRect = icon.translated(_itemShift); } void EffectPreview::repaintBackground() { @@ -462,11 +489,17 @@ void EffectPreview::setupSend(Details details) { } } +bool EffectPreview::checkIconBecameLoaded() { + if (!_icon.isNull()) { + return false; + } + const auto reactions = &_show->session().data().reactions(); + _icon = reactions->resolveEffectImageFor(_effect.id.custom()); + return !_icon.isNull(); +} + bool EffectPreview::checkReady() { - if (_icon.isNull()) { - const auto reactions = &_show->session().data().reactions(); - _icon = reactions->resolveEffectImageFor(_effect.id.custom()); - repaintBackground(); + if (checkIconBecameLoaded()) { update(); } if (_effect.aroundAnimation) { diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index 182861622..1d7361bdd 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -1129,3 +1129,6 @@ effectPreviewPromoLabel: FlatLabel(defaultFlatLabel) { } } effectPreviewPromoPadding: margins(4px, 6px, 4px, 6px); +effectPreviewLoading: InfiniteRadialAnimation(defaultInfiniteRadialAnimation) { + thickness: 2px; +}