From 5897e357bfd6114ecede2711831b8c5e9d045fcb Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 30 Nov 2020 12:38:22 +0300 Subject: [PATCH] Added colors overriding for call settings button from mute button. --- ui/widgets/call_mute_button.cpp | 42 ++++++++++++++++++++++++++++++++- ui/widgets/call_mute_button.h | 8 +++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/ui/widgets/call_mute_button.cpp b/ui/widgets/call_mute_button.cpp index 73be479..f001baa 100644 --- a/ui/widgets/call_mute_button.cpp +++ b/ui/widgets/call_mute_button.cpp @@ -37,6 +37,9 @@ constexpr auto kGlowPaddingFactor = 1.2; constexpr auto kGlowMinScale = 0.6; constexpr auto kGlowAlpha = 150; +constexpr auto kOverrideColorBgAlpha = 76; +constexpr auto kOverrideColorRippleAlpha = 50; + constexpr auto kSwitchStateDuration = 120; auto MuteBlobs() -> std::array { @@ -111,6 +114,10 @@ bool IsConnecting(CallMuteButtonType type) { return (type == CallMuteButtonType::Connecting); } +bool IsInactive(CallMuteButtonType type) { + return IsConnecting(type) || (type == CallMuteButtonType::ForceMuted); +} + } // namespace class BlobsWidget final : public RpWidget { @@ -280,7 +287,7 @@ void CallMuteButton::init() { lifetime().make_state(_state.current().type); const auto glowColor = [=](CallMuteButtonType type) { - if (IsConnecting(type) || (type == CallMuteButtonType::ForceMuted)) { + if (IsInactive(type)) { return st::groupCallBg->c; } auto c = _colors.at(type)[0]; @@ -336,6 +343,8 @@ void CallMuteButton::init() { if (radialShowProgress != _radialShowProgress.current()) { _radialShowProgress = radialShowProgress; } + + overridesColors(previous, type, value); }; _switchAnimation.stop(); @@ -451,6 +460,37 @@ void CallMuteButton::lower() { _blobs->lower(); } +void CallMuteButton::overridesColors( + CallMuteButtonType fromType, + CallMuteButtonType toType, + float64 progress) { + const auto toInactive = IsInactive(toType); + const auto fromInactive = IsInactive(fromType); + if (toInactive && (progress == 1)) { + _colorOverrides.fire({ std::nullopt, std::nullopt }); + return; + } + auto from = _colors.at(fromType)[0]; + auto to = _colors.at(toType)[0]; + auto fromRipple = from; + auto toRipple = to; + if (!toInactive) { + toRipple.setAlpha(kOverrideColorRippleAlpha); + to.setAlpha(kOverrideColorBgAlpha); + } + if (!fromInactive) { + fromRipple.setAlpha(kOverrideColorRippleAlpha); + from.setAlpha(kOverrideColorBgAlpha); + } + const auto resultBg = anim::color(from, to, progress); + const auto resultRipple = anim::color(fromRipple, toRipple, progress); + _colorOverrides.fire({ resultBg, resultRipple }); +} + +rpl::producer CallMuteButton::colorOverrides() const { + return _colorOverrides.events(); +} + rpl::lifetime &CallMuteButton::lifetime() { return _blobs->lifetime(); } diff --git a/ui/widgets/call_mute_button.h b/ui/widgets/call_mute_button.h index 6d59e30..8f12d9a 100644 --- a/ui/widgets/call_mute_button.h +++ b/ui/widgets/call_mute_button.h @@ -55,11 +55,17 @@ public: void raise(); void lower(); + [[nodiscard]] rpl::producer colorOverrides() const; + [[nodiscard]] rpl::lifetime &lifetime(); private: void init(); void contentPaint(); + void overridesColors( + CallMuteButtonType fromType, + CallMuteButtonType toType, + float64 progress); rpl::variable _state; float _level = 0.; @@ -76,6 +82,8 @@ private: CrossLineAnimation _crossLineMuteAnimation; Animations::Simple _switchAnimation; + rpl::event_stream _colorOverrides; + }; } // namespace Ui