1 #pragma once
2 
3 #ifndef ONION_SKIN_MASK_INCLUDED
4 #define ONION_SKIN_MASK_INCLUDED
5 
6 // TnzCore includes
7 #include "tcommon.h"
8 #include "tgeometry.h"
9 
10 #include <QList>
11 
12 #undef DVAPI
13 #undef DVVAR
14 #ifdef TOONZLIB_EXPORTS
15 #define DVAPI DV_EXPORT_API
16 #define DVVAR DV_EXPORT_VAR
17 #else
18 #define DVAPI DV_IMPORT_API
19 #define DVVAR DV_IMPORT_VAR
20 #endif
21 
22 //====================================================
23 
24 //    Forward declarations
25 
26 class TFrameId;
27 class TXshSimpleLevel;
28 
29 //====================================================
30 
31 //***************************************************************************
32 //    OnionSkinMask  declaration
33 //***************************************************************************
34 
35 /*!
36   OnionSkinMask is the class encapsulating onion skin data in Toonz.
37 */
38 
39 class DVAPI OnionSkinMask {
40 public:
41   enum ShiftTraceStatus {
42     DISABLED,
43     EDITING_GHOST,
44     ENABLED,
45     ENABLED_WITHOUT_GHOST_MOVEMENTS
46   };
47 
48 public:
OnionSkinMask()49   OnionSkinMask() : m_enabled(false), m_wholeScene(false) {}
50 
51   void clear();
52 
53   //! Fills in the output vector with the absolute frames to be onion-skinned.
54   void getAll(int currentRow, std::vector<int> &output) const;
55 
getMosCount()56   int getMosCount() const {
57     return m_mos.size();
58   }  //!< Returns the Mobile OS frames count
getFosCount()59   int getFosCount() const {
60     return m_fos.size();
61   }  //!< Returns the Fixed OS frames count
62 
getMos(int index)63   int getMos(int index) const {
64     assert(0 <= index && index < (int)m_mos.size());
65     return m_mos[index];
66   }
67 
getFos(int index)68   int getFos(int index) const {
69     assert(0 <= index && index < (int)m_fos.size());
70     return m_fos[index];
71   }
72 
73   void setMos(int drow, bool on);  //!< Sets a Mobile OS frame shifted by drow
74                                    //! around current xsheet frame
75   void setFos(int row,
76               bool on);  //!< Sets a Fixed OS frame to the specified xsheet row
77 
78   bool isMos(int drow) const;
79   bool isFos(int row) const;
80 
81   bool getMosRange(int &drow0, int &drow1) const;
82 
isEmpty()83   bool isEmpty() const { return m_mos.empty() && m_fos.empty(); }
84 
isEnabled()85   bool isEnabled() const { return m_enabled; }
enable(bool on)86   void enable(bool on) { m_enabled = on; }
87 
isWholeScene()88   bool isWholeScene() const { return m_wholeScene; }
setIsWholeScene(bool wholeScene)89   void setIsWholeScene(bool wholeScene) { m_wholeScene = wholeScene; }
90 
91   /*!
92 Returns the fade (transparency) value, in the [0.0, 1.0] range, corresponding to
93 the specified
94 distance from current frame. In case distance == 0, the returned value is 0.9,
95 ie \a almost opaque,
96 since underlying onion-skinned drawings must be visible.
97 */
98   static double getOnionSkinFade(int distance);
99 
100   // Shift & Trace  stuff
101 
getShiftTraceStatus()102   ShiftTraceStatus getShiftTraceStatus() const { return m_shiftTraceStatus; }
setShiftTraceStatus(ShiftTraceStatus status)103   void setShiftTraceStatus(ShiftTraceStatus status) {
104     m_shiftTraceStatus = status;
105   }
106 
isShiftTraceEnabled()107   bool isShiftTraceEnabled() const { return m_shiftTraceStatus != DISABLED; }
108 
getShiftTraceGhostAff(int index)109   const TAffine getShiftTraceGhostAff(int index) const {
110     return m_ghostAff[index];
111   }
112   void setShiftTraceGhostAff(int index, const TAffine &aff);
113 
getShiftTraceGhostCenter(int index)114   const TPointD getShiftTraceGhostCenter(int index) const {
115     return m_ghostCenter[index];
116   }
117   void setShiftTraceGhostCenter(int index, const TPointD &center);
118 
getShiftTraceGhostFrameOffset(int index)119   const int getShiftTraceGhostFrameOffset(int index) {
120     return m_ghostFrame[index];
121   }
setShiftTraceGhostFrameOffset(int index,int offset)122   void setShiftTraceGhostFrameOffset(int index, int offset) {
123     m_ghostFrame[index] = offset;
124   }
125 
getGhostFlipKey()126   const int getGhostFlipKey() {
127     return (m_ghostFlipKeys.isEmpty()) ? 0 : m_ghostFlipKeys.last();
128   }
appendGhostFlipKey(int key)129   void appendGhostFlipKey(int key) {
130     m_ghostFlipKeys.removeAll(key);
131     m_ghostFlipKeys.append(key);
132   }
removeGhostFlipKey(int key)133   void removeGhostFlipKey(int key) { m_ghostFlipKeys.removeAll(key); }
clearGhostFlipKey()134   void clearGhostFlipKey() { m_ghostFlipKeys.clear(); }
135 
136 private:
137   std::vector<int> m_fos, m_mos;  //!< Fixed and Mobile Onion Skin indices
138   bool m_enabled;                 //!< Whether onion skin is enabled
139   bool m_wholeScene;              //!< Whether the OS works on the entire scene
140 
141   ShiftTraceStatus m_shiftTraceStatus;
142   TAffine m_ghostAff[2];
143   TPointD m_ghostCenter[2];
144   int m_ghostFrame[2];         // relative frame position of the ghosts
145   QList<int> m_ghostFlipKeys;  // If F1, F2 or F3 key is pressed, then only
146                                // display the corresponding ghost
147 };
148 
149 //***************************************************************************
150 //    OnionSkinMaskModifier  declaration
151 //***************************************************************************
152 
153 class DVAPI OnionSkinMaskModifier {
154 public:
155   OnionSkinMaskModifier(OnionSkinMask mask, int currentRow);
156 
getMask()157   const OnionSkinMask &getMask() const { return m_curMask; }
158 
159   void click(int row, bool isFos);
160   void drag(int row);
161   void release(int row);
162 
163 private:
164   OnionSkinMask m_oldMask, m_curMask;
165 
166   int m_firstRow, m_lastRow;
167   int m_curRow;
168 
169   int m_status;
170 };
171 
172 #endif  // ONION_SKIN_MASK_INCLUDED
173