Replaced raw radius values of Blob with struct.
This commit is contained in:
parent
5f44304a30
commit
5b0e499932
5 changed files with 62 additions and 41 deletions
|
|
@ -105,9 +105,9 @@ void BlobBezier::generateBlob() {
|
||||||
|
|
||||||
void BlobBezier::generateBlob(float &radius, float &angle, int i) {
|
void BlobBezier::generateBlob(float &radius, float &angle, int i) {
|
||||||
const auto angleDiff = _segmentAngle * 0.05;
|
const auto angleDiff = _segmentAngle * 0.05;
|
||||||
const auto radDiff = _maxRadius - _minRadius;
|
const auto radDiff = _radiuses.max - _radiuses.min;
|
||||||
|
|
||||||
radius = _minRadius + std::abs(RandomAdditional()) * radDiff;
|
radius = _radiuses.min + std::abs(RandomAdditional()) * radDiff;
|
||||||
angle = _segmentAngle * i + RandomAdditional() * angleDiff;
|
angle = _segmentAngle * i + RandomAdditional() * angleDiff;
|
||||||
_segments[i].speed = 0.017 + 0.003 * std::abs(RandomAdditional());
|
_segments[i].speed = 0.017 + 0.003 * std::abs(RandomAdditional());
|
||||||
}
|
}
|
||||||
|
|
@ -127,12 +127,12 @@ void BlobBezier::update(float level, float speedScale) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlobBezier::setMinRadius(float value) {
|
void BlobBezier::setRadiuses(Radiuses values) {
|
||||||
_minRadius = value;
|
_radiuses = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlobBezier::setMaxRadius(float value) {
|
BlobBezier::Radiuses BlobBezier::radiuses() const {
|
||||||
_maxRadius = value;
|
return _radiuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Ui::Paint
|
} // namespace Ui::Paint
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,15 @@ namespace Ui::Paint {
|
||||||
|
|
||||||
class BlobBezier final {
|
class BlobBezier final {
|
||||||
public:
|
public:
|
||||||
|
struct Radiuses {
|
||||||
|
float min = 0.;
|
||||||
|
float max = 0.;
|
||||||
|
|
||||||
|
inline bool operator==(const Radiuses &other) const {
|
||||||
|
return (min == other.min) && (max == other.max);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
BlobBezier(int n, float minScale, float minSpeed = 0, float maxSpeed = 0);
|
BlobBezier(int n, float minScale, float minSpeed = 0, float maxSpeed = 0);
|
||||||
|
|
||||||
void paint(Painter &p, const QBrush &brush);
|
void paint(Painter &p, const QBrush &brush);
|
||||||
|
|
@ -21,6 +30,9 @@ public:
|
||||||
void setMinRadius(float value);
|
void setMinRadius(float value);
|
||||||
void setMaxRadius(float value);
|
void setMaxRadius(float value);
|
||||||
|
|
||||||
|
void setRadiuses(Radiuses values);
|
||||||
|
Radiuses radiuses() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Segment {
|
struct Segment {
|
||||||
float radius = 0.;
|
float radius = 0.;
|
||||||
|
|
@ -44,8 +56,7 @@ private:
|
||||||
std::vector<Segment> _segments;
|
std::vector<Segment> _segments;
|
||||||
|
|
||||||
float64 _scale = 0;
|
float64 _scale = 0;
|
||||||
float _minRadius = 0.;
|
Radiuses _radiuses;
|
||||||
float _maxRadius = 0.;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,7 @@ Blobs::Blobs(
|
||||||
void Blobs::init() {
|
void Blobs::init() {
|
||||||
for (const auto &data : _blobDatas) {
|
for (const auto &data : _blobDatas) {
|
||||||
auto blob = Paint::BlobBezier(data.segmentsCount, data.minScale);
|
auto blob = Paint::BlobBezier(data.segmentsCount, data.minScale);
|
||||||
blob.setMinRadius(data.minRadius);
|
blob.setRadiuses({ data.minRadius, data.maxRadius });
|
||||||
blob.setMaxRadius(data.maxRadius);
|
|
||||||
blob.generateBlob();
|
blob.generateBlob();
|
||||||
_blobs.push_back(std::move(blob));
|
_blobs.push_back(std::move(blob));
|
||||||
}
|
}
|
||||||
|
|
@ -45,22 +44,22 @@ int Blobs::size() const {
|
||||||
return _blobs.size();
|
return _blobs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Blobs::setRadiusAt(
|
void Blobs::setRadiusesAt(
|
||||||
rpl::producer<float> &&radius,
|
rpl::producer<BlobBezier::Radiuses> &&radiuses,
|
||||||
int index,
|
int index) {
|
||||||
bool isMax) {
|
|
||||||
Expects(index >= 0 && index < size());
|
Expects(index >= 0 && index < size());
|
||||||
std::move(
|
std::move(
|
||||||
radius
|
radiuses
|
||||||
) | rpl::start_with_next([=](float r) {
|
) | rpl::start_with_next([=](BlobBezier::Radiuses r) {
|
||||||
if (isMax) {
|
_blobs[index].setRadiuses(std::move(r));
|
||||||
_blobs[index].setMaxRadius(r);
|
|
||||||
} else {
|
|
||||||
_blobs[index].setMinRadius(r);
|
|
||||||
}
|
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BlobBezier::Radiuses Blobs::radiusesAt(int index) {
|
||||||
|
Expects(index >= 0 && index < size());
|
||||||
|
return _blobs[index].radiuses();
|
||||||
|
}
|
||||||
|
|
||||||
void Blobs::setLevel(float value) {
|
void Blobs::setLevel(float value) {
|
||||||
const auto to = std::min(_maxLevel, value) / _maxLevel;
|
const auto to = std::min(_maxLevel, value) / _maxLevel;
|
||||||
_levelValue.start(to);
|
_levelValue.start(to);
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,11 @@ public:
|
||||||
float levelDuration,
|
float levelDuration,
|
||||||
float maxLevel);
|
float maxLevel);
|
||||||
|
|
||||||
void setRadiusAt(rpl::producer<float> &&radius, int index, bool isMax);
|
void setRadiusesAt(
|
||||||
|
rpl::producer<BlobBezier::Radiuses> &&radiuses,
|
||||||
|
int index);
|
||||||
|
BlobBezier::Radiuses radiusesAt(int index);
|
||||||
|
|
||||||
void setLevel(float value);
|
void setLevel(float value);
|
||||||
void paint(Painter &p, const QBrush &brush);
|
void paint(Painter &p, const QBrush &brush);
|
||||||
void updateLevel(crl::time dt);
|
void updateLevel(crl::time dt);
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ namespace Ui {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using Radiuses = Paint::BlobBezier::Radiuses;
|
||||||
|
|
||||||
constexpr auto kMaxLevel = 1.;
|
constexpr auto kMaxLevel = 1.;
|
||||||
|
|
||||||
constexpr auto kLevelDuration = 100. + 500. * 0.33;
|
constexpr auto kLevelDuration = 100. + 500. * 0.33;
|
||||||
|
|
@ -125,12 +127,13 @@ bool IsInactive(CallMuteButtonType type) {
|
||||||
|
|
||||||
class BlobsWidget final : public RpWidget {
|
class BlobsWidget final : public RpWidget {
|
||||||
public:
|
public:
|
||||||
BlobsWidget(not_null<RpWidget*> parent);
|
BlobsWidget(
|
||||||
|
not_null<RpWidget*> parent,
|
||||||
|
rpl::producer<bool> &&hideBlobs);
|
||||||
|
|
||||||
void setLevel(float level);
|
void setLevel(float level);
|
||||||
void setBlobBrush(QBrush brush);
|
void setBlobBrush(QBrush brush);
|
||||||
void setGlowBrush(QBrush brush);
|
void setGlowBrush(QBrush brush);
|
||||||
void setMainRadius(rpl::producer<float> &&radius);
|
|
||||||
|
|
||||||
[[nodiscard]] QRect innerRect() const;
|
[[nodiscard]] QRect innerRect() const;
|
||||||
|
|
||||||
|
|
@ -150,13 +153,27 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BlobsWidget::BlobsWidget(not_null<RpWidget*> parent)
|
BlobsWidget::BlobsWidget(
|
||||||
|
not_null<RpWidget*> parent,
|
||||||
|
rpl::producer<bool> &&hideBlobs)
|
||||||
: RpWidget(parent)
|
: RpWidget(parent)
|
||||||
, _blobs(MuteBlobs() | ranges::to_vector, kLevelDuration, kMaxLevel)
|
, _blobs(MuteBlobs() | ranges::to_vector, kLevelDuration, kMaxLevel)
|
||||||
, _blobBrush(Qt::transparent)
|
, _blobBrush(Qt::transparent)
|
||||||
, _glowBrush(Qt::transparent)
|
, _glowBrush(Qt::transparent)
|
||||||
, _blobsLastTime(crl::now()) {
|
, _blobsLastTime(crl::now()) {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
for (auto i = 0; i < _blobs.size(); i++) {
|
||||||
|
const auto radiuses = _blobs.radiusesAt(i);
|
||||||
|
auto radiusesChange = rpl::duplicate(
|
||||||
|
hideBlobs
|
||||||
|
) | rpl::map([=](bool hide) -> Radiuses {
|
||||||
|
return hide
|
||||||
|
? Radiuses{ radiuses.min, radiuses.min }
|
||||||
|
: radiuses;
|
||||||
|
}) | rpl::distinct_until_changed();
|
||||||
|
_blobs.setRadiusesAt(std::move(radiusesChange), i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlobsWidget::init() {
|
void BlobsWidget::init() {
|
||||||
|
|
@ -244,15 +261,16 @@ void BlobsWidget::setLevel(float level) {
|
||||||
_blobs.setLevel(level);
|
_blobs.setLevel(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlobsWidget::setMainRadius(rpl::producer<float> &&radius) {
|
|
||||||
_blobs.setRadiusAt(std::move(radius), 0, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
CallMuteButton::CallMuteButton(
|
CallMuteButton::CallMuteButton(
|
||||||
not_null<RpWidget*> parent,
|
not_null<RpWidget*> parent,
|
||||||
CallMuteButtonState initial)
|
CallMuteButtonState initial)
|
||||||
: _state(initial)
|
: _state(initial)
|
||||||
, _blobs(base::make_unique_q<BlobsWidget>(parent))
|
, _blobs(base::make_unique_q<BlobsWidget>(
|
||||||
|
parent,
|
||||||
|
_state.value(
|
||||||
|
) | rpl::map([](const CallMuteButtonState &state) {
|
||||||
|
return IsConnecting(state.type);
|
||||||
|
})))
|
||||||
, _content(parent, st::callMuteButtonActive, &st::callMuteButtonMuted)
|
, _content(parent, st::callMuteButtonActive, &st::callMuteButtonMuted)
|
||||||
, _radial(nullptr)
|
, _radial(nullptr)
|
||||||
, _colors(Colors())
|
, _colors(Colors())
|
||||||
|
|
@ -387,17 +405,6 @@ void CallMuteButton::init() {
|
||||||
icon.height());
|
icon.height());
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
// Main blob radius.
|
|
||||||
{
|
|
||||||
auto radius = _state.value(
|
|
||||||
) | rpl::map([](const CallMuteButtonState &state) -> float {
|
|
||||||
return (IsConnecting(state.type)
|
|
||||||
? st::callMuteMainBlobMinRadius
|
|
||||||
: st::callMuteMainBlobMaxRadius) * kMainRadiusFactor;
|
|
||||||
}) | rpl::distinct_until_changed();
|
|
||||||
_blobs->setMainRadius(std::move(radius));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Paint.
|
// Paint.
|
||||||
auto filterCallback = [=](not_null<QEvent*> e) {
|
auto filterCallback = [=](not_null<QEvent*> e) {
|
||||||
if (e->type() != QEvent::Paint) {
|
if (e->type() != QEvent::Paint) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue