diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index eef393c47..341fbbed1 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -74,6 +74,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_options.h" #include "ui/emoji_config.h" #include "ui/effects/animations.h" +#include "ui/effects/spoiler_mess.h" #include "ui/cached_round_corners.h" #include "storage/serialize_common.h" #include "storage/storage_domain.h" @@ -255,6 +256,7 @@ void Application::run() { Ui::InitTextOptions(); Ui::StartCachedCorners(); Ui::Emoji::Init(); + Ui::PrepareDefaultSpoilerMess(); startEmojiImageLoader(); startSystemDarkModeViewer(); Media::Player::start(_audio.get()); diff --git a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp index 21d3c510d..210b4f3a9 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp @@ -84,11 +84,12 @@ void ExtendedPreview::ensureThumbnailRead() const { } bool ExtendedPreview::hasHeavyPart() const { - return !_inlineThumbnail.isNull(); + return _animation || !_inlineThumbnail.isNull(); } void ExtendedPreview::unloadHeavyPart() { _inlineThumbnail = _imageCache = QImage(); + _animation = nullptr; _caption.unloadCustomEmoji(); } @@ -192,7 +193,7 @@ void ExtendedPreview::draw(Painter &p, const PaintContext &context) const { | ((isRoundedInBubbleBottom() && _caption.isEmpty()) ? (RectPart::BottomLeft | RectPart::BottomRight) : RectPart::None)); validateImageCache(rthumb.size(), roundRadius, roundCorners); p.drawImage(rthumb.topLeft(), _imageCache); - fillSpoilerMess(p, rthumb, roundRadius, roundCorners); + fillSpoilerMess(p, context.now, rthumb, roundRadius, roundCorners); if (context.selected()) { Ui::FillComplexOverlayRect(p, st, rthumb, roundRadius, roundCorners); } @@ -267,25 +268,21 @@ QImage ExtendedPreview::prepareImageCache(QSize outer) const { void ExtendedPreview::fillSpoilerMess( QPainter &p, + crl::time now, QRect rect, ImageRoundRadius radius, RectParts corners) const { - const auto size = style::ConvertScale(100); - static const auto test = [&] { - const auto ratio = style::DevicePixelRatio(); - return Ui::GenerateSpoilerMess({ - .particleFadeInDuration = 200, - .particleFadeOutDuration = 200, - .particleSizeMin = style::ConvertScaleExact(1.5) * ratio, - .particleSizeMax = style::ConvertScaleExact(2.) * ratio, - .particleSpritesCount = 5, - .particlesCount = 2000, - .canvasSize = size * ratio, - .framesCount = 60, - .frameDuration = 33, + if (!_animation) { + _animation = std::make_unique([=] { + _parent->customEmojiRepaint(); }); - }(); - const auto frame = test.frame(); + history()->owner().registerHeavyViewPart(_parent); + } + _parent->clearCustomEmojiRepaint(); + const auto &spoiler = Ui::DefaultImageSpoiler(); + const auto size = spoiler.canvasSize() / style::DevicePixelRatio(); + const auto frame = spoiler.frame( + _animation->index(now, _parent->delegate()->elementIsGifPaused())); const auto columns = (rect.width() + size - 1) / size; const auto rows = (rect.height() + size - 1) / size; p.setClipRect(rect); diff --git a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.h b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.h index 396bc1378..6b3c3ab70 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.h +++ b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.h @@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL enum class ImageRoundRadius; +namespace Ui { +class SpoilerAnimation; +} // namespace Ui + namespace Data { struct Invoice; } // namespace Data @@ -84,6 +88,7 @@ private: void fillSpoilerMess( QPainter &p, + crl::time now, QRect rect, ImageRoundRadius radius, RectParts corners) const; @@ -91,6 +96,7 @@ private: const not_null _invoice; ClickHandlerPtr _link; Ui::Text::String _caption; + mutable std::unique_ptr _animation; mutable QImage _inlineThumbnail; mutable QImage _imageCache; mutable int _imageCacheRoundRadius : 4 = 0;