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()->getLayer(this->layer);
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  editor->updateFrame(this->frame);
38  editor->scrubTo(this->frame);
39 
40  if (this->frame > 0 && layer->getKeyFrameAt(this->frame) == nullptr)
41  {
42  editor->restoreKey();
43  }
44  else
45  {
46  if (layer != nullptr)
47  {
48  if (layer->type() == Layer::BITMAP)
49  {
50  auto pLayerBitmap = static_cast<LayerBitmap*>(layer);
51  *pLayerBitmap->getLastBitmapImageAtFrame(this->frame, 0) = this->bitmapImage; // restore the image
52  }
53  }
54  }
55 }
56 
57 void BackupVectorElement::restore(Editor* editor)
58 {
59  Layer* layer = editor->object()->getLayer(this->layer);
60  auto selectMan = editor->select();
61  selectMan->setSelection(mySelection, false);
62  selectMan->setTransformedSelectionRect(myTransformedSelection);
63  selectMan->setTempTransformedSelectionRect(myTempTransformedSelection);
64  selectMan->setRotation(rotationAngle);
65  selectMan->setSomethingSelected(somethingSelected);
66 
67  editor->updateFrameAndVector(this->frame);
68  editor->scrubTo(this->frame);
69  if (this->frame > 0 && layer->getKeyFrameAt(this->frame) == nullptr)
70  {
71  editor->restoreKey();
72  }
73  else
74  {
75  if (layer != nullptr)
76  {
77  if (layer->type() == Layer::VECTOR)
78  {
79  auto pVectorImage = static_cast<LayerVector*>(layer);
80  *pVectorImage->getLastVectorImageAtFrame(this->frame, 0) = this->vectorImage; // restore the image
81  }
82  }
83  }
84 }
85 
86 void BackupSoundElement::restore(Editor* editor)
87 {
88  Layer* layer = editor->object()->getLayer(this->layer);
89  editor->updateFrame(this->frame);
90  editor->scrubTo(this->frame);
91 
92  // TODO: soundclip won't restore if overlapping on first frame
93  if (this->frame > 0 && layer->getKeyFrameAt(this->frame) == nullptr)
94  {
95  editor->restoreKey();
96  }
97 }
Definition: layer.h:39
Definition: editor.h:51