mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 08:04:08 +02:00
Slightly optimized paint in VoiceRecordBar.
This commit is contained in:
parent
ebe1fa7408
commit
43635f6e4b
2 changed files with 49 additions and 29 deletions
|
@ -59,7 +59,6 @@ VoiceRecordBar::VoiceRecordBar(
|
||||||
, _wrap(std::make_unique<Ui::RpWidget>(parent))
|
, _wrap(std::make_unique<Ui::RpWidget>(parent))
|
||||||
, _send(send)
|
, _send(send)
|
||||||
, _cancelFont(st::historyRecordFont)
|
, _cancelFont(st::historyRecordFont)
|
||||||
, _recordCancelWidth(_cancelFont->width(tr::lng_record_cancel(tr::now)))
|
|
||||||
, _recordingAnimation([=](crl::time now) {
|
, _recordingAnimation([=](crl::time now) {
|
||||||
return recordingAnimationCallback(now);
|
return recordingAnimationCallback(now);
|
||||||
}) {
|
}) {
|
||||||
|
@ -90,6 +89,18 @@ void VoiceRecordBar::updateControlsGeometry(QSize size) {
|
||||||
_cancelFont->width(FormatVoiceDuration(kMaxSamples)),
|
_cancelFont->width(FormatVoiceDuration(kMaxSamples)),
|
||||||
_redCircleRect.height());
|
_redCircleRect.height());
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const auto left = _durationRect.x()
|
||||||
|
+ _durationRect.width()
|
||||||
|
+ ((_send->width() - st::historyRecordVoice.width()) / 2);
|
||||||
|
const auto right = width() - _send->width();
|
||||||
|
const auto width = _cancelFont->width(tr::lng_record_cancel(tr::now));
|
||||||
|
_messageRect = QRect(
|
||||||
|
left + (right - left - width) / 2,
|
||||||
|
st::historyRecordTextTop,
|
||||||
|
width + st::historyRecordDurationSkip,
|
||||||
|
_cancelFont->height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoiceRecordBar::init() {
|
void VoiceRecordBar::init() {
|
||||||
|
@ -111,12 +122,23 @@ void VoiceRecordBar::init() {
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
paintRequest(
|
paintRequest(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=](const QRect &clip) {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
p.setOpacity(_showAnimation.value(1.));
|
if (_showAnimation.animating()) {
|
||||||
p.fillRect(rect(), st::historyComposeAreaBg);
|
p.setOpacity(_showAnimation.value(1.));
|
||||||
|
}
|
||||||
|
p.fillRect(clip, st::historyComposeAreaBg);
|
||||||
|
|
||||||
drawRecording(p, activeAnimationRatio());
|
if (clip.intersects(_messageRect)) {
|
||||||
|
// The message should be painted first to avoid flickering.
|
||||||
|
drawMessage(p, activeAnimationRatio());
|
||||||
|
}
|
||||||
|
if (clip.intersects(_redCircleRect)) {
|
||||||
|
drawRecording(p);
|
||||||
|
}
|
||||||
|
if (clip.intersects(_durationRect)) {
|
||||||
|
drawDuration(p);
|
||||||
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
_inField.changes(
|
_inField.changes(
|
||||||
|
@ -132,7 +154,7 @@ void VoiceRecordBar::activeAnimate(bool active) {
|
||||||
_activeAnimation.change(to, duration);
|
_activeAnimation.change(to, duration);
|
||||||
} else {
|
} else {
|
||||||
auto callback = [=] {
|
auto callback = [=] {
|
||||||
update();
|
update(_messageRect);
|
||||||
_send->requestPaintRecord(activeAnimationRatio());
|
_send->requestPaintRecord(activeAnimationRatio());
|
||||||
};
|
};
|
||||||
const auto from = active ? 0. : 1.;
|
const auto from = active ? 0. : 1.;
|
||||||
|
@ -264,40 +286,36 @@ void VoiceRecordBar::stopRecording(bool send) {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoiceRecordBar::drawRecording(Painter &p, float64 recordActive) {
|
void VoiceRecordBar::drawDuration(Painter &p) {
|
||||||
p.setPen(Qt::NoPen);
|
|
||||||
p.setBrush(st::historyRecordSignalColor);
|
|
||||||
|
|
||||||
{
|
|
||||||
PainterHighQualityEnabler hq(p);
|
|
||||||
const auto min = st::historyRecordSignalMin;
|
|
||||||
const auto max = st::historyRecordSignalMax;
|
|
||||||
const auto delta = std::min(_recordingLevel.current() / 0x4000, 1.);
|
|
||||||
const auto radii = qRound(min + (delta * (max - min)));
|
|
||||||
const auto center = _redCircleRect.center() + QPoint(1, 1);
|
|
||||||
p.drawEllipse(center, radii, radii);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto duration = FormatVoiceDuration(_recordingSamples);
|
const auto duration = FormatVoiceDuration(_recordingSamples);
|
||||||
p.setFont(_cancelFont);
|
p.setFont(_cancelFont);
|
||||||
p.setPen(st::historyRecordDurationFg);
|
p.setPen(st::historyRecordDurationFg);
|
||||||
|
|
||||||
p.fillRect(_durationRect, Qt::red);
|
|
||||||
p.drawText(_durationRect, style::al_left, duration);
|
p.drawText(_durationRect, style::al_left, duration);
|
||||||
|
}
|
||||||
|
|
||||||
const auto leftCancel = _durationRect.x()
|
void VoiceRecordBar::drawRecording(Painter &p) {
|
||||||
+ _durationRect.width()
|
PainterHighQualityEnabler hq(p);
|
||||||
+ ((_send->width() - st::historyRecordVoice.width()) / 2);
|
p.setPen(Qt::NoPen);
|
||||||
const auto rightCancel = width() - _send->width();
|
p.setBrush(st::historyRecordSignalColor);
|
||||||
|
|
||||||
|
const auto min = st::historyRecordSignalMin;
|
||||||
|
const auto max = st::historyRecordSignalMax;
|
||||||
|
const auto delta = std::min(_recordingLevel.current() / 0x4000, 1.);
|
||||||
|
const auto radii = qRound(min + (delta * (max - min)));
|
||||||
|
const auto center = _redCircleRect.center() + QPoint(1, 1);
|
||||||
|
p.drawEllipse(center, radii, radii);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoiceRecordBar::drawMessage(Painter &p, float64 recordActive) {
|
||||||
p.setPen(
|
p.setPen(
|
||||||
anim::pen(
|
anim::pen(
|
||||||
st::historyRecordCancel,
|
st::historyRecordCancel,
|
||||||
st::historyRecordCancelActive,
|
st::historyRecordCancelActive,
|
||||||
1. - recordActive));
|
1. - recordActive));
|
||||||
p.drawText(
|
p.drawText(
|
||||||
leftCancel + (rightCancel - leftCancel - _recordCancelWidth) / 2,
|
_messageRect.x(),
|
||||||
st::historyRecordTextTop + _cancelFont->ascent,
|
_messageRect.y() + _cancelFont->ascent,
|
||||||
tr::lng_record_cancel(tr::now));
|
tr::lng_record_cancel(tr::now));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,9 @@ private:
|
||||||
void recordUpdateCallback(QPoint globalPos);
|
void recordUpdateCallback(QPoint globalPos);
|
||||||
|
|
||||||
bool showRecordButton() const;
|
bool showRecordButton() const;
|
||||||
void drawRecording(Painter &p, float64 recordActive);
|
void drawDuration(Painter &p);
|
||||||
|
void drawRecording(Painter &p);
|
||||||
|
void drawMessage(Painter &p, float64 recordActive);
|
||||||
void updateOverStates(QPoint pos);
|
void updateOverStates(QPoint pos);
|
||||||
|
|
||||||
bool isTypeRecord() const;
|
bool isTypeRecord() const;
|
||||||
|
@ -80,13 +82,13 @@ private:
|
||||||
int _centerY = 0;
|
int _centerY = 0;
|
||||||
QRect _redCircleRect;
|
QRect _redCircleRect;
|
||||||
QRect _durationRect;
|
QRect _durationRect;
|
||||||
|
QRect _messageRect;
|
||||||
|
|
||||||
rpl::variable<bool> _recording = false;
|
rpl::variable<bool> _recording = false;
|
||||||
rpl::variable<bool> _inField = false;
|
rpl::variable<bool> _inField = false;
|
||||||
int _recordingSamples = 0;
|
int _recordingSamples = 0;
|
||||||
|
|
||||||
const style::font &_cancelFont;
|
const style::font &_cancelFont;
|
||||||
int _recordCancelWidth;
|
|
||||||
|
|
||||||
rpl::lifetime _recordingLifetime;
|
rpl::lifetime _recordingLifetime;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue