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) {
|
void BlobBezier::setMinRadius(float value) {
|
||||||
_minRadius = std::min(min, max);
|
_minRadius = value;
|
||||||
_maxRadius = std::max(min, max);
|
}
|
||||||
generateBlob();
|
|
||||||
|
void BlobBezier::setMaxRadius(float value) {
|
||||||
|
_maxRadius = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Ui::Paint
|
} // namespace Ui::Paint
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ public:
|
||||||
void generateBlob();
|
void generateBlob();
|
||||||
|
|
||||||
void setRadius(float min, float max);
|
void setRadius(float min, float max);
|
||||||
|
void setMinRadius(float value);
|
||||||
|
void setMaxRadius(float value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void generateBlob(
|
void generateBlob(
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,9 @@ 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.setRadius(data.minRadius, data.maxRadius);
|
blob.setMinRadius(data.minRadius);
|
||||||
|
blob.setMaxRadius(data.maxRadius);
|
||||||
|
blob.generateBlob();
|
||||||
_blobs.push_back(std::move(blob));
|
_blobs.push_back(std::move(blob));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -39,6 +41,26 @@ float Blobs::maxRadius() const {
|
||||||
return maxOfRadiuses(max);
|
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) {
|
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,10 +29,12 @@ public:
|
||||||
float levelDuration,
|
float levelDuration,
|
||||||
float maxLevel);
|
float maxLevel);
|
||||||
|
|
||||||
|
void setRadiusAt(rpl::producer<float> &&radius, int index, bool isMax);
|
||||||
void setLevel(float value);
|
void setLevel(float value);
|
||||||
void paint(Painter &p, const QBrush &brush);
|
void paint(Painter &p, const QBrush &brush);
|
||||||
|
|
||||||
[[nodiscard]] float maxRadius() const;
|
[[nodiscard]] float maxRadius() const;
|
||||||
|
[[nodiscard]] int size() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
|
@ -45,6 +47,8 @@ private:
|
||||||
crl::time _lastUpdateTime = 0;
|
crl::time _lastUpdateTime = 0;
|
||||||
anim::continuous_value _levelValue;
|
anim::continuous_value _levelValue;
|
||||||
|
|
||||||
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Ui::Paint
|
} // namespace Ui::Paint
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue