Skip to content

Commit

Permalink
Implement ParentEffect.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaurycyLiebner committed Mar 5, 2021
1 parent 4c930bd commit 52714d7
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 116 deletions.
103 changes: 25 additions & 78 deletions src/core/Animators/transformanimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,9 @@ SkPoint BasicTransformAnimator::mapFromParent(const SkPoint &parentRelPos) const
return toSkPoint(mapFromParent(toQPointF(parentRelPos)));
}

QMatrix BasicTransformAnimator::getCurrentTransform() const {
QMatrix matrix;
matrix.translate(mPosAnimator->getEffectiveXValue(),
mPosAnimator->getEffectiveYValue());

matrix.rotate(mRotAnimator->getEffectiveValue());
matrix.scale(mScaleAnimator->getEffectiveXValue(),
mScaleAnimator->getEffectiveYValue());
return matrix;
}

QMatrix BasicTransformAnimator::getRelativeTransformAtFrame(
const qreal relFrame) const {
const qreal relFrame, QMatrix* postTransform) const {
Q_UNUSED(postTransform)
QMatrix matrix;
matrix.translate(mPosAnimator->getEffectiveXValue(relFrame),
mPosAnimator->getEffectiveYValue(relFrame));
Expand All @@ -183,10 +173,10 @@ QMatrix BasicTransformAnimator::getRelativeTransformAtFrame(
}

void BasicTransformAnimator::moveByAbs(const QPointF &absTrans) {
if(!mParentTransform) return;
const auto savedRelPos = mPosAnimator->getSavedValue();
const auto savedAbsPos = mParentTransform->mapRelPosToAbs(savedRelPos);
const auto relPos = mParentTransform->mapAbsPosToRel(savedAbsPos + absTrans);
const auto transform = mPostTransform*mInheritedTransform;
const auto savedAbsPos = transform.map(savedRelPos);
const auto relPos = transform.inverted().map(savedAbsPos + absTrans);
setRelativePos(relPos);
}

Expand All @@ -207,7 +197,8 @@ void BasicTransformAnimator::rotateRelativeToSavedValue(const qreal rotRel,
}

void BasicTransformAnimator::updateRelativeTransform(const UpdateReason reason) {
mRelTransform = getCurrentTransform();
mRelTransform = getRelativeTransformAtFrame(anim_getCurrentRelFrame(),
&mPostTransform);
updateTotalTransform(reason);
}

Expand Down Expand Up @@ -271,19 +262,6 @@ void BasicTransformAnimator::scaleRelativeToSavedValue(const qreal sx,
mPosAnimator->setBaseValue(QPointF(matrix.dx(), matrix.dy()));
}

QMatrix BasicTransformAnimator::getParentTotalTransformAtRelFrame(
const qreal relFrame) {
if(mParentTransform.data() == nullptr) {
return QMatrix();
} else {
const qreal absFrame = prp_relFrameToAbsFrameF(relFrame);
const qreal parentRelFrame =
mParentTransform->prp_absFrameToRelFrameF(absFrame);
return mParentTransform->
getTotalTransformAtFrame(parentRelFrame);
}
}

QPointFAnimator *BasicTransformAnimator::getPosAnimator() const {
return mPosAnimator.get();
}
Expand Down Expand Up @@ -506,53 +484,23 @@ QMatrix valuesToMatrix(const qreal pivotX, const qreal pivotY,
return matrix;
}

QMatrix AdvancedTransformAnimator::getCurrentTransform() const {
qreal pivotX = mPivotAnimator->getEffectiveXValue();
qreal pivotY = mPivotAnimator->getEffectiveYValue();

qreal posX = mPosAnimator->getEffectiveXValue();
qreal posY = mPosAnimator->getEffectiveYValue();

qreal rot = mRotAnimator->getEffectiveValue();

qreal scaleX = mScaleAnimator->getEffectiveXValue();
qreal scaleY = mScaleAnimator->getEffectiveYValue();

qreal shearX = mShearAnimator->getEffectiveXValue();
qreal shearY = mShearAnimator->getEffectiveYValue();


applyTransformEffects(anim_getCurrentRelFrame(),
pivotX, pivotY,
posX, posY,
rot,
scaleX, scaleY,
shearX, shearY);

QMatrix matrix = valuesToMatrix(pivotX, pivotY,
posX, posY,
rot,
scaleX, scaleY,
shearX, shearY);

return matrix;
}

void AdvancedTransformAnimator::applyTransformEffects(
const qreal relFrame,
qreal& pivotX, qreal& pivotY,
qreal& posX, qreal& posY,
qreal& rot,
qreal& scaleX, qreal& scaleY,
qreal& shearX, qreal& shearY) const {
qreal& shearX, qreal& shearY,
QMatrix& postTransform) const {
const auto parent = getFirstAncestor<BoundingBox>();
if(!parent) return;
parent->applyTransformEffects(relFrame,
pivotX, pivotY,
posX, posY,
rot,
scaleX, scaleY,
shearX, shearY);
shearX, shearY,
postTransform);
}

void AdvancedTransformAnimator::setValues(const TransformValues &values) {
Expand All @@ -578,12 +526,6 @@ QMatrix AdvancedTransformAnimator::getRotScaleShearTransform() {
qreal shearX = mShearAnimator->getEffectiveXValue();
qreal shearY = mShearAnimator->getEffectiveYValue();

applyTransformEffects(anim_getCurrentRelFrame(),
pivotX, pivotY,
posX, posY,
rot,
scaleX, scaleY,
shearX, shearY);

QMatrix matrix = valuesToMatrix(pivotX, pivotY,
posX, posY,
Expand All @@ -594,7 +536,8 @@ QMatrix AdvancedTransformAnimator::getRotScaleShearTransform() {
return matrix;
}

QMatrix AdvancedTransformAnimator::getRelativeTransformAtFrame(const qreal relFrame) const {
QMatrix AdvancedTransformAnimator::getRelativeTransformAtFrame(
const qreal relFrame, QMatrix* postTransform) const {
qreal pivotX = mPivotAnimator->getEffectiveXValue(relFrame);
qreal pivotY = mPivotAnimator->getEffectiveYValue(relFrame);

Expand All @@ -609,20 +552,24 @@ QMatrix AdvancedTransformAnimator::getRelativeTransformAtFrame(const qreal relFr
qreal shearX = mShearAnimator->getEffectiveXValue(relFrame);
qreal shearY = mShearAnimator->getEffectiveYValue(relFrame);

applyTransformEffects(anim_getCurrentRelFrame(),
QMatrix postTransformT;

applyTransformEffects(relFrame,
pivotX, pivotY,
posX, posY,
rot,
scaleX, scaleY,
shearX, shearY);
shearX, shearY,
postTransformT);
if(postTransform) *postTransform = postTransformT;

QMatrix matrix = valuesToMatrix(pivotX, pivotY,
posX, posY,
rot,
scaleX, scaleY,
shearX, shearY);
const auto matrix = valuesToMatrix(pivotX, pivotY,
posX, posY,
rot,
scaleX, scaleY,
shearX, shearY);

return matrix;
return matrix*postTransformT;
}

BoxTransformAnimator::BoxTransformAnimator() {
Expand Down
14 changes: 7 additions & 7 deletions src/core/Animators/transformanimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class CORE_EXPORT BasicTransformAnimator : public StaticComplexAnimator {
BasicTransformAnimator();
public:
virtual void reset();
virtual QMatrix getCurrentTransform() const;
virtual QMatrix getRelativeTransformAtFrame(const qreal relFrame) const;
virtual QMatrix getRelativeTransformAtFrame(
const qreal relFrame, QMatrix* postTransform = nullptr) const;
virtual QMatrix getInheritedTransformAtFrame(const qreal relFrame) const;
virtual QMatrix getTotalTransformAtFrame(const qreal relFrame) const;

Expand Down Expand Up @@ -92,8 +92,6 @@ class CORE_EXPORT BasicTransformAnimator : public StaticComplexAnimator {

void setParentTransformAnimator(BasicTransformAnimator *parent);

QMatrix getParentTotalTransformAtRelFrame(const qreal relFrame);

QPointFAnimator *getPosAnimator() const;
QPointFAnimator *getScaleAnimator() const;
QrealAnimator *getRotAnimator() const;
Expand All @@ -103,6 +101,7 @@ class CORE_EXPORT BasicTransformAnimator : public StaticComplexAnimator {
QList<qsptr<BasicTransformAnimator>> mChildBoxes;

QMatrix mRelTransform;
QMatrix mPostTransform;
QMatrix mInheritedTransform;
QMatrix mTotalTransform;

Expand All @@ -124,15 +123,16 @@ class CORE_EXPORT AdvancedTransformAnimator : public BasicTransformAnimator {
AdvancedTransformAnimator();
public:
void reset();
QMatrix getRelativeTransformAtFrame(const qreal relFrame) const;
QMatrix getCurrentTransform() const;
QMatrix getRelativeTransformAtFrame(
const qreal relFrame, QMatrix* postTransform = nullptr) const;

void applyTransformEffects(const qreal relFrame,
qreal& pivotX, qreal& pivotY,
qreal& posX, qreal& posY,
qreal& rot,
qreal& scaleX, qreal& scaleY,
qreal& shearX, qreal& shearY) const;
qreal& shearX, qreal& shearY,
QMatrix& postTransform) const;

void setValues(const TransformValues& values);

Expand Down
5 changes: 3 additions & 2 deletions src/core/Boxes/boundingbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,15 @@ void BoundingBox::applyTransformEffects(
qreal& posX, qreal& posY,
qreal& rot,
qreal& scaleX, qreal& scaleY,
qreal& shearX, qreal& shearY) {
qreal& shearX, qreal& shearY,
QMatrix& postTransform) {
mTransformEffectCollection->applyEffects(relFrame,
pivotX, pivotY,
posX, posY,
rot,
scaleX, scaleY,
shearX, shearY,
this);
postTransform, this);
}

bool BoundingBox::hasTransformEffects() const {
Expand Down
3 changes: 2 additions & 1 deletion src/core/Boxes/boundingbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ class CORE_EXPORT BoundingBox : public eBoxOrSound {
qreal& posX, qreal& posY,
qreal& rot,
qreal& scaleX, qreal& scaleY,
qreal& shearX, qreal& shearY);
qreal& shearX, qreal& shearY,
QMatrix& postTransform);

bool hasTransformEffects() const;

Expand Down
13 changes: 7 additions & 6 deletions src/core/TransformEffects/followobjecteffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ FollowObjectEffect::FollowObjectEffect() :
FollowObjectEffectBase("follow object",
TransformEffectType::followObject) {}

void FollowObjectEffect::applyEffect(
const qreal relFrame,
void FollowObjectEffect::applyEffect(const qreal relFrame,
qreal& pivotX, qreal& pivotY,
qreal& posX, qreal& posY,
qreal& rot,
qreal& scaleX, qreal& scaleY,
qreal& shearX, qreal& shearY,
QMatrix& postTransform,
BoundingBox* const parent) {
Q_UNUSED(pivotX);
Q_UNUSED(pivotY);
Q_UNUSED(shearX);
Q_UNUSED(shearY);
Q_UNUSED(pivotX)
Q_UNUSED(pivotY)
Q_UNUSED(shearX)
Q_UNUSED(shearY)
Q_UNUSED(postTransform)

if(!isVisible()) return;

Expand Down
1 change: 1 addition & 0 deletions src/core/TransformEffects/followobjecteffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class FollowObjectEffect : public FollowObjectEffectBase {
qreal &rot,
qreal &scaleX, qreal &scaleY,
qreal &shearX, qreal &shearY,
QMatrix& postTransform,
BoundingBox* const parent) override;
};

Expand Down
2 changes: 1 addition & 1 deletion src/core/TransformEffects/followobjecteffectbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FollowObjectEffectBase : public TargetTransformEffect {
qreal &shearX, qreal &shearY,
BoundingBox* const parent,
const QMatrix& transform);
private:
protected:
void setRotScaleAfterTargetChange(
BoundingBox* const oldTarget,
BoundingBox* const newTarget) override;
Expand Down
10 changes: 6 additions & 4 deletions src/core/TransformEffects/followobjectrelativeeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ void FollowObjectRelativeEffect::applyEffect(
qreal& rot,
qreal& scaleX, qreal& scaleY,
qreal& shearX, qreal& shearY,
QMatrix& postTransform,
BoundingBox* const parent) {
Q_UNUSED(pivotX);
Q_UNUSED(pivotY);
Q_UNUSED(shearX);
Q_UNUSED(shearY);
Q_UNUSED(pivotX)
Q_UNUSED(pivotY)
Q_UNUSED(shearX)
Q_UNUSED(shearY)
Q_UNUSED(postTransform)

if(!isVisible()) return;

Expand Down
1 change: 1 addition & 0 deletions src/core/TransformEffects/followobjectrelativeeffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class FollowObjectRelativeEffect :
qreal &rot,
qreal &scaleX, qreal &scaleY,
qreal &shearX, qreal &shearY,
QMatrix& postTransform,
BoundingBox* const parent) override;
};

Expand Down
17 changes: 9 additions & 8 deletions src/core/TransformEffects/followpatheffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,21 @@ void FollowPathEffect::setRotScaleAfterTargetChange(
parent->rotateBy(rot);
}

void FollowPathEffect::applyEffect(
const qreal relFrame,
void FollowPathEffect::applyEffect(const qreal relFrame,
qreal& pivotX, qreal& pivotY,
qreal& posX, qreal& posY,
qreal& rot,
qreal& scaleX, qreal& scaleY,
qreal& shearX, qreal& shearY,
QMatrix& postTransform,
BoundingBox* const parent) {
Q_UNUSED(pivotX);
Q_UNUSED(pivotY);
Q_UNUSED(scaleX);
Q_UNUSED(scaleY);
Q_UNUSED(shearX);
Q_UNUSED(shearY);
Q_UNUSED(pivotX)
Q_UNUSED(pivotY)
Q_UNUSED(scaleX)
Q_UNUSED(scaleY)
Q_UNUSED(shearX)
Q_UNUSED(shearY)
Q_UNUSED(postTransform)

if(!isVisible()) return;

Expand Down
1 change: 1 addition & 0 deletions src/core/TransformEffects/followpatheffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FollowPathEffect : public TargetTransformEffect {
qreal &rot,
qreal &scaleX, qreal &scaleY,
qreal &shearX, qreal &shearY,
QMatrix& postTransform,
BoundingBox* const parent) override;
private:
void setRotScaleAfterTargetChange(
Expand Down
Loading

0 comments on commit 52714d7

Please sign in to comment.