Moved progress clamping in mute button to single place.

This commit is contained in:
23rd 2020-12-18 06:55:29 +03:00
parent a8edd6567e
commit 1d2357eed9

View file

@ -133,6 +133,10 @@ bool IsInactive(CallMuteButtonType type) {
return IsConnecting(type) || (type == CallMuteButtonType::ForceMuted); return IsConnecting(type) || (type == CallMuteButtonType::ForceMuted);
} }
auto Clamp(float64 value) {
return std::clamp(value, 0., 1.);
}
} // namespace } // namespace
class BlobsWidget final : public RpWidget { class BlobsWidget final : public RpWidget {
@ -247,10 +251,8 @@ void BlobsWidget::init() {
const auto scale = (_switchConnectingProgress > 0.) const auto scale = (_switchConnectingProgress > 0.)
? anim::easeOutBack( ? anim::easeOutBack(
1., 1.,
_blobsScaleEnter * (1. - std::clamp( _blobsScaleEnter * (1. - Clamp(
(_switchConnectingProgress / kBlobPartAnimation), _switchConnectingProgress / kBlobPartAnimation)))
0.,
1.)))
: _blobsScaleEnter; : _blobsScaleEnter;
_blobs.paint(p, _blobBrush, scale); _blobs.paint(p, _blobBrush, scale);
@ -263,10 +265,8 @@ void BlobsWidget::init() {
if (_switchConnectingProgress > 0.) { if (_switchConnectingProgress > 0.) {
p.resetTransform(); p.resetTransform();
const auto circleProgress = std::clamp( const auto circleProgress =
(_switchConnectingProgress - kBlobPartAnimation), Clamp(_switchConnectingProgress - kBlobPartAnimation)
0.,
1.)
/ kFillCirclePartAnimation; / kFillCirclePartAnimation;
const auto mF = (_circleRect.width() / 2) * (1. - circleProgress); const auto mF = (_circleRect.width() / 2) * (1. - circleProgress);
@ -299,10 +299,8 @@ void BlobsWidget::init() {
_blobs.updateLevel(now - _blobsLastTime); _blobs.updateLevel(now - _blobsLastTime);
_blobsLastTime = now; _blobsLastTime = now;
const auto dt = std::clamp( const auto dt = Clamp(
(now - _blobsScaleLastTime) / float64(kBlobsScaleEnterDuration), (now - _blobsScaleLastTime) / float64(kBlobsScaleEnterDuration));
0.,
1.);
_blobsScaleEnter = _hideBlobs _blobsScaleEnter = _hideBlobs
? (1. - anim::linear(1., dt)) ? (1. - anim::linear(1., dt))
: anim::easeOutBack(1., dt); : anim::easeOutBack(1., dt);
@ -526,10 +524,8 @@ void CallMuteButton::init() {
: anim::interpolateF(radialShowFrom, radialShowTo, value); : anim::interpolateF(radialShowFrom, radialShowTo, value);
if (radialShowProgress != _radialShowProgress.current()) { if (radialShowProgress != _radialShowProgress.current()) {
_radialShowProgress = radialShowProgress; _radialShowProgress = radialShowProgress;
_blobs->setSwitchConnectingProgress(std::clamp( _blobs->setSwitchConnectingProgress(Clamp(
radialShowProgress / kBlobsWidgetPartAnimation, radialShowProgress / kBlobsWidgetPartAnimation));
0.,
1.));
} }
overridesColors(previous, type, value); overridesColors(previous, type, value);
@ -577,7 +573,7 @@ void CallMuteButton::init() {
r.arcLength = anim::interpolate( r.arcLength = anim::interpolate(
r.arcLength, r.arcLength,
-RadialState::kFull, -RadialState::kFull,
std::clamp(radialProgress, 0., 1.)); Clamp(radialProgress));
const auto opacity = (radialProgress > kOverlapProgressRadialHide) const auto opacity = (radialProgress > kOverlapProgressRadialHide)
? 0. ? 0.