All Classes Namespaces Functions Variables Enumerations Properties Pages
backupelement.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include "backupelement.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 
27 void BackupBitmapElement::restore(Editor* editor)
28 {
29  Layer* layer = editor->object()->findLayerById(this->layerId);
30  auto selectMan = editor->select();
31  selectMan->setSelection(mySelection, true);
32  selectMan->setTransformedSelectionRect(myTransformedSelection);
33  selectMan->setTempTransformedSelectionRect(myTempTransformedSelection);
34  selectMan->setRotation(rotationAngle);
35  selectMan->setSomethingSelected(somethingSelected);
36 
37  if (editor->currentFrame() != this->frame) {
38  editor->scrubTo(this->frame);
39  }
40  editor->frameModified(this->frame);
41 
42  if (this->frame > 0 && layer->getKeyFrameAt(this->frame) == nullptr)
43  {
44  editor->restoreKey();
45  }
46  else
47  {
48  if (layer != nullptr)
49  {
50  if (layer->type() == Layer::BITMAP)
51  {
52  auto bitmapLayer = static_cast<LayerBitmap*>(layer);
53  *bitmapLayer->getLastBitmapImageAtFrame(this->frame, 0) = bitmapImage; // restore the image
54  }
55  }
56  }
57 }
58 
59 void BackupVectorElement::restore(Editor* editor)
60 {
61  Layer* layer = editor->object()->findLayerById(this->layerId);
62  auto selectMan = editor->select();
63  selectMan->setSelection(mySelection, false);
64  selectMan->setTransformedSelectionRect(myTransformedSelection);
65  selectMan->setTempTransformedSelectionRect(myTempTransformedSelection);
66  selectMan->setRotation(rotationAngle);
67  selectMan->setSomethingSelected(somethingSelected);
68 
69  for (int i = 0; i < editor->object()->getLayerCount(); i++)
70  {
71  Layer* layer = editor->object()->getLayer(i);
72  if (layer->type() == Layer::VECTOR)
73  {
74  VectorImage* vectorImage = static_cast<LayerVector*>(layer)->getVectorImageAtFrame(this->frame);
75  if (vectorImage != nullptr)
76  {
77  vectorImage->modification();
78  }
79  }
80  }
81 
82  if (editor->currentFrame() != this->frame) {
83  editor->scrubTo(this->frame);
84  }
85  editor->frameModified(this->frame);
86  if (this->frame > 0 && layer->getKeyFrameAt(this->frame) == nullptr)
87  {
88  editor->restoreKey();
89  }
90  else
91  {
92  if (layer != nullptr)
93  {
94  if (layer->type() == Layer::VECTOR)
95  {
96  auto pVectorImage = static_cast<LayerVector*>(layer);
97  *pVectorImage->getLastVectorImageAtFrame(this->frame, 0) = this->vectorImage; // restore the image
98  }
99  }
100  }
101 }
102 
103 void BackupSoundElement::restore(Editor* editor)
104 {
105  Layer* layer = editor->object()->findLayerById(this->layerId);
106  if (editor->currentFrame() != this->frame) {
107  editor->scrubTo(this->frame);
108  }
109  editor->frameModified(this->frame);
110 
111  // TODO: soundclip won't restore if overlapping on first frame
112  if (this->frame > 0 && layer->getKeyFrameAt(this->frame) == nullptr)
113  {
114  editor->restoreKey();
115  }
116 }
void frameModified(int frameNumber)
This should be emitted after modifying the frame content.
Definition: layer.h:38
Definition: editor.h:55