All Classes Namespaces Functions Variables Enumerations Properties Pages
keyframe.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 "keyframe.h"
19 
20 
21 KeyFrame::KeyFrame()
22 {
23 }
24 
25 KeyFrame::KeyFrame(const KeyFrame& k2)
26 {
27  mFrame = k2.mFrame;
28  mLength = k2.mLength;
29  mIsModified = k2.mIsModified;
30  mIsSelected = k2.mIsSelected;
31  mAttachedFileName = k2.mAttachedFileName;
32  // intentionally not copying event listeners
33 }
34 
35 KeyFrame::~KeyFrame()
36 {
37  for (KeyFrameEventListener* listener : mEventListeners)
38  {
39  listener->onKeyFrameDestroy(this);
40  }
41 }
42 
43 KeyFrame& KeyFrame::operator=(const KeyFrame& k2)
44 {
45  if (this == &k2)
46  {
47  return *this; // a self-assignment
48  }
49 
50  mFrame = k2.mFrame;
51  mLength = k2.mLength;
52  mIsModified = k2.mIsModified;
53  mIsSelected = k2.mIsSelected;
54  mAttachedFileName = k2.mAttachedFileName;
55  // intentionally not copying event listeners
56  return *this;
57 }
58 
59 void KeyFrame::addEventListener(KeyFrameEventListener* listener)
60 {
61  auto it = std::find(mEventListeners.begin(), mEventListeners.end(), listener);
62  if (it == mEventListeners.end())
63  {
64  mEventListeners.push_back(listener);
65  }
66 }
67 
68 void KeyFrame::removeEventListner(KeyFrameEventListener* listener)
69 {
70  auto it = std::find(mEventListeners.begin(), mEventListeners.end(), listener);
71  if (it != mEventListeners.end())
72  {
73  mEventListeners.erase(it);
74  }
75 }