Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/Animators/transformanimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,11 @@ void AdvancedTransformAnimator::setPivotFixedTransform(
} else if(posAnimated && !pivotAnimated) {
mPosAnimator->incAllBaseValues(posXInc, posYInc);
mPivotAnimator->setBaseValueWithoutCallingUpdater(newPivot);
mPivotAnimator->prp_afterChangedCurrent(UpdateReason::userChange);
} else { // if(!posAnimated && !pivotAnimated) {
mPosAnimator->incBaseValuesWithoutCallingUpdater(posXInc, posYInc);
mPivotAnimator->setBaseValueWithoutCallingUpdater(newPivot);
mPivotAnimator->prp_afterChangedCurrent(UpdateReason::userChange);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/core/Boxes/boundingbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ BoundingBox::BoundingBox(const QString& name, const eBoxType type) :

ca_addChild(mTransformAnimator);
const auto pivotAnim = mTransformAnimator->getPivotAnimator();
connect(pivotAnim, &Property::prp_currentFrameChanged,
this, &BoundingBox::requestGlobalPivotUpdateIfSelected);
if(pivotAnim) {
connect(pivotAnim, &Property::prp_currentFrameChanged,
this, [this](const UpdateReason reason) {
requestGlobalPivotUpdateIfSelected();
planUpdate(reason);
onPivotChanged(reason);
});
}

ca_addChild(mRasterEffectsAnimators);
mRasterEffectsAnimators->SWT_hide();
Expand Down Expand Up @@ -1036,6 +1042,8 @@ void BoundingBox::setRelativePos(const QPointF &relPos) {
mTransformAnimator->setPosition(relPos.x(), relPos.y());
}

void BoundingBox::onPivotChanged(const UpdateReason) {}

void BoundingBox::setOpacity(const qreal opacity) {
mTransformAnimator->setOpacity(opacity);
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/Boxes/boundingbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ class CORE_EXPORT BoundingBox : public eBoxOrSound {

void setPivotAbsPos(const QPointF &absPos);
void setPivotRelPos(const QPointF &relPos);
protected:
virtual void onPivotChanged(const UpdateReason reason);
public:

bool isAnimated() const;

Expand Down
8 changes: 8 additions & 0 deletions src/core/Boxes/boxwithpatheffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ void BoxWithPathEffects::addOutlineEffects(const qreal relFrame,
parent->addOutlineEffects(parentRelFrame, list, influence);
}

void BoxWithPathEffects::onPivotChanged(const UpdateReason reason) {
BoundingBox::onPivotChanged(reason);
mPathEffectsAnimators->prp_afterChangedCurrent(reason);
mFillPathEffectsAnimators->prp_afterChangedCurrent(reason);
mOutlineBasePathEffectsAnimators->prp_afterChangedCurrent(reason);
mOutlinePathEffectsAnimators->prp_afterChangedCurrent(reason);
}

void BoxWithPathEffects::getMotionBlurProperties(QList<Property*> &list) const {
BoundingBox::getMotionBlurProperties(list);
list.append(mPathEffectsAnimators.get());
Expand Down
1 change: 1 addition & 0 deletions src/core/Boxes/boxwithpatheffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class CORE_EXPORT BoxWithPathEffects : public BoundingBox {
PathCallerList& list,
const qreal influence = 1) const;
protected:
void onPivotChanged(const UpdateReason reason) override;
void getMotionBlurProperties(QList<Property*> &list) const;

qsptr<PathEffectCollection> mPathEffectsAnimators;
Expand Down
80 changes: 75 additions & 5 deletions src/core/PathEffects/duplicatepatheffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,86 @@
#include "duplicatepatheffect.h"
#include "Animators/qpointfanimator.h"
#include "Animators/intanimator.h"
#include "Animators/qrealanimator.h"
#include "Animators/transformanimator.h"
#include "Boxes/boundingbox.h"
#include "Properties/boolproperty.h"

DuplicatePathEffect::DuplicatePathEffect() :
PathEffect("duplicate effect", PathEffectType::Duplicate) {
mTranslation = enve::make_shared<QPointFAnimator>("translation");
mTranslation->setBaseValue(QPointF(10, 10));
ca_addChild(mTranslation);

mRotation = enve::make_shared<QrealAnimator>(0, -360, 360, 1, "rotation");
ca_addChild(mRotation);

mCount = enve::make_shared<IntAnimator>(1, 0, 25, 1, "count");
ca_addChild(mCount);

mUseCustomPivot = enve::make_shared<BoolProperty>("use custom pivot");
ca_addChild(mUseCustomPivot);

mCustomPivot = enve::make_shared<QPointFAnimator>("custom pivot");
mCustomPivot->setBaseValue(QPointF(0, 0));
ca_addChild(mCustomPivot);
}

class DuplicateEffectCaller : public PathEffectCaller {
public:
DuplicateEffectCaller(const int count, const qreal dX, const qreal dY) :
mCount(count), mDX(toSkScalar(dX)), mDY(toSkScalar(dY)) {}
DuplicateEffectCaller(const int count,
const qreal dX,
const qreal dY,
const qreal rot,
const bool useCustomPivot,
const SkPoint customPivot,
const SkPoint fallbackPivot,
BoxTransformAnimator * const transform,
const qreal relFrame) :
mCount(count),
mDX(toSkScalar(dX)),
mDY(toSkScalar(dY)),
mRot(toSkScalar(rot)),
mUseCustomPivot(useCustomPivot),
mCustomPivot(customPivot),
mFallbackPivot(fallbackPivot),
mTransform(transform),
mRelFrame(relFrame),
mPivotAnimator(transform ? transform->getPivotAnimator() : nullptr) {}

void apply(SkPath& path);
private:
const int mCount;
const float mDX;
const float mDY;
const float mRot;
const bool mUseCustomPivot;
const SkPoint mCustomPivot;
const SkPoint mFallbackPivot;
BoxTransformAnimator * const mTransform;
const qreal mRelFrame;
QPointFAnimator * const mPivotAnimator;
};

void DuplicateEffectCaller::apply(SkPath &path) {
SkPoint pivot;
if(mUseCustomPivot) {
pivot = mCustomPivot;
} else if(mTransform) {
pivot = toSkPoint(mTransform->getPivot(mRelFrame));
} else if(mPivotAnimator) {
pivot = toSkPoint(mPivotAnimator->getEffectiveValue(mRelFrame));
} else {
pivot = mFallbackPivot;
}

const SkPath src = path;
for(int i = 1; i <= mCount; i++)
path.addPath(src, i*mDX, i*mDY);
for(int i = 1; i <= mCount; i++) {
SkMatrix m;
m.setTranslate(i*mDX, i*mDY);
m.preRotate(i*mRot, pivot.x(), pivot.y());
path.addPath(src, m);
}
}


Expand All @@ -61,7 +114,24 @@ stdsptr<PathEffectCaller> DuplicatePathEffect::getEffectCaller(
const int count = mCount->getEffectiveIntValue(relFrame);
const qreal dX = mTranslation->getEffectiveXValue(relFrame)*influence;
const qreal dY = mTranslation->getEffectiveYValue(relFrame)*influence;
return enve::make_shared<DuplicateEffectCaller>(count, dX, dY);
const qreal rot = mRotation->getEffectiveValue(relFrame)*influence;
const bool useCustomPivot = mUseCustomPivot->getValue();
const SkPoint customPivot = toSkPoint(mCustomPivot->getEffectiveValue(relFrame));
SkPoint fallbackPivot = SkPoint::Make(0.f, 0.f);
BoxTransformAnimator *transform = nullptr;
if(const auto owner = getFirstAncestor<BoundingBox>()) {
fallbackPivot = toSkPoint(owner->getRelBoundingRect().center());
transform = owner->getBoxTransformAnimator();
}
return enve::make_shared<DuplicateEffectCaller>(count,
dX,
dY,
rot,
useCustomPivot,
customPivot,
fallbackPivot,
transform,
relFrame);
}

bool DuplicatePathEffect::skipZeroInfluence(const qreal relFrame) const {
Expand Down
11 changes: 8 additions & 3 deletions src/core/PathEffects/duplicatepatheffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@
#include "PathEffects/patheffect.h"
class IntAnimator;
class QPointFAnimator;
class QrealAnimator;
class BoolProperty;

class CORE_EXPORT DuplicatePathEffect : public PathEffect {
e_OBJECT
protected:
DuplicatePathEffect();
public:
stdsptr<PathEffectCaller> getEffectCaller(
const qreal relFrame, const qreal influence) const;
bool skipZeroInfluence(const qreal relFrame) const;
const qreal relFrame, const qreal influence) const override;
bool skipZeroInfluence(const qreal relFrame) const override;
private:
qsptr<IntAnimator> mCount;
qsptr<QPointFAnimator> mTranslation;
qsptr<QrealAnimator> mRotation;
qsptr<IntAnimator> mCount;
qsptr<BoolProperty> mUseCustomPivot;
qsptr<QPointFAnimator> mCustomPivot;
};

#endif // DUPLICATEPATHEFFECT_H