Commit 4b933a69 authored by Eoin O'Neill's avatar Eoin O'Neill 🍀
Browse files

AnimTransform: Fix move tool not respecting, modifying, or outright breaking animated masks.

Should work more or less how the user expects. There could be more to streamline the process
to make it less error prone to interface with animation, and `setParameters` sometimes causing
animations to "break" will need to be investigated at some point. For now, it works.

BUG:441974
parent ab1347fd
Pipeline #80452 skipped with stage
......@@ -54,6 +54,9 @@ public:
virtual KisKeyframeChannel* getKeyframeChannel(const KoID& koid) const = 0;
virtual void setKeyframeChannel(const QString &name, QSharedPointer<KisKeyframeChannel> kcsp) = 0;
virtual QList<KisKeyframeChannel*> copyChannelsFrom(const KisAnimatedTransformParamsInterface* other) = 0;
virtual void initializeKeyframes(KisTransformMaskSP mask, KisTransformMaskParamsInterfaceSP params, KUndo2Command* cmnd = nullptr) = 0;
virtual void setKeyframeData(KisTransformMaskSP mask, KisTransformMaskParamsInterfaceSP params, KUndo2Command* cmnd = nullptr) = 0;
};
class QDomElement;
......
......@@ -22,6 +22,9 @@
#include "kis_transform_mask.h"
#include "kis_transform_mask_params_interface.h"
#include "kis_keyframe_channel.h"
#include "kis_scalar_keyframe_channel.h"
#include "kis_image_animation_interface.h"
#include "commands_new/KisSimpleModifyTransformMaskCommand.h"
MoveStrokeStrategy::MoveStrokeStrategy(KisNodeSelectionRecipe nodeSelection,
......@@ -278,12 +281,24 @@ QRect MoveStrokeStrategy::moveNode(KisNodeSP node, QPoint offset)
TransformMaskData &data = m_transformMaskData[node];
std::unique_ptr<KUndo2Command> cmd;
KisTransformMaskParamsInterfaceSP oldParams = mask->transformParams();
KisTransformMaskParamsInterfaceSP params = oldParams->clone();
params->translateDstSpace(offset - data.currentOffset);
mask->setTransformParams(params);
std::unique_ptr<KUndo2Command> cmd(new KisSimpleModifyTransformMaskCommand(mask, oldParams, params));
if (mask->isAnimated()) {
KUndo2Command* parent = new KUndo2Command();
KisAnimatedTransformParamsInterface* animInterface = dynamic_cast<KisAnimatedTransformParamsInterface*>(mask->transformParams().data());
KIS_ASSERT(animInterface);
animInterface->initializeKeyframes(mask, params, parent);
cmd.reset(parent);
} else {
mask->setTransformParams(params);
cmd.reset(new KisSimpleModifyTransformMaskCommand(mask, oldParams, params));
}
KIS_ASSERT(cmd);
if (data.undoCommand) {
const bool mergeResult = data.undoCommand->mergeWith(cmd.get());
......
......@@ -111,6 +111,7 @@ private:
};
std::unordered_map<KisNodeSP, TransformMaskData> m_transformMaskData;
KUndo2Command* keyframeCommand;
QElapsedTimer m_updateTimer;
bool m_hasPostponedJob = false;
......
......@@ -240,6 +240,18 @@ QList<KisKeyframeChannel *> KisAnimatedTransformMaskParameters::copyChannelsFrom
return chans;
}
void KisAnimatedTransformMaskParameters::initializeKeyframes(KisTransformMaskSP mask, KisTransformMaskParamsInterfaceSP params, KUndo2Command *cmnd)
{
int time = mask->parent()->original()->defaultBounds()->currentTime();
KisAnimatedTransformMaskParameters::addKeyframes(mask, time, params, cmnd );
}
void KisAnimatedTransformMaskParameters::setKeyframeData(KisTransformMaskSP mask, KisTransformMaskParamsInterfaceSP params, KUndo2Command *cmnd)
{
int time = mask->parent()->original()->defaultBounds()->currentTime();
KisAnimatedTransformMaskParameters::setKeyframes(mask, time, params, cmnd );
}
qreal KisAnimatedTransformMaskParameters::defaultValueForScalarChannel(QString name)
{
KoID channelID = chanNameToKoID(name);
......
......@@ -34,6 +34,9 @@ public:
KisKeyframeChannel* getKeyframeChannel(const KoID& koid) const override;
QList<KisKeyframeChannel*> copyChannelsFrom(const KisAnimatedTransformParamsInterface *other) override;
void initializeKeyframes(KisTransformMaskSP mask, KisTransformMaskParamsInterfaceSP params, KUndo2Command* cmnd = nullptr) override;
void setKeyframeData(KisTransformMaskSP mask, KisTransformMaskParamsInterfaceSP params, KUndo2Command* cmnd = nullptr) override;
qreal defaultValueForScalarChannel(QString name);
bool isHidden() const override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment