Added ability to change blob radius.
This commit is contained in:
parent
c9f003546a
commit
0018276c5f
4 changed files with 35 additions and 5 deletions
|
|
@ -127,10 +127,12 @@ void BlobBezier::update(float level, float speedScale) {
|
|||
}
|
||||
}
|
||||
|
||||
void BlobBezier::setRadius(float min, float max) {
|
||||
_minRadius = std::min(min, max);
|
||||
_maxRadius = std::max(min, max);
|
||||
generateBlob();
|
||||
void BlobBezier::setMinRadius(float value) {
|
||||
_minRadius = value;
|
||||
}
|
||||
|
||||
void BlobBezier::setMaxRadius(float value) {
|
||||
_maxRadius = value;
|
||||
}
|
||||
|
||||
} // namespace Ui::Paint
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ public:
|
|||
void generateBlob();
|
||||
|
||||
void setRadius(float min, float max);
|
||||
void setMinRadius(float value);
|
||||
void setMaxRadius(float value);
|
||||
|
||||
private:
|
||||
void generateBlob(
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ Blobs::Blobs(
|
|||
void Blobs::init() {
|
||||
for (const auto &data : _blobDatas) {
|
||||
auto blob = Paint::BlobBezier(data.segmentsCount, data.minScale);
|
||||
blob.setRadius(data.minRadius, data.maxRadius);
|
||||
blob.setMinRadius(data.minRadius);
|
||||
blob.setMaxRadius(data.maxRadius);
|
||||
blob.generateBlob();
|
||||
_blobs.push_back(std::move(blob));
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +41,26 @@ float Blobs::maxRadius() const {
|
|||
return maxOfRadiuses(max);
|
||||
}
|
||||
|
||||
int Blobs::size() const {
|
||||
return _blobs.size();
|
||||
}
|
||||
|
||||
void Blobs::setRadiusAt(
|
||||
rpl::producer<float> &&radius,
|
||||
int index,
|
||||
bool isMax) {
|
||||
Expects(index >= 0 && index < size());
|
||||
std::move(
|
||||
radius
|
||||
) | rpl::start_with_next([=](float r) {
|
||||
if (isMax) {
|
||||
_blobs[index].setMaxRadius(r);
|
||||
} else {
|
||||
_blobs[index].setMinRadius(r);
|
||||
}
|
||||
}, _lifetime);
|
||||
}
|
||||
|
||||
void Blobs::setLevel(float value) {
|
||||
const auto to = std::min(_maxLevel, value) / _maxLevel;
|
||||
_levelValue.start(to);
|
||||
|
|
|
|||
|
|
@ -29,10 +29,12 @@ public:
|
|||
float levelDuration,
|
||||
float maxLevel);
|
||||
|
||||
void setRadiusAt(rpl::producer<float> &&radius, int index, bool isMax);
|
||||
void setLevel(float value);
|
||||
void paint(Painter &p, const QBrush &brush);
|
||||
|
||||
[[nodiscard]] float maxRadius() const;
|
||||
[[nodiscard]] int size() const;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
|
@ -45,6 +47,8 @@ private:
|
|||
crl::time _lastUpdateTime = 0;
|
||||
anim::continuous_value _levelValue;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Ui::Paint
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue