Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
layer.h
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2017 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 #ifndef LAYER_H
18 #define LAYER_H
19 
20 #include <map>
21 #include <functional>
22 #include <QString>
23 #include <QPainter>
24 #include <QtXml>
25 
26 class QMouseEvent;
27 class KeyFrame;
28 class Object;
29 class TimeLineCells;
30 class Status;
31 
32 class Layer : public QObject
33 {
34  Q_OBJECT
35 
36 public:
37  enum LAYER_TYPE
38  {
39  UNDEFINED = 0,
40  BITMAP = 1,
41  VECTOR = 2,
42  MOVIE = 3,
43  SOUND = 4,
44  CAMERA = 5,
45 
46  //PAINTABLE =
47  };
48 
49  explicit Layer(Object*, LAYER_TYPE);
50  virtual ~Layer();
51 
52  QString mName;
53  bool mVisible = true;
54 
55  int id() { return mId; }
56 
57  LAYER_TYPE type() { return meType; }
58  Object* object() { return mObject; }
59 
60  void setName( QString name ) { mName = name; }
61  QString name() { return mName; }
62 
63  void switchVisibility() { mVisible = !mVisible; }
64 
65  bool visible() { return mVisible; }
66 
67  // KeyFrame interface
68  int getMaxKeyFramePosition();
69  int firstKeyFramePosition();
70 
71  virtual Status saveKeyFrame( KeyFrame*, QString path ) = 0;
72  virtual void loadDomElement( QDomElement element, QString dataDirPath ) = 0;
73  virtual QDomElement createDomElement( QDomDocument& doc ) = 0;
74 
75  bool keyExists( int position );
76  int getPreviousKeyFramePosition( int position );
77  int getNextKeyFramePosition( int position );
78  int getPreviousFrameNumber( int position, bool isAbsolute );
79  int getNextFrameNumber( int position, bool isAbsolute );
80 
81  int keyFrameCount() { return static_cast< int >( mKeyFrames.size() ); }
82 
83  bool addNewEmptyKeyAt( int position );
84  bool addKeyFrame( int position, KeyFrame* );
85  bool removeKeyFrame(int position);
86  bool swapKeyFrames( int position1, int position2 );
87  bool moveKeyFrameForward( int position );
88  bool moveKeyFrameBackward( int position );
89  bool loadKey( KeyFrame* );
90  KeyFrame* getKeyFrameAt( int position );
91  KeyFrame* getLastKeyFrameAtPosition( int position );
92  bool keyExistsWhichCovers(int frameNumber);
93  KeyFrame *getKeyFrameWhichCovers(int frameNumber);
94 
95  void foreachKeyFrame( std::function<void( KeyFrame* )> );
96 
97  void setModified( int position, bool isModified );
98 
99  // Handle selection
100  bool isFrameSelected( int position );
101  void setFrameSelected( int position, bool isSelected);
102  void toggleFrameSelected( int position, bool allowMultiple = false );
103  void extendSelectionTo( int position );
104  void selectAllFramesAfter( int position );
105  void deselectAll();
106 
107  bool moveSelectedFrames( int offset );
108 
109  Status save( QString dataFolder );
110 
111  // graphic representation -- could be put in another class
112  void paintTrack(QPainter& painter, TimeLineCells* cells, int x, int y, int width, int height, bool selected, int frameSize);
113  void paintFrames( QPainter& painter, TimeLineCells* cells, int y, int height, bool selected, int frameSize );
114  void paintLabel(QPainter& painter, TimeLineCells* cells, int x, int y, int height, int width, bool selected, int allLayers);
115  virtual void paintSelection(QPainter& painter, int x, int y, int height, int width);
116 
117  void mousePress(QMouseEvent*, int frameNumber);
118  void mouseMove(QMouseEvent*, int frameNumber);
119  void mouseRelease(QMouseEvent*, int frameNumber);
120  void mouseDoubleClick(QMouseEvent*, int frameNumber);
121 
122  virtual void editProperties();
123 
124  void setUpdated();
125 
126 protected:
127  void setId( int LayerId ) { mId = LayerId; }
128 
129 private:
130  LAYER_TYPE meType = UNDEFINED;
131  Object* mObject = nullptr;
132  int mId = 0;
133 
134  std::map<int, KeyFrame*, std::greater<int>> mKeyFrames;
135 
136  // We need to keep track of selected frames ordered by last selected
137  // and by position.
138  // Both should be pre-sorted on each selection for optimization purpose when moving frames.
139  //
140  QList<int> mSelectedFrames_byLast; // Used to hadle selection range (based on last selected
141  QList<int> mSelectedFrames_byPosition; // Used to handle frames movements on the timeline
142 };
143 
144 bool isLayerPaintable( Layer* );
145 
146 #endif
Definition: layer.h:32
Definition: object.h:71