From d73d5724d87e1e09ed8f9f2b5f72f41e7f293f35 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 22 Oct 2021 13:45:04 +0400 Subject: [PATCH] Show radial progress in PeerShortInfoBox video. --- .../boxes/peers/peer_short_info_box.cpp | 47 ++++++++++++++++++- .../boxes/peers/peer_short_info_box.h | 4 ++ Telegram/SourceFiles/info/info.style | 5 ++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/peer_short_info_box.cpp b/Telegram/SourceFiles/boxes/peers/peer_short_info_box.cpp index e92288a05c..a8227adfd7 100644 --- a/Telegram/SourceFiles/boxes/peers/peer_short_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/peer_short_info_box.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/peers/peer_short_info_box.h" +#include "ui/effects/radial_animation.h" #include "ui/widgets/labels.h" #include "ui/widgets/scroll_area.h" #include "ui/wrap/vertical_layout.h" @@ -36,6 +37,17 @@ struct PeerShortInfoBox::CustomLabelStyle { float64 opacity = 1.; }; +struct PeerShortInfoBox::Radial { + explicit Radial(Fn &&callback); + + Ui::RadialAnimation radial; + base::Timer removeTimer; +}; + +PeerShortInfoBox::Radial::Radial(Fn &&callback) +: radial(callback) { +} + PeerShortInfoBox::CustomLabelStyle::CustomLabelStyle( const style::FlatLabel &original) : textFg([=, c = original.textFg]{ @@ -259,6 +271,7 @@ void PeerShortInfoBox::paintCover(QPainter &p) { paintCoverImage(p, frame.isNull() ? _userpicImage : frame); paintBars(p); paintShadow(p); + paintRadial(p); if (_videoInstance && _videoInstance->ready() && !paused) { _videoInstance->markFrameShown(); } @@ -437,6 +450,31 @@ void PeerShortInfoBox::paintShadow(QPainter &p) { p.setOpacity(1.); } +void PeerShortInfoBox::paintRadial(QPainter &p) { + const auto radial = radialRect(); + if (_videoInstance && _videoInstance->waitingShown()) { + const auto line = st::shortInfoRadialAnimation.thickness; + const auto arc = radial.marginsRemoved( + { line, line, line, line }); + p.setOpacity(_videoInstance->waitingOpacity()); + p.setPen(Qt::NoPen); + p.setBrush(st::radialBg); + { + PainterHighQualityEnabler hq(p); + p.drawEllipse(radial); + } + p.setOpacity(1.); + Ui::InfiniteRadialAnimation::Draw( + p, + _videoInstance->waitingState(), + arc.topLeft(), + arc.size(), + st::shortInfoWidth, + st::radialFg, + line); + } +} + QImage PeerShortInfoBox::currentVideoFrame() const { const auto coverSize = st::shortInfoWidth; const auto size = QSize(coverSize, coverSize); @@ -631,11 +669,16 @@ void PeerShortInfoBox::refreshBarImages() { QRect PeerShortInfoBox::radialRect() const { const auto cover = _cover->rect(); - return cover; + const auto size = st::boxLoadingSize; + return QRect( + cover.x() + (cover.width() - size) / 2, + cover.y() + (cover.height() - size) / 2, + size, + size); } void PeerShortInfoBox::videoWaiting() { if (!anim::Disabled()) { - update(radialRect()); + _cover->update(radialRect()); } } diff --git a/Telegram/SourceFiles/boxes/peers/peer_short_info_box.h b/Telegram/SourceFiles/boxes/peers/peer_short_info_box.h index 3111bb2b7d..0f9a08c8af 100644 --- a/Telegram/SourceFiles/boxes/peers/peer_short_info_box.h +++ b/Telegram/SourceFiles/boxes/peers/peer_short_info_box.h @@ -63,6 +63,7 @@ public: private: struct CustomLabelStyle; + struct Radial; void prepare() override; void prepareRows(); @@ -74,6 +75,7 @@ private: void paintCoverImage(QPainter &p, const QImage &image); void paintBars(QPainter &p); void paintShadow(QPainter &p); + void paintRadial(QPainter &p); void refreshRoundedTopImage(const QColor &color); int fillRoundedTopHeight(); @@ -132,6 +134,8 @@ private: Fn _videoPaused; QImage _shadowBottom; + std::unique_ptr _radial; + rpl::event_stream<> _openRequests; rpl::event_stream _moveRequests; diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index c255f0bac4..02f0b4daeb 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -984,3 +984,8 @@ shortInfoScroll: ScrollArea(defaultScrollArea) { duration: 150; hiding: 1000; } + +shortInfoRadialAnimation: InfiniteRadialAnimation(defaultInfiniteRadialAnimation) { + color: radialFg; + thickness: 2px; +}