mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added recursive animation to lock hint while recording voice.
This commit is contained in:
parent
6bd2a7c962
commit
f56ddbb1e0
2 changed files with 57 additions and 3 deletions
|
@ -1562,7 +1562,7 @@ void VoiceRecordBar::init() {
|
||||||
if (value == 0. && !show) {
|
if (value == 0. && !show) {
|
||||||
_lock->hide();
|
_lock->hide();
|
||||||
} else if (value == 1. && show) {
|
} else if (value == 1. && show) {
|
||||||
computeAndSetLockProgress(QCursor::pos());
|
_lock->requestPaintProgress(calcLockProgress(QCursor::pos()));
|
||||||
}
|
}
|
||||||
if (_fullRecord && !show) {
|
if (_fullRecord && !show) {
|
||||||
updateTTLGeometry(TTLAnimationType::RightLeft, 1.);
|
updateTTLGeometry(TTLAnimationType::RightLeft, 1.);
|
||||||
|
@ -1867,6 +1867,52 @@ void VoiceRecordBar::startRecording() {
|
||||||
|
|
||||||
_inField = true;
|
_inField = true;
|
||||||
|
|
||||||
|
struct FloatingState {
|
||||||
|
Ui::Animations::Basic animation;
|
||||||
|
float64 animationProgress = 0;
|
||||||
|
float64 cursorProgress = 0;
|
||||||
|
bool lockCapturedByInput = false;
|
||||||
|
float64 frameCounter = 0;
|
||||||
|
rpl::lifetime lifetime;
|
||||||
|
};
|
||||||
|
const auto stateOwned
|
||||||
|
= _recordingLifetime.make_state<std::unique_ptr<FloatingState>>(
|
||||||
|
std::make_unique<FloatingState>());
|
||||||
|
const auto state = stateOwned->get();
|
||||||
|
|
||||||
|
_lock->locks() | rpl::start_with_next([=] {
|
||||||
|
stateOwned->reset();
|
||||||
|
}, state->lifetime);
|
||||||
|
|
||||||
|
constexpr auto kAnimationThreshold = 0.35;
|
||||||
|
const auto calcStateRatio = [=](float64 counter) {
|
||||||
|
return (1 - std::cos(std::fmod(counter, 2 * M_PI))) * 0.5;
|
||||||
|
};
|
||||||
|
state->animation.init([=](crl::time now) {
|
||||||
|
if (state->cursorProgress > kAnimationThreshold) {
|
||||||
|
state->lockCapturedByInput = true;
|
||||||
|
}
|
||||||
|
if (state->lockCapturedByInput) {
|
||||||
|
if (state->cursorProgress < 0.01) {
|
||||||
|
state->lockCapturedByInput = false;
|
||||||
|
state->frameCounter = 0;
|
||||||
|
} else {
|
||||||
|
_lock->requestPaintProgress(state->cursorProgress);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const auto progress = anim::interpolateF(
|
||||||
|
state->cursorProgress,
|
||||||
|
kAnimationThreshold,
|
||||||
|
calcStateRatio(state->frameCounter));
|
||||||
|
state->frameCounter += 0.01;
|
||||||
|
_lock->requestPaintProgress(progress);
|
||||||
|
});
|
||||||
|
state->animation.start();
|
||||||
|
if (hasDuration()) {
|
||||||
|
stateOwned->reset();
|
||||||
|
}
|
||||||
|
|
||||||
_send->events(
|
_send->events(
|
||||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||||
return (e->type() == QEvent::MouseMove
|
return (e->type() == QEvent::MouseMove
|
||||||
|
@ -1887,7 +1933,10 @@ void VoiceRecordBar::startRecording() {
|
||||||
if (_showLockAnimation.animating() || !hasDuration()) {
|
if (_showLockAnimation.animating() || !hasDuration()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
computeAndSetLockProgress(mouse->globalPos());
|
const auto inputProgress = calcLockProgress(mouse->globalPos());
|
||||||
|
if (inputProgress > state->animationProgress) {
|
||||||
|
state->cursorProgress = inputProgress;
|
||||||
|
}
|
||||||
} else if (type == QEvent::MouseButtonRelease) {
|
} else if (type == QEvent::MouseButtonRelease) {
|
||||||
checkTipRequired();
|
checkTipRequired();
|
||||||
stop(_inField.current());
|
stop(_inField.current());
|
||||||
|
@ -2273,10 +2322,14 @@ float64 VoiceRecordBar::showListenAnimationRatio() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoiceRecordBar::computeAndSetLockProgress(QPoint globalPos) {
|
void VoiceRecordBar::computeAndSetLockProgress(QPoint globalPos) {
|
||||||
|
_lock->requestPaintProgress(calcLockProgress(globalPos));
|
||||||
|
}
|
||||||
|
|
||||||
|
float64 VoiceRecordBar::calcLockProgress(QPoint globalPos) {
|
||||||
const auto localPos = mapFromGlobal(globalPos);
|
const auto localPos = mapFromGlobal(globalPos);
|
||||||
const auto lower = _lock->height();
|
const auto lower = _lock->height();
|
||||||
const auto higher = 0;
|
const auto higher = 0;
|
||||||
_lock->requestPaintProgress(Progress(localPos.y(), higher - lower));
|
return Progress(localPos.y(), higher - lower);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VoiceRecordBar::peekTTLState() const {
|
bool VoiceRecordBar::peekTTLState() const {
|
||||||
|
|
|
@ -156,6 +156,7 @@ private:
|
||||||
[[nodiscard]] float64 activeAnimationRatio() const;
|
[[nodiscard]] float64 activeAnimationRatio() const;
|
||||||
|
|
||||||
void computeAndSetLockProgress(QPoint globalPos);
|
void computeAndSetLockProgress(QPoint globalPos);
|
||||||
|
[[nodiscard]] float64 calcLockProgress(QPoint globalPos);
|
||||||
|
|
||||||
[[nodiscard]] bool peekTTLState() const;
|
[[nodiscard]] bool peekTTLState() const;
|
||||||
[[nodiscard]] bool takeTTLState() const;
|
[[nodiscard]] bool takeTTLState() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue