mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 07:33:52 +02:00
Show speaking animations in voice chat bar.
This commit is contained in:
parent
fe23ba086a
commit
7217d14f09
5 changed files with 158 additions and 20 deletions
|
@ -417,6 +417,7 @@ auto Row::generatePaintUserpicCallback() -> PaintRoundImageCallback {
|
||||||
return [=](Painter &p, int x, int y, int outerWidth, int size) mutable {
|
return [=](Painter &p, int x, int y, int outerWidth, int size) mutable {
|
||||||
if (_blobsAnimation) {
|
if (_blobsAnimation) {
|
||||||
const auto shift = QPointF(x + size / 2., y + size / 2.);
|
const auto shift = QPointF(x + size / 2., y + size / 2.);
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
p.translate(shift);
|
p.translate(shift);
|
||||||
_blobsAnimation->blobs.paint(p, st::groupCallMemberActiveStatus);
|
_blobsAnimation->blobs.paint(p, st::groupCallMemberActiveStatus);
|
||||||
p.translate(-shift);
|
p.translate(-shift);
|
||||||
|
|
|
@ -141,6 +141,7 @@ rpl::producer<Ui::GroupCallBarContent> GroupCallTracker::ContentByCall(
|
||||||
state->someUserpicsNotLoaded = false;
|
state->someUserpicsNotLoaded = false;
|
||||||
using User = Ui::GroupCallBarContent::User;
|
using User = Ui::GroupCallBarContent::User;
|
||||||
for (auto &userpic : state->userpics) {
|
for (auto &userpic : state->userpics) {
|
||||||
|
userpic.peer->loadUserpic();
|
||||||
const auto pic = userpic.peer->genUserpic(userpic.view, st.size);
|
const auto pic = userpic.peer->genUserpic(userpic.view, st.size);
|
||||||
userpic.uniqueKey = userpic.peer->userpicUniqueKey(userpic.view);
|
userpic.uniqueKey = userpic.peer->userpicUniqueKey(userpic.view);
|
||||||
state->current.users.push_back({
|
state->current.users.push_back({
|
||||||
|
|
|
@ -797,9 +797,11 @@ historyCommentsOpenOutSelected: icon {{ "history_comments_open", msgFileThumbLin
|
||||||
|
|
||||||
historySlowmodeCounterMargins: margins(0px, 0px, 10px, 0px);
|
historySlowmodeCounterMargins: margins(0px, 0px, 10px, 0px);
|
||||||
|
|
||||||
historyGroupCallUserpicSize: 36px;
|
historyGroupCallUserpicSize: 32px;
|
||||||
historyGroupCallUserpicShift: 12px;
|
historyGroupCallUserpicShift: 12px;
|
||||||
historyGroupCallUserpicStroke: 2px;
|
historyGroupCallUserpicStroke: 4px;
|
||||||
|
historyGroupCallBlobMinRadius: 23px;
|
||||||
|
historyGroupCallBlobMaxRadius: 25px;
|
||||||
|
|
||||||
largeEmojiSize: 36px;
|
largeEmojiSize: 36px;
|
||||||
largeEmojiOutline: 1px;
|
largeEmojiOutline: 1px;
|
||||||
|
|
|
@ -10,7 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/chat/message_bar.h"
|
#include "ui/chat/message_bar.h"
|
||||||
#include "ui/widgets/shadow.h"
|
#include "ui/widgets/shadow.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
|
#include "ui/paint/blobs.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
#include "base/openssl_help.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
#include "styles/style_calls.h"
|
#include "styles/style_calls.h"
|
||||||
#include "styles/style_info.h" // st::topBarArrowPadding, like TopBarWidget.
|
#include "styles/style_info.h" // st::topBarArrowPadding, like TopBarWidget.
|
||||||
|
@ -25,8 +27,66 @@ constexpr auto kDuration = 160;
|
||||||
constexpr auto kMaxUserpics = 4;
|
constexpr auto kMaxUserpics = 4;
|
||||||
constexpr auto kWideScale = 5;
|
constexpr auto kWideScale = 5;
|
||||||
|
|
||||||
|
constexpr auto kBlobsEnterDuration = crl::time(250);
|
||||||
|
constexpr auto kLevelDuration = 100. + 500. * 0.23;
|
||||||
|
constexpr auto kBlobScale = 0.605;
|
||||||
|
constexpr auto kMinorBlobFactor = 0.9f;
|
||||||
|
constexpr auto kUserpicMinScale = 0.8;
|
||||||
|
constexpr auto kMaxLevel = 1.;
|
||||||
|
constexpr auto kSendRandomLevelInterval = crl::time(100);
|
||||||
|
|
||||||
|
auto Blobs()->std::array<Ui::Paint::Blobs::BlobData, 2> {
|
||||||
|
return { {
|
||||||
|
{
|
||||||
|
.segmentsCount = 6,
|
||||||
|
.minScale = kBlobScale * kMinorBlobFactor,
|
||||||
|
.minRadius = st::historyGroupCallBlobMinRadius * kMinorBlobFactor,
|
||||||
|
.maxRadius = st::historyGroupCallBlobMaxRadius * kMinorBlobFactor,
|
||||||
|
.speedScale = 1.,
|
||||||
|
.alpha = .5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.segmentsCount = 8,
|
||||||
|
.minScale = kBlobScale,
|
||||||
|
.minRadius = (float)st::historyGroupCallBlobMinRadius,
|
||||||
|
.maxRadius = (float)st::historyGroupCallBlobMaxRadius,
|
||||||
|
.speedScale = 1.,
|
||||||
|
.alpha = .2,
|
||||||
|
},
|
||||||
|
} };
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
struct GroupCallBar::BlobsAnimation {
|
||||||
|
BlobsAnimation(
|
||||||
|
std::vector<Ui::Paint::Blobs::BlobData> blobDatas,
|
||||||
|
float levelDuration,
|
||||||
|
float maxLevel)
|
||||||
|
: blobs(std::move(blobDatas), levelDuration, maxLevel) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Ui::Paint::Blobs blobs;
|
||||||
|
crl::time lastTime = 0;
|
||||||
|
crl::time lastSpeakingUpdateTime = 0;
|
||||||
|
float64 enter = 0.;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GroupCallBar::Userpic {
|
||||||
|
User data;
|
||||||
|
std::pair<uint64, uint64> cacheKey;
|
||||||
|
crl::time speakingStarted = 0;
|
||||||
|
QImage cache;
|
||||||
|
Animations::Simple leftAnimation;
|
||||||
|
Animations::Simple shownAnimation;
|
||||||
|
std::unique_ptr<BlobsAnimation> blobsAnimation;
|
||||||
|
int left = 0;
|
||||||
|
bool positionInited = false;
|
||||||
|
bool topMost = false;
|
||||||
|
bool hiding = false;
|
||||||
|
bool cacheMasked = false;
|
||||||
|
};
|
||||||
|
|
||||||
GroupCallBar::GroupCallBar(
|
GroupCallBar::GroupCallBar(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
rpl::producer<GroupCallBarContent> content)
|
rpl::producer<GroupCallBarContent> content)
|
||||||
|
@ -36,7 +96,8 @@ GroupCallBar::GroupCallBar(
|
||||||
_inner.get(),
|
_inner.get(),
|
||||||
tr::lng_group_call_join(),
|
tr::lng_group_call_join(),
|
||||||
st::groupCallTopBarJoin))
|
st::groupCallTopBarJoin))
|
||||||
, _shadow(std::make_unique<PlainShadow>(_wrap.parentWidget())) {
|
, _shadow(std::make_unique<PlainShadow>(_wrap.parentWidget()))
|
||||||
|
, _randomSpeakingTimer([=] { sendRandomLevels(); }) {
|
||||||
_wrap.hide(anim::type::instant);
|
_wrap.hide(anim::type::instant);
|
||||||
_shadow->hide();
|
_shadow->hide();
|
||||||
|
|
||||||
|
@ -78,6 +139,28 @@ GroupCallBar::GroupCallBar(
|
||||||
_wrap.toggle(false, anim::type::normal);
|
_wrap.toggle(false, anim::type::normal);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
style::PaletteChanged(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
for (auto &userpic : _userpics) {
|
||||||
|
userpic.cache = QImage();
|
||||||
|
}
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
|
_speakingAnimation.init([=](crl::time now) {
|
||||||
|
//if (const auto &last = _speakingAnimationHideLastTime; (last > 0)
|
||||||
|
// && (now - last >= kBlobsEnterDuration)) {
|
||||||
|
// _speakingAnimation.stop();
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
for (auto &userpic : _userpics) {
|
||||||
|
if (const auto blobs = userpic.blobsAnimation.get()) {
|
||||||
|
blobs->blobs.updateLevel(now - blobs->lastTime);
|
||||||
|
blobs->lastTime = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateUserpics();
|
||||||
|
});
|
||||||
|
|
||||||
setupInner();
|
setupInner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,17 +251,30 @@ void GroupCallBar::paintUserpics(Painter &p) {
|
||||||
validateUserpicCache(userpic);
|
validateUserpicCache(userpic);
|
||||||
p.setOpacity(shown);
|
p.setOpacity(shown);
|
||||||
const auto left = middle + userpic.leftAnimation.value(userpic.left);
|
const auto left = middle + userpic.leftAnimation.value(userpic.left);
|
||||||
if (userpic.data.speaking) {
|
const auto blobs = userpic.blobsAnimation.get();
|
||||||
//p.fillRect(left, top, size, size, QColor(255, 128, 128));
|
const auto shownScale = 0.5 + shown / 2.;
|
||||||
|
const auto &minScale = kUserpicMinScale;
|
||||||
|
const auto scale = shownScale * (blobs
|
||||||
|
? (minScale + (1. - minScale) * blobs->blobs.currentLevel())
|
||||||
|
: 1.);
|
||||||
|
if (blobs) {
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
|
||||||
|
const auto shift = QPointF(left + size / 2., top + size / 2.);
|
||||||
|
p.translate(shift);
|
||||||
|
blobs->blobs.paint(p, st::windowActiveTextFg);
|
||||||
|
p.translate(-shift);
|
||||||
|
p.setOpacity(1.);
|
||||||
}
|
}
|
||||||
if (shown == 1.) {
|
if (std::abs(scale - 1.) < 0.001) {
|
||||||
const auto skip = ((kWideScale - 1) / 2) * size * factor;
|
const auto skip = ((kWideScale - 1) / 2) * size * factor;
|
||||||
p.drawImage(
|
p.drawImage(
|
||||||
QRect(left, top, size, size),
|
QRect(left, top, size, size),
|
||||||
userpic.cache,
|
userpic.cache,
|
||||||
QRect(skip, skip, size * factor, size * factor));
|
QRect(skip, skip, size * factor, size * factor));
|
||||||
} else {
|
} else {
|
||||||
const auto scale = 0.5 + shown / 2.;
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
|
||||||
auto target = QRect(
|
auto target = QRect(
|
||||||
left + (1 - kWideScale) / 2 * size,
|
left + (1 - kWideScale) / 2 * size,
|
||||||
top + (1 - kWideScale) / 2 * size,
|
top + (1 - kWideScale) / 2 * size,
|
||||||
|
@ -215,6 +311,26 @@ bool GroupCallBar::needUserpicCacheRefresh(Userpic &userpic) {
|
||||||
return !userpic.leftAnimation.animating();
|
return !userpic.leftAnimation.animating();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GroupCallBar::ensureBlobsAnimation(Userpic &userpic) {
|
||||||
|
if (userpic.blobsAnimation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
userpic.blobsAnimation = std::make_unique<BlobsAnimation>(
|
||||||
|
Blobs() | ranges::to_vector,
|
||||||
|
kLevelDuration,
|
||||||
|
kMaxLevel);
|
||||||
|
userpic.blobsAnimation->lastTime = crl::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupCallBar::sendRandomLevels() {
|
||||||
|
for (auto &userpic : _userpics) {
|
||||||
|
if (const auto blobs = userpic.blobsAnimation.get()) {
|
||||||
|
const auto value = 30 + (openssl::RandomValue<uint32>() % 70);
|
||||||
|
userpic.blobsAnimation->blobs.setLevel(float64(value) / 100.);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GroupCallBar::validateUserpicCache(Userpic &userpic) {
|
void GroupCallBar::validateUserpicCache(Userpic &userpic) {
|
||||||
if (!needUserpicCacheRefresh(userpic)) {
|
if (!needUserpicCacheRefresh(userpic)) {
|
||||||
return;
|
return;
|
||||||
|
@ -248,7 +364,6 @@ void GroupCallBar::validateUserpicCache(Userpic &userpic) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCallBar::updateControlsGeometry(QRect wrapGeometry) {
|
void GroupCallBar::updateControlsGeometry(QRect wrapGeometry) {
|
||||||
_inner->resizeToWidth(wrapGeometry.width());
|
|
||||||
const auto hidden = _wrap.isHidden() || !wrapGeometry.height();
|
const auto hidden = _wrap.isHidden() || !wrapGeometry.height();
|
||||||
if (_shadow->isHidden() != hidden) {
|
if (_shadow->isHidden() != hidden) {
|
||||||
_shadow->setVisible(!hidden);
|
_shadow->setVisible(!hidden);
|
||||||
|
@ -308,8 +423,15 @@ void GroupCallBar::updateUserpicsFromContent() {
|
||||||
const auto userpicsBegin = begin(_userpics);
|
const auto userpicsBegin = begin(_userpics);
|
||||||
const auto userpicsEnd = end(_userpics);
|
const auto userpicsEnd = end(_userpics);
|
||||||
auto markedTopMost = userpicsEnd;
|
auto markedTopMost = userpicsEnd;
|
||||||
|
auto hasBlobs = false;
|
||||||
for (auto i = userpicsBegin; i != userpicsEnd; ++i) {
|
for (auto i = userpicsBegin; i != userpicsEnd; ++i) {
|
||||||
auto &userpic = *i;
|
auto &userpic = *i;
|
||||||
|
if (userpic.data.speaking) {
|
||||||
|
ensureBlobsAnimation(userpic);
|
||||||
|
hasBlobs = true;
|
||||||
|
} else {
|
||||||
|
userpic.blobsAnimation = nullptr;
|
||||||
|
}
|
||||||
if (userpic.topMost) {
|
if (userpic.topMost) {
|
||||||
toggleUserpic(userpic, false);
|
toggleUserpic(userpic, false);
|
||||||
userpic.topMost = false;
|
userpic.topMost = false;
|
||||||
|
@ -323,6 +445,21 @@ void GroupCallBar::updateUserpicsFromContent() {
|
||||||
std::rotate(userpicsBegin, markedTopMost, markedTopMost + 1);
|
std::rotate(userpicsBegin, markedTopMost, markedTopMost + 1);
|
||||||
}
|
}
|
||||||
updateUserpicsPositions();
|
updateUserpicsPositions();
|
||||||
|
|
||||||
|
if (!hasBlobs) {
|
||||||
|
_randomSpeakingTimer.cancel();
|
||||||
|
_speakingAnimation.stop();
|
||||||
|
} else if (!_randomSpeakingTimer.isActive()) {
|
||||||
|
_randomSpeakingTimer.callEach(kSendRandomLevelInterval);
|
||||||
|
_speakingAnimation.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_wrap.isHidden()) {
|
||||||
|
for (auto &userpic : _userpics) {
|
||||||
|
userpic.shownAnimation.stop();
|
||||||
|
userpic.leftAnimation.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCallBar::toggleUserpic(Userpic &userpic, bool shown) {
|
void GroupCallBar::toggleUserpic(Userpic &userpic, bool shown) {
|
||||||
|
@ -408,6 +545,7 @@ void GroupCallBar::move(int x, int y) {
|
||||||
|
|
||||||
void GroupCallBar::resizeToWidth(int width) {
|
void GroupCallBar::resizeToWidth(int width) {
|
||||||
_wrap.entity()->resizeToWidth(width);
|
_wrap.entity()->resizeToWidth(width);
|
||||||
|
_inner->resizeToWidth(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GroupCallBar::height() const {
|
int GroupCallBar::height() const {
|
||||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "ui/effects/animations.h"
|
#include "ui/effects/animations.h"
|
||||||
#include "base/object_ptr.h"
|
#include "base/object_ptr.h"
|
||||||
|
#include "base/timer.h"
|
||||||
|
|
||||||
class Painter;
|
class Painter;
|
||||||
|
|
||||||
|
@ -57,18 +58,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using User = GroupCallBarContent::User;
|
using User = GroupCallBarContent::User;
|
||||||
struct Userpic {
|
struct BlobsAnimation;
|
||||||
User data;
|
struct Userpic;
|
||||||
std::pair<uint64, uint64> cacheKey;
|
|
||||||
QImage cache;
|
|
||||||
Animations::Simple leftAnimation;
|
|
||||||
Animations::Simple shownAnimation;
|
|
||||||
int left = 0;
|
|
||||||
bool positionInited = false;
|
|
||||||
bool topMost = false;
|
|
||||||
bool hiding = false;
|
|
||||||
bool cacheMasked = false;
|
|
||||||
};
|
|
||||||
void updateShadowGeometry(QRect wrapGeometry);
|
void updateShadowGeometry(QRect wrapGeometry);
|
||||||
void updateControlsGeometry(QRect wrapGeometry);
|
void updateControlsGeometry(QRect wrapGeometry);
|
||||||
void updateUserpicsFromContent();
|
void updateUserpicsFromContent();
|
||||||
|
@ -81,6 +73,8 @@ private:
|
||||||
void updateUserpicsPositions();
|
void updateUserpicsPositions();
|
||||||
void validateUserpicCache(Userpic &userpic);
|
void validateUserpicCache(Userpic &userpic);
|
||||||
[[nodiscard]] bool needUserpicCacheRefresh(Userpic &userpic);
|
[[nodiscard]] bool needUserpicCacheRefresh(Userpic &userpic);
|
||||||
|
void ensureBlobsAnimation(Userpic &userpic);
|
||||||
|
void sendRandomLevels();
|
||||||
|
|
||||||
SlideWrap<> _wrap;
|
SlideWrap<> _wrap;
|
||||||
not_null<RpWidget*> _inner;
|
not_null<RpWidget*> _inner;
|
||||||
|
@ -89,6 +83,8 @@ private:
|
||||||
rpl::event_stream<> _barClicks;
|
rpl::event_stream<> _barClicks;
|
||||||
Fn<QRect(QRect)> _shadowGeometryPostprocess;
|
Fn<QRect(QRect)> _shadowGeometryPostprocess;
|
||||||
std::vector<Userpic> _userpics;
|
std::vector<Userpic> _userpics;
|
||||||
|
base::Timer _randomSpeakingTimer;
|
||||||
|
Ui::Animations::Basic _speakingAnimation;
|
||||||
int _maxUserpicsWidth = 0;
|
int _maxUserpicsWidth = 0;
|
||||||
bool _shouldBeShown = false;
|
bool _shouldBeShown = false;
|
||||||
bool _forceHidden = false;
|
bool _forceHidden = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue