mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 08:04:08 +02:00
Moved active animation processing from SendButton to VoiceRecordBar.
This commit is contained in:
parent
db564ca486
commit
3e4866d3b7
4 changed files with 48 additions and 32 deletions
|
@ -92,8 +92,28 @@ void VoiceRecordBar::init() {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
p.fillRect(rect(), st::historyComposeAreaBg);
|
p.fillRect(rect(), st::historyComposeAreaBg);
|
||||||
|
|
||||||
drawRecording(p, _send->recordActiveRatio());
|
drawRecording(p, activeAnimationRatio());
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
_inField.changes(
|
||||||
|
) | rpl::start_with_next([=](bool value) {
|
||||||
|
activeAnimate(value);
|
||||||
|
}, lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoiceRecordBar::activeAnimate(bool active) {
|
||||||
|
const auto to = active ? 1. : 0.;
|
||||||
|
const auto duration = st::historyRecordVoiceDuration;
|
||||||
|
if (_activeAnimation.animating()) {
|
||||||
|
_activeAnimation.change(to, duration);
|
||||||
|
} else {
|
||||||
|
auto callback = [=] {
|
||||||
|
update();
|
||||||
|
_send->requestPaintRecord(activeAnimationRatio());
|
||||||
|
};
|
||||||
|
const auto from = active ? 0. : 1.;
|
||||||
|
_activeAnimation.start(std::move(callback), from, to, duration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoiceRecordBar::startRecording() {
|
void VoiceRecordBar::startRecording() {
|
||||||
|
@ -116,7 +136,7 @@ void VoiceRecordBar::startRecording() {
|
||||||
_controller->widget()->setInnerFocus();
|
_controller->widget()->setInnerFocus();
|
||||||
|
|
||||||
update();
|
update();
|
||||||
_send->setRecordActive(true);
|
activeAnimate(true);
|
||||||
|
|
||||||
_send->events(
|
_send->events(
|
||||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||||
|
@ -127,14 +147,9 @@ void VoiceRecordBar::startRecording() {
|
||||||
const auto type = e->type();
|
const auto type = e->type();
|
||||||
if (type == QEvent::MouseMove) {
|
if (type == QEvent::MouseMove) {
|
||||||
const auto mouse = static_cast<QMouseEvent*>(e.get());
|
const auto mouse = static_cast<QMouseEvent*>(e.get());
|
||||||
const auto pos = mapFromGlobal(mouse->globalPos());
|
_inField = rect().contains(mapFromGlobal(mouse->globalPos()));
|
||||||
const auto inField = rect().contains(pos);
|
|
||||||
if (inField != _inField) {
|
|
||||||
_inField = inField;
|
|
||||||
_send->setRecordActive(_inField);
|
|
||||||
}
|
|
||||||
} else if (type == QEvent::MouseButtonRelease) {
|
} else if (type == QEvent::MouseButtonRelease) {
|
||||||
stopRecording(_inField);
|
stopRecording(_inField.current());
|
||||||
}
|
}
|
||||||
}, _recordingLifetime);
|
}, _recordingLifetime);
|
||||||
}
|
}
|
||||||
|
@ -160,7 +175,7 @@ void VoiceRecordBar::recordUpdated(quint16 level, int samples) {
|
||||||
_recordingAnimation.start();
|
_recordingAnimation.start();
|
||||||
_recordingSamples = samples;
|
_recordingSamples = samples;
|
||||||
if (samples < 0 || samples >= kMaxSamples) {
|
if (samples < 0 || samples >= kMaxSamples) {
|
||||||
stopRecording(samples > 0 && _inField);
|
stopRecording(samples > 0 && _inField.current());
|
||||||
}
|
}
|
||||||
Core::App().updateNonIdle();
|
Core::App().updateNonIdle();
|
||||||
update();
|
update();
|
||||||
|
@ -189,6 +204,8 @@ void VoiceRecordBar::stopRecording(bool send) {
|
||||||
_recordingLevel = anim::value();
|
_recordingLevel = anim::value();
|
||||||
_recordingAnimation.stop();
|
_recordingAnimation.stop();
|
||||||
|
|
||||||
|
_inField = false;
|
||||||
|
|
||||||
_recordingLifetime.destroy();
|
_recordingLifetime.destroy();
|
||||||
_recordingSamples = 0;
|
_recordingSamples = 0;
|
||||||
_sendActionUpdates.fire({ Api::SendProgressType::RecordVoice, -1 });
|
_sendActionUpdates.fire({ Api::SendProgressType::RecordVoice, -1 });
|
||||||
|
@ -196,7 +213,6 @@ void VoiceRecordBar::stopRecording(bool send) {
|
||||||
_controller->widget()->setInnerFocus();
|
_controller->widget()->setInnerFocus();
|
||||||
|
|
||||||
update();
|
update();
|
||||||
_send->setRecordActive(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoiceRecordBar::drawRecording(Painter &p, float64 recordActive) {
|
void VoiceRecordBar::drawRecording(Painter &p, float64 recordActive) {
|
||||||
|
@ -277,4 +293,8 @@ bool VoiceRecordBar::isTypeRecord() const {
|
||||||
return (_send->type() == Ui::SendButton::Type::Record);
|
return (_send->type() == Ui::SendButton::Type::Record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float64 VoiceRecordBar::activeAnimationRatio() const {
|
||||||
|
return _activeAnimation.value(_inField.current() ? 1. : 0.);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace HistoryView::Controls
|
} // namespace HistoryView::Controls
|
||||||
|
|
|
@ -64,6 +64,9 @@ private:
|
||||||
|
|
||||||
bool isTypeRecord() const;
|
bool isTypeRecord() const;
|
||||||
|
|
||||||
|
void activeAnimate(bool active);
|
||||||
|
float64 activeAnimationRatio() const;
|
||||||
|
|
||||||
const not_null<Window::SessionController*> _controller;
|
const not_null<Window::SessionController*> _controller;
|
||||||
const std::unique_ptr<Ui::RpWidget> _wrap;
|
const std::unique_ptr<Ui::RpWidget> _wrap;
|
||||||
const std::shared_ptr<Ui::SendButton> _send;
|
const std::shared_ptr<Ui::SendButton> _send;
|
||||||
|
@ -75,7 +78,7 @@ private:
|
||||||
QRect _redCircleRect;
|
QRect _redCircleRect;
|
||||||
|
|
||||||
rpl::variable<bool> _recording = false;
|
rpl::variable<bool> _recording = false;
|
||||||
bool _inField = false;
|
rpl::variable<bool> _inField = false;
|
||||||
int _recordingSamples = 0;
|
int _recordingSamples = 0;
|
||||||
|
|
||||||
const style::font &_cancelFont;
|
const style::font &_cancelFont;
|
||||||
|
@ -86,6 +89,7 @@ private:
|
||||||
// This can animate for a very long time (like in music playing),
|
// This can animate for a very long time (like in music playing),
|
||||||
// so it should be a Basic, not a Simple animation.
|
// so it should be a Basic, not a Simple animation.
|
||||||
Ui::Animations::Basic _recordingAnimation;
|
Ui::Animations::Basic _recordingAnimation;
|
||||||
|
Ui::Animations::Simple _activeAnimation;
|
||||||
anim::value _recordingLevel;
|
anim::value _recordingLevel;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,20 +43,7 @@ void SendButton::setType(Type type) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
if (_type != Type::Record) {
|
if (_type != Type::Record) {
|
||||||
_recordActive = false;
|
_recordProgress = 0.;
|
||||||
_a_recordActive.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SendButton::setRecordActive(bool recordActive) {
|
|
||||||
if (_recordActive != recordActive) {
|
|
||||||
_recordActive = recordActive;
|
|
||||||
_a_recordActive.start(
|
|
||||||
[=] { recordAnimationCallback(); },
|
|
||||||
_recordActive ? 0. : 1.,
|
|
||||||
_recordActive ? 1. : 0,
|
|
||||||
st::historyRecordVoiceDuration);
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +63,6 @@ void SendButton::setSlowmodeDelay(int seconds) {
|
||||||
|
|
||||||
void SendButton::finishAnimating() {
|
void SendButton::finishAnimating() {
|
||||||
_a_typeChanged.stop();
|
_a_typeChanged.stop();
|
||||||
_a_recordActive.stop();
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +75,13 @@ void SendButton::mouseMoveEvent(QMouseEvent *e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendButton::requestPaintRecord(float64 progress) {
|
||||||
|
if (_type == Type::Record) {
|
||||||
|
_recordProgress = progress;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SendButton::paintEvent(QPaintEvent *e) {
|
void SendButton::paintEvent(QPaintEvent *e) {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
|
|
||||||
|
@ -118,7 +111,7 @@ void SendButton::paintEvent(QPaintEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendButton::paintRecord(Painter &p, bool over) {
|
void SendButton::paintRecord(Painter &p, bool over) {
|
||||||
auto recordActive = recordActiveRatio();
|
const auto recordActive = _recordProgress;
|
||||||
if (!isDisabled()) {
|
if (!isDisabled()) {
|
||||||
auto rippleColor = anim::color(st::historyAttachEmoji.ripple.color, st::historyRecordVoiceRippleBgActive, recordActive);
|
auto rippleColor = anim::color(st::historyAttachEmoji.ripple.color, st::historyRecordVoiceRippleBgActive, recordActive);
|
||||||
paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y(), &rippleColor);
|
paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y(), &rippleColor);
|
||||||
|
|
|
@ -46,9 +46,7 @@ public:
|
||||||
_recordAnimationCallback = std::move(callback);
|
_recordAnimationCallback = std::move(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] float64 recordActiveRatio() {
|
void requestPaintRecord(float64 progress);
|
||||||
return _a_recordActive.value(_recordActive ? 1. : 0.);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QMouseEvent *e) override;
|
void mouseMoveEvent(QMouseEvent *e) override;
|
||||||
|
@ -76,7 +74,8 @@ private:
|
||||||
QPixmap _contentFrom, _contentTo;
|
QPixmap _contentFrom, _contentTo;
|
||||||
|
|
||||||
Ui::Animations::Simple _a_typeChanged;
|
Ui::Animations::Simple _a_typeChanged;
|
||||||
Ui::Animations::Simple _a_recordActive;
|
|
||||||
|
float64 _recordProgress = 0.;
|
||||||
|
|
||||||
bool _recording = false;
|
bool _recording = false;
|
||||||
Fn<void()> _recordStartCallback;
|
Fn<void()> _recordStartCallback;
|
||||||
|
|
Loading…
Add table
Reference in a new issue