Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • interface
legacybackupelement.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#include "legacybackupelement.h"
19
20#include "editor.h"
21#include "layer.h"
22#include "layerbitmap.h"
23#include "layervector.h"
24#include "object.h"
25#include "selectionmanager.h"
26#include "layermanager.h"
27#include "undoredomanager.h"
28
29void BackupLegacyBitmapElement::restore(Editor* editor)
30{
31 Layer* layer = editor->object()->findLayerById(this->layerId);
32
33 if (editor->currentFrame() != this->frame) {
34 editor->scrubTo(this->frame);
35 }
36
37 editor->layers()->setCurrentLayer(layer);
38
39 if (this->frame > 0 && layer->getKeyFrameAt(this->frame) == nullptr)
40 {
41 editor->undoRedo()->restoreLegacyKey();
42 }
43 else
44 {
45 if (layer != nullptr)
46 {
47 if (layer->type() == Layer::BITMAP)
48 {
49 auto bitmapLayer = static_cast<LayerBitmap*>(layer);
50 *bitmapLayer->getLastBitmapImageAtFrame(this->frame, 0) = bitmapImage; // restore the image
51 }
52 }
53 }
54
55 auto selectMan = editor->select();
56 selectMan->setSelection(mySelection, true);
57 selectMan->setTransformAnchor(selectionAnchor);
58 selectMan->setRotation(rotationAngle);
59 selectMan->setScale(scaleX, scaleY);
60 selectMan->setTranslation(translation);
61
62 selectMan->calculateSelectionTransformation();
63
64 emit editor->frameModified(this->frame);
65}
66
67void BackupLegacyVectorElement::restore(Editor* editor)
68{
69 Layer* layer = editor->object()->findLayerById(this->layerId);
70 for (int i = 0; i < editor->object()->getLayerCount(); i++)
71 {
72 Layer* layer = editor->object()->getLayer(i);
73 if (layer->type() == Layer::VECTOR)
74 {
75 VectorImage* vectorImage = static_cast<LayerVector*>(layer)->getVectorImageAtFrame(this->frame);
76 if (vectorImage != nullptr)
77 {
78 vectorImage->modification();
79 }
80 }
81 }
82
83 if (editor->currentFrame() != this->frame) {
84 editor->scrubTo(this->frame);
85 }
86
87 editor->layers()->setCurrentLayer(layer);
88
89 if (this->frame > 0 && layer->getKeyFrameAt(this->frame) == nullptr)
90 {
91 editor->undoRedo()->restoreLegacyKey();
92 }
93 else
94 {
95 if (layer != nullptr)
96 {
97 if (layer->type() == Layer::VECTOR)
98 {
99 auto pVectorImage = static_cast<LayerVector*>(layer);
100 *pVectorImage->getLastVectorImageAtFrame(this->frame, 0) = this->vectorImage; // restore the image
101 }
102 }
103 }
104
105 auto selectMan = editor->select();
106 selectMan->setSelection(mySelection, false);
107 selectMan->setTransformAnchor(selectionAnchor);
108 selectMan->setRotation(rotationAngle);
109 selectMan->setScale(scaleX, scaleY);
110 selectMan->setTranslation(translation);
111 selectMan->calculateSelectionTransformation();
112
113 emit editor->frameModified(this->frame);
114
115}
116
117void BackupLegacySoundElement::restore(Editor* editor)
118{
119 Layer* layer = editor->object()->findLayerById(this->layerId);
120
121 editor->layers()->setCurrentLayer(layer);
122
123 if (editor->currentFrame() != this->frame) {
124 editor->scrubTo(this->frame);
125 }
126 emit editor->frameModified(this->frame);
127
128 // TODO: soundclip won't restore if overlapping on first frame
129 if (this->frame > 0 && layer->getKeyFrameAt(this->frame) == nullptr)
130 {
131 editor->undoRedo()->restoreLegacyKey();
132 }
133}
Editor
Definition: editor.h:71
Editor::frameModified
void frameModified(int frameNumber)
This should be emitted after modifying the frame content.
LayerBitmap
Definition: layerbitmap.h:26
Layer
Definition: layer.h:33
LayerVector
Definition: layervector.h:26
VectorImage
Definition: vectorimage.h:32
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39