From 9ce6636c6a52646a8d5a7a357f7b8a1a427f63e6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 23 Oct 2024 22:16:19 +0400 Subject: [PATCH] Create nice camera init effect. --- .../ui/controls/round_video_recorder.cpp | 49 ++++++++++++++++++- .../ui/controls/round_video_recorder.h | 4 ++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp b/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp index 7d9cf9689..c7383614a 100644 --- a/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp +++ b/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp @@ -1031,6 +1031,12 @@ void RoundVideoRecorder::Private::updateResultDuration( RoundVideoRecorder::RoundVideoRecorder( RoundVideoRecorderDescriptor &&descriptor) : _descriptor(std::move(descriptor)) +, _gradientBg(QColor(255, 255, 255, 0)) +, _gradientFg(QColor(255, 255, 255, 48)) +, _gradient( + _gradientBg.color(), + _gradientFg.color(), + [=] { _preview->update(); }) , _preview(std::make_unique(_descriptor.container)) , _private(MinithumbSize()) { setup(); @@ -1192,6 +1198,43 @@ void RoundVideoRecorder::setup() { QRect(0, 0, side, side))); }, raw->lifetime()); + const auto paintPlaceholder = [=](QPainter &p, QRect inner) { + p.drawImage(inner, _framePlaceholder); + if (_paused) { + return; + } + + _gradient.startFrame( + 0, + raw->width(), + raw->width() * 2 / 3); + _gradient.paint([&](const Ui::PathShiftGradient::Background &b) { + if (!v::is(b)) { + return true; + } + auto hq = PainterHighQualityEnabler(p); + const auto gradient = v::get(b); + + auto copy = *gradient; + auto stops = copy.stops(); + for (auto &pair : stops) { + if (pair.second.alpha() > 0) { + pair.second.setAlpha(255); + } + } + copy.setStops(stops); + + const auto stroke = style::ConvertScaleExact(1.); + const auto sub = stroke / 2.; + p.setPen(QPen(QBrush(copy), stroke)); + + p.setBrush(*gradient); + const auto innerf = QRectF(inner); + p.drawEllipse(innerf.marginsRemoved({ sub, sub, sub, sub })); + return true; + }); + }; + raw->paintRequest() | rpl::start_with_next([=] { prepareFrame(); @@ -1202,14 +1245,16 @@ void RoundVideoRecorder::setup() { } else if (!_visible) { return; } + p.drawImage(raw->rect(), _shadow); const auto inner = QRect(_extent, _extent, _side, _side); const auto fading = _fadeContentAnimation.animating(); if (!_progressReceived && !fading) { - p.drawImage(inner, _framePlaceholder); + paintPlaceholder(p, inner); } else { if (fading) { - p.drawImage(inner, _framePlaceholder); + paintPlaceholder(p, inner); + const auto to = _progressReceived ? 1. : 0.; p.setOpacity(opacity * _fadeContentAnimation.value(to)); } diff --git a/Telegram/SourceFiles/ui/controls/round_video_recorder.h b/Telegram/SourceFiles/ui/controls/round_video_recorder.h index ecef3e425..e8cd5379f 100644 --- a/Telegram/SourceFiles/ui/controls/round_video_recorder.h +++ b/Telegram/SourceFiles/ui/controls/round_video_recorder.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/weak_ptr.h" #include "ui/effects/animations.h" +#include "ui/effects/path_shift_gradient.h" #include @@ -91,6 +92,9 @@ private: [[nodiscard]] PreviewFrame lookupPreviewFrame() const; const RoundVideoRecorderDescriptor _descriptor; + style::owned_color _gradientBg; + style::owned_color _gradientFg; + PathShiftGradient _gradient; std::unique_ptr _preview; crl::object_on_queue _private; Ui::Animations::Simple _progressAnimation;