Create nice camera init effect.

This commit is contained in:
John Preston 2024-10-23 22:16:19 +04:00
parent 6287d306c2
commit 9ce6636c6a
2 changed files with 51 additions and 2 deletions

View file

@ -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<RpWidget>(_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<QLinearGradient*>(b)) {
return true;
}
auto hq = PainterHighQualityEnabler(p);
const auto gradient = v::get<QLinearGradient*>(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));
}

View file

@ -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 <crl/crl_object_on_queue.h>
@ -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<RpWidget> _preview;
crl::object_on_queue<Private> _private;
Ui::Animations::Simple _progressAnimation;