Skip to content

Commit

Permalink
Merge pull request #338 from friction2d/sub-path-effect_offset
Browse files Browse the repository at this point in the history
Sub path effect offset
  • Loading branch information
rodlie authored Nov 22, 2024
2 parents d28f819 + 6e81b66 commit cc994d1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/core/Animators/staticcomplexanimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ void StaticComplexAnimator::prp_readProperty_impl(eReadStream &src)
{
const auto& children = ca_getChildren();
const auto SVGProperties = QStringList() << "begin event" << "end event";
const bool isSubPathEffect = prp_getName() == "sub-path effect";

for (const auto& prop : children) {
if (src.evFileVersion() < EvFormat::svgBeginEnd &&
SVGProperties.contains(prop->prp_getName())) { continue; }
if (src.evFileVersion() < EvFormat::subPathOffset &&
isSubPathEffect && prop->prp_getName() == "offset") { continue; }
prop->prp_readProperty(src);
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/core/PathEffects/subpatheffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ SubPathEffect::SubPathEffect() :
mMax->setValueRange(-999, 999);
mMax->setCurrentBaseValue(100);

mOffset = enve::make_shared<QrealAnimator>("offset");
mOffset->setValueRange(-999, 999);
mOffset->setCurrentBaseValue(0);

ca_addChild(mPathWise);
ca_addChild(mMin);
ca_addChild(mMax);
ca_addChild(mOffset);
}

class SubPathEffectCaller : public PathEffectCaller {
Expand Down Expand Up @@ -121,7 +126,9 @@ void SubPathEffectCaller::apply(SkPath &path) {
stdsptr<PathEffectCaller> SubPathEffect::getEffectCaller(
const qreal relFrame, const qreal influence) const {
const bool pathWise = mPathWise->getValue();
const qreal minFrac = mMin->getEffectiveValue(relFrame)*0.01*influence;
const qreal maxFrac = mMax->getEffectiveValue(relFrame)*0.01*influence + 1 - influence;
const qreal offset = mOffset->getEffectiveValue(relFrame);
const qreal minFrac = (mMin->getEffectiveValue(relFrame) + offset) * 0.01 * influence;
const qreal maxFrac = (mMax->getEffectiveValue(relFrame) + offset) * 0.01 * influence + 1 - influence;

return enve::make_shared<SubPathEffectCaller>(pathWise, minFrac, maxFrac);
}
1 change: 1 addition & 0 deletions src/core/PathEffects/subpatheffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CORE_EXPORT SubPathEffect : public PathEffect {
qsptr<BoolProperty> mPathWise;
qsptr<QrealAnimator> mMin;
qsptr<QrealAnimator> mMax;
qsptr<QrealAnimator> mOffset;
};

#endif // SUBPATHEFFECT_H
1 change: 1 addition & 0 deletions src/core/ReadWrite/evformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace EvFormat {
svgBeginEnd = 29,
formatOptions = 30,
formatOptions2 = 31,
subPathOffset = 32,

nextVersion
};
Expand Down

0 comments on commit cc994d1

Please sign in to comment.