Skip to content

Commit

Permalink
Fix copy/paste gradient between scenes
Browse files Browse the repository at this point in the history
This will fix issues where you copy something with a gradient to a different scene.

Fixes #231
  • Loading branch information
rodlie committed Aug 31, 2024
1 parent e92a3d6 commit a5fd62e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/core/Animators/paintsettingsanimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,36 @@ void PaintSettingsAnimator::prp_writeProperty_impl(eWriteStream& dst) const {
mGradientTransform->prp_writeProperty_impl(dst);
}

void PaintSettingsAnimator::prp_readProperty_impl(eReadStream& src) {
void PaintSettingsAnimator::prp_readProperty_impl(eReadStream& src)
{
mColor->prp_readProperty_impl(src);
PaintType paintType;
src.read(&paintType, sizeof(PaintType));
src.read(&mGradientType, sizeof(GradientType));
int gradRWId; src >> gradRWId;
int gradDocId; src >> gradDocId;
SimpleTask::sScheduleContexted(this, [this, gradRWId, gradDocId]() {
const auto parentScene = getParentScene();
if(!parentScene) return;
auto parentScene = getParentScene();
if (!parentScene) { return; }
SceneBoundGradient* gradient = nullptr;
if(gradRWId != -1)
if (gradRWId != -1) {
gradient = parentScene->getGradientWithRWId(gradRWId);
if(!gradient && gradDocId != -1)
}
if (!gradient && gradDocId != -1) {
gradient = parentScene->getGradientWithDocumentId(gradDocId);
if (!gradient) { // gradient is in a different scene
gradient = parentScene->getGradientWithDocumentSceneId(gradDocId);
const auto newGrad = parentScene->createNewGradient();
const auto clipboard = enve::make_shared<PropertyClipboard>(gradient);
clipboard->paste(newGrad);
gradient = newGrad;
}
}
setGradientVar(gradient);
});

mGradientPoints->prp_readProperty_impl(src);
if(src.evFileVersion() > 7) {
if (src.evFileVersion() > 7) {
mGradientTransform->prp_readProperty_impl(src);
}
setPaintType(paintType);
Expand Down
10 changes: 10 additions & 0 deletions src/core/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,16 @@ SceneBoundGradient *Canvas::getGradientWithDocumentId(const int id) const
return nullptr;
}

SceneBoundGradient *Canvas::getGradientWithDocumentSceneId(const int id) const
{
for (const auto &scene : mDocument.fScenes) {
for (const auto &grad : scene->mGradients) {
if (grad->getDocumentId() == id) { return grad.get(); }
}
}
return nullptr;
}

void Canvas::addNullObject(NullObject* const obj)
{
mNullObjects.append(obj);
Expand Down
1 change: 1 addition & 0 deletions src/core/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ class CORE_EXPORT Canvas : public CanvasBase

SceneBoundGradient * getGradientWithRWId(const int rwId) const;
SceneBoundGradient * getGradientWithDocumentId(const int id) const;
SceneBoundGradient * getGradientWithDocumentSceneId(const int id) const;

void addNullObject(NullObject* const obj);
void removeNullObject(NullObject* const obj);
Expand Down

0 comments on commit a5fd62e

Please sign in to comment.