diff --git a/Telegram/SourceFiles/statistics/widgets/chart_lines_filter_widget.cpp b/Telegram/SourceFiles/statistics/widgets/chart_lines_filter_widget.cpp index 8098e24fcd..a6dfa45c23 100644 --- a/Telegram/SourceFiles/statistics/widgets/chart_lines_filter_widget.cpp +++ b/Telegram/SourceFiles/statistics/widgets/chart_lines_filter_widget.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/abstract_button.h" #include "ui/effects/animations.h" +#include "ui/effects/shake_animation.h" #include "ui/painter.h" #include "ui/rect.h" #include "styles/style_basic.h" @@ -16,9 +17,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_widgets.h" namespace Statistic { -namespace { -constexpr auto kShiftDuration = crl::time(300); -} // namespace class ChartLinesFilterWidget::FlatCheckbox final : public Ui::AbstractButton { public: @@ -83,7 +81,7 @@ void ChartLinesFilterWidget::FlatCheckbox::setChecked( } else { const auto from = value ? 0. : 1.; const auto to = value ? 1. : 0.; - _animation.start([=] { update(); }, from, to, kShiftDuration); + _animation.start([=] { update(); }, from, to, st::shakeDuration); } } @@ -95,30 +93,10 @@ void ChartLinesFilterWidget::FlatCheckbox::shake() { if (_shake.animation.animating()) { return; } - constexpr auto kShiftProgress = 6; - constexpr auto kSegmentsCount = 5; - const auto refresh = [=] { - const auto fullProgress = _shake.animation.value(1.) * kShiftProgress; - const auto segment = std::clamp( - int(std::floor(fullProgress)), - 0, - kSegmentsCount); - const auto part = fullProgress - segment; - const auto from = (segment == 0) - ? 0. - : (segment == 1 || segment == 3 || segment == 5) - ? 1. - : -1.; - const auto to = (segment == 0 || segment == 2 || segment == 4) - ? 1. - : (segment == 1 || segment == 3) - ? -1. - : 0.; - const auto shift = from * (1. - part) + to * part; - _shake.shift = int(base::SafeRound(shift * st::shakeShift)); + _shake.animation.start(Ui::DefaultShakeCallback([=](int shift) { + _shake.shift = shift; update(); - }; - _shake.animation.start(refresh, 0., 1., kShiftDuration); + }), 0., 1., st::shakeDuration); } void ChartLinesFilterWidget::FlatCheckbox::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/ui/controls/call_mute_button.cpp b/Telegram/SourceFiles/ui/controls/call_mute_button.cpp index 64be6e5c29..b913f34281 100644 --- a/Telegram/SourceFiles/ui/controls/call_mute_button.cpp +++ b/Telegram/SourceFiles/ui/controls/call_mute_button.cpp @@ -8,6 +8,7 @@ #include "base/flat_map.h" #include "ui/abstract_button.h" +#include "ui/effects/shake_animation.h" #include "ui/paint/blobs.h" #include "ui/painter.h" #include "ui/power_saving.h" @@ -48,7 +49,6 @@ constexpr auto kGlowAlpha = 150; constexpr auto kOverrideColorBgAlpha = 76; constexpr auto kOverrideColorRippleAlpha = 50; -constexpr auto kShiftDuration = crl::time(300); constexpr auto kSwitchStateDuration = crl::time(120); constexpr auto kSwitchLabelDuration = crl::time(180); @@ -996,29 +996,10 @@ void CallMuteButton::shake() { if (_shakeAnimation.animating()) { return; } - const auto update = [=] { - const auto fullProgress = _shakeAnimation.value(1.) * 6; - const auto segment = std::clamp(int(std::floor(fullProgress)), 0, 5); - const auto part = fullProgress - segment; - const auto from = (segment == 0) - ? 0. - : (segment == 1 || segment == 3 || segment == 5) - ? 1. - : -1.; - const auto to = (segment == 0 || segment == 2 || segment == 4) - ? 1. - : (segment == 1 || segment == 3) - ? -1. - : 0.; - const auto shift = from * (1. - part) + to * part; - _labelShakeShift = int(base::SafeRound(shift * st::shakeShift)); + _shakeAnimation.start(DefaultShakeCallback([=](int shift) { + _labelShakeShift = shift; updateLabelsGeometry(); - }; - _shakeAnimation.start( - update, - 0., - 1., - kShiftDuration); + }), 0., 1., st::shakeDuration); } CallMuteButton::HandleMouseState CallMuteButton::HandleMouseStateFromType( diff --git a/Telegram/SourceFiles/ui/effects/shake_animation.cpp b/Telegram/SourceFiles/ui/effects/shake_animation.cpp new file mode 100644 index 0000000000..38fbd6f01a --- /dev/null +++ b/Telegram/SourceFiles/ui/effects/shake_animation.cpp @@ -0,0 +1,39 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "ui/effects/shake_animation.h" + +#include "styles/style_basic.h" + +namespace Ui { + +Fn DefaultShakeCallback(Fn applyShift) { + constexpr auto kShiftProgress = 6; + constexpr auto kSegmentsCount = 5; + return [=, applyShift = std::move(applyShift)](float64 value) { + const auto fullProgress = value * kShiftProgress; + const auto segment = std::clamp( + int(std::floor(fullProgress)), + 0, + kSegmentsCount); + const auto part = fullProgress - segment; + const auto from = (segment == 0) + ? 0. + : (segment == 1 || segment == 3 || segment == 5) + ? 1. + : -1.; + const auto to = (segment == 0 || segment == 2 || segment == 4) + ? 1. + : (segment == 1 || segment == 3) + ? -1. + : 0.; + const auto shift = from * (1. - part) + to * part; + applyShift(int(base::SafeRound(shift * st::shakeShift))); + }; +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/effects/shake_animation.h b/Telegram/SourceFiles/ui/effects/shake_animation.h new file mode 100644 index 0000000000..d2e5cf0676 --- /dev/null +++ b/Telegram/SourceFiles/ui/effects/shake_animation.h @@ -0,0 +1,14 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Ui { + +Fn DefaultShakeCallback(Fn applyShift); + +} // namespace Ui diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index c1f62e06c1..40c38c6851 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -333,6 +333,8 @@ PRIVATE ui/effects/round_checkbox.h ui/effects/scroll_content_shadow.cpp ui/effects/scroll_content_shadow.h + ui/effects/shake_animation.cpp + ui/effects/shake_animation.h ui/effects/snowflakes.cpp ui/effects/snowflakes.h ui/effects/toggle_arrow.cpp diff --git a/Telegram/lib_base b/Telegram/lib_base index 299548dcaa..f69758da19 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit 299548dcaafc3f75462c78565c3d2ad68a8f7623 +Subproject commit f69758da1906b204c156ea6ad254eacd61210a42 diff --git a/Telegram/lib_storage b/Telegram/lib_storage index de73188516..0971b69ca9 160000 --- a/Telegram/lib_storage +++ b/Telegram/lib_storage @@ -1 +1 @@ -Subproject commit de731885163bc1b3fe3095413453777ee89a8561 +Subproject commit 0971b69ca90f1697ef81276d9820dcd6d26de4ac diff --git a/Telegram/lib_ui b/Telegram/lib_ui index cd4e9d378c..66ca90c1b2 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit cd4e9d378cc98f590f814332900ec33863ffb98c +Subproject commit 66ca90c1b2c111fe8ae45453c7bf180af2593d8d