mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Removed redundant code from VoiceRecordButton.
This commit is contained in:
parent
6ae15485ad
commit
ce1ae5ba12
2 changed files with 3 additions and 74 deletions
|
@ -16,8 +16,6 @@ namespace HistoryView::Controls {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kRecordingUpdateDelta = crl::time(100);
|
|
||||||
|
|
||||||
constexpr auto kSegmentsCount = 12;
|
constexpr auto kSegmentsCount = 12;
|
||||||
constexpr auto kMajorDegreeOffset = 360 / kSegmentsCount;
|
constexpr auto kMajorDegreeOffset = 360 / kSegmentsCount;
|
||||||
constexpr auto kSixtyDegrees = 60;
|
constexpr auto kSixtyDegrees = 60;
|
||||||
|
@ -196,7 +194,6 @@ private:
|
||||||
bool _wasFling = false;
|
bool _wasFling = false;
|
||||||
float64 _amplitude = 0.;
|
float64 _amplitude = 0.;
|
||||||
float64 _animateAmplitudeDiff = 0.;
|
float64 _animateAmplitudeDiff = 0.;
|
||||||
float64 _animateAmplitudeSlowDiff = 0.;
|
|
||||||
float64 _animateToAmplitude = 0.;
|
float64 _animateToAmplitude = 0.;
|
||||||
float64 _flingRadius = 0.;
|
float64 _flingRadius = 0.;
|
||||||
float64 _idleRadius = 0.;
|
float64 _idleRadius = 0.;
|
||||||
|
@ -204,7 +201,6 @@ private:
|
||||||
float64 _lastRadius = 0.;
|
float64 _lastRadius = 0.;
|
||||||
float64 _rotation = 0.;
|
float64 _rotation = 0.;
|
||||||
float64 _sineAngleMax = 0.;
|
float64 _sineAngleMax = 0.;
|
||||||
float64 _slowAmplitude = 0.;
|
|
||||||
float64 _waveAngle = 0.;
|
float64 _waveAngle = 0.;
|
||||||
float64 _waveDiff = 0.;
|
float64 _waveDiff = 0.;
|
||||||
|
|
||||||
|
@ -336,14 +332,11 @@ void Wave::setValue(float64 value) {
|
||||||
_animateToAmplitude = value;
|
_animateToAmplitude = value;
|
||||||
|
|
||||||
const auto amplitudeDelta = (_animateToAmplitude - _amplitude);
|
const auto amplitudeDelta = (_animateToAmplitude - _amplitude);
|
||||||
const auto amplitudeSlowDelta = (_animateToAmplitude - _slowAmplitude);
|
|
||||||
const auto factor = (_animateToAmplitude <= _amplitude)
|
const auto factor = (_animateToAmplitude <= _amplitude)
|
||||||
? kAmplitudeDiffFactorMax
|
? kAmplitudeDiffFactorMax
|
||||||
: _amplitudeDiffFactor;
|
: _amplitudeDiffFactor;
|
||||||
_animateAmplitudeDiff = amplitudeDelta
|
_animateAmplitudeDiff = amplitudeDelta
|
||||||
/ (kMinDivider + factor * _amplitudeDiffSpeed);
|
/ (kMinDivider + factor * _amplitudeDiffSpeed);
|
||||||
_animateAmplitudeSlowDiff = amplitudeSlowDelta
|
|
||||||
/ (kMinDivider + kAmplitudeDiffFactorMax * _amplitudeDiffSpeed);
|
|
||||||
|
|
||||||
const auto idle = value < 0.1;
|
const auto idle = value < 0.1;
|
||||||
if (_isIdle != idle && idle) {
|
if (_isIdle != idle && idle) {
|
||||||
|
@ -439,17 +432,6 @@ void Wave::tick(float64 circleRadius, crl::time lastUpdateTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_animateToAmplitude != _slowAmplitude) {
|
|
||||||
_slowAmplitude += _animateAmplitudeSlowDiff * dt;
|
|
||||||
if (std::abs(_slowAmplitude - _amplitude) > 0.2) {
|
|
||||||
_slowAmplitude = _amplitude + (_slowAmplitude > _amplitude ?
|
|
||||||
0.2 : -0.2);
|
|
||||||
}
|
|
||||||
ApplyTo(_slowAmplitude,
|
|
||||||
_animateToAmplitude,
|
|
||||||
_animateAmplitudeSlowDiff);
|
|
||||||
}
|
|
||||||
|
|
||||||
_idleRadius = circleRadius * kIdleRadiusFactor;
|
_idleRadius = circleRadius * kIdleRadiusFactor;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -589,14 +571,14 @@ VoiceRecordButton::VoiceRecordButton(
|
||||||
: AbstractButton(parent)
|
: AbstractButton(parent)
|
||||||
, _recordCircle(std::make_unique<RecordCircle>(
|
, _recordCircle(std::make_unique<RecordCircle>(
|
||||||
_recordAnimationTicked.events()))
|
_recordAnimationTicked.events()))
|
||||||
, _height(st::historyRecordLevelMaxRadius * 2)
|
, _center(st::historyRecordLevelMaxRadius)
|
||||||
, _center(_height / 2)
|
|
||||||
, _recordingAnimation([=](crl::time now) {
|
, _recordingAnimation([=](crl::time now) {
|
||||||
update();
|
update();
|
||||||
_recordAnimationTicked.fire_copy(now);
|
_recordAnimationTicked.fire_copy(now);
|
||||||
return true;
|
return true;
|
||||||
}) {
|
}) {
|
||||||
resize(_height, _height);
|
const auto h = st::historyRecordLevelMaxRadius * 2;
|
||||||
|
resize(h, h);
|
||||||
std::move(
|
std::move(
|
||||||
leaveWindowEventProducer
|
leaveWindowEventProducer
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
|
@ -612,22 +594,6 @@ void VoiceRecordButton::requestPaintLevel(quint16 level) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VoiceRecordButton::recordingAnimationCallback(crl::time now) {
|
|
||||||
const auto dt = anim::Disabled()
|
|
||||||
? 1.
|
|
||||||
: ((now - _recordingAnimation.started())
|
|
||||||
/ float64(kRecordingUpdateDelta));
|
|
||||||
if (dt >= 1.) {
|
|
||||||
_recordingLevel.finish();
|
|
||||||
} else {
|
|
||||||
_recordingLevel.update(dt, anim::sineInOut);
|
|
||||||
}
|
|
||||||
if (!anim::Disabled()) {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
return (dt < 1.);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoiceRecordButton::init() {
|
void VoiceRecordButton::init() {
|
||||||
const auto hasProgress = [](auto value) { return value != 0.; };
|
const auto hasProgress = [](auto value) { return value != 0.; };
|
||||||
|
|
||||||
|
@ -664,9 +630,7 @@ void VoiceRecordButton::init() {
|
||||||
setVisible(show);
|
setVisible(show);
|
||||||
setMouseTracking(show);
|
setMouseTracking(show);
|
||||||
if (!show) {
|
if (!show) {
|
||||||
_recordingLevel = anim::value();
|
|
||||||
_recordingAnimation.stop();
|
_recordingAnimation.stop();
|
||||||
_showingLifetime.destroy();
|
|
||||||
_showProgress = 0.;
|
_showProgress = 0.;
|
||||||
} else {
|
} else {
|
||||||
if (!_recordingAnimation.animating()) {
|
if (!_recordingAnimation.animating()) {
|
||||||
|
@ -714,33 +678,6 @@ bool VoiceRecordButton::inCircle(const QPoint &localPos) const {
|
||||||
return ((dx * dx + dy * dy) <= (radii * radii));
|
return ((dx * dx + dy * dy) <= (radii * radii));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoiceRecordButton::drawProgress(Painter &p) {
|
|
||||||
PainterHighQualityEnabler hq(p);
|
|
||||||
p.setPen(Qt::NoPen);
|
|
||||||
const auto color = anim::color(
|
|
||||||
st::historyRecordSignalColor,
|
|
||||||
st::historyRecordVoiceFgActive,
|
|
||||||
_colorProgress.current());
|
|
||||||
p.setBrush(color);
|
|
||||||
|
|
||||||
const auto progress = _showProgress.current();
|
|
||||||
|
|
||||||
const auto center = QPoint(_center, _center);
|
|
||||||
const int mainRadii = progress * st::historyRecordLevelMainRadius;
|
|
||||||
|
|
||||||
{
|
|
||||||
p.setOpacity(.5);
|
|
||||||
const auto min = progress * st::historyRecordLevelMinRadius;
|
|
||||||
const auto max = progress * st::historyRecordLevelMaxRadius;
|
|
||||||
const auto delta = std::min(_recordingLevel.current() / 0x4000, 1.);
|
|
||||||
const auto radii = qRound(min + (delta * (max - min)));
|
|
||||||
p.drawEllipse(center, radii, radii);
|
|
||||||
p.setOpacity(1.);
|
|
||||||
}
|
|
||||||
|
|
||||||
p.drawEllipse(center, mainRadii, mainRadii);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoiceRecordButton::requestPaintProgress(float64 progress) {
|
void VoiceRecordButton::requestPaintProgress(float64 progress) {
|
||||||
_showProgress = progress;
|
_showProgress = progress;
|
||||||
update();
|
update();
|
||||||
|
|
|
@ -33,26 +33,18 @@ public:
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
void drawProgress(Painter &p);
|
|
||||||
|
|
||||||
rpl::event_stream<crl::time> _recordAnimationTicked;
|
rpl::event_stream<crl::time> _recordAnimationTicked;
|
||||||
std::unique_ptr<RecordCircle> _recordCircle;
|
std::unique_ptr<RecordCircle> _recordCircle;
|
||||||
|
|
||||||
const int _height;
|
|
||||||
const int _center;
|
const int _center;
|
||||||
|
|
||||||
rpl::variable<float64> _showProgress = 0.;
|
rpl::variable<float64> _showProgress = 0.;
|
||||||
rpl::variable<float64> _colorProgress = 0.;
|
rpl::variable<float64> _colorProgress = 0.;
|
||||||
rpl::variable<bool> _inCircle = false;
|
rpl::variable<bool> _inCircle = false;
|
||||||
|
|
||||||
bool recordingAnimationCallback(crl::time now);
|
|
||||||
|
|
||||||
// This can animate for a very long time (like in music playing),
|
// This can animate for a very long time (like in music playing),
|
||||||
// so it should be a Basic, not a Simple animation.
|
// so it should be a Basic, not a Simple animation.
|
||||||
Ui::Animations::Basic _recordingAnimation;
|
Ui::Animations::Basic _recordingAnimation;
|
||||||
anim::value _recordingLevel;
|
|
||||||
|
|
||||||
rpl::lifetime _showingLifetime;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace HistoryView::Controls
|
} // namespace HistoryView::Controls
|
||||||
|
|
Loading…
Add table
Reference in a new issue