mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-24 09:16:57 +00:00
Moved animation callback for shake effect to single place.
This commit is contained in:
parent
f433d6fbc9
commit
9ef0e5cf83
@ -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) {
|
||||
|
@ -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(
|
||||
|
39
Telegram/SourceFiles/ui/effects/shake_animation.cpp
Normal file
39
Telegram/SourceFiles/ui/effects/shake_animation.cpp
Normal file
@ -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<void(float64)> DefaultShakeCallback(Fn<void(int)> 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
|
14
Telegram/SourceFiles/ui/effects/shake_animation.h
Normal file
14
Telegram/SourceFiles/ui/effects/shake_animation.h
Normal file
@ -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<void(float64)> DefaultShakeCallback(Fn<void(int)> applyShift);
|
||||
|
||||
} // namespace Ui
|
@ -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
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 299548dcaafc3f75462c78565c3d2ad68a8f7623
|
||||
Subproject commit f69758da1906b204c156ea6ad254eacd61210a42
|
@ -1 +1 @@
|
||||
Subproject commit de731885163bc1b3fe3095413453777ee89a8561
|
||||
Subproject commit 0971b69ca90f1697ef81276d9820dcd6d26de4ac
|
@ -1 +1 @@
|
||||
Subproject commit cd4e9d378cc98f590f814332900ec33863ffb98c
|
||||
Subproject commit 66ca90c1b2c111fe8ae45453c7bf180af2593d8d
|
Loading…
Reference in New Issue
Block a user