1 #pragma once
2 
3 #ifndef STROKEDEFORMATION_IMPL_H
4 #define STROKEDEFORMATION_IMPL_H
5 
6 /**
7  * @author  Fabrizio Morciano <fabrizio.morciano@gmail.com>
8  */
9 
10 #include "ext/StrokeDeformation.h"
11 
12 #undef DVAPI
13 #undef DVVAR
14 #ifdef TNZEXT_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 #include "ExtUtil.h"
23 
24 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
25 // to avoid annoying warning
26 #pragma warning(push)
27 #pragma warning(disable : 4251)
28 #endif
29 
30 namespace ToonzExt {
31 class DVAPI StrokeDeformationImpl {
32 private:
33   bool init(const ContextStatus *);
34 
35   bool computeStroke2Transform(const ContextStatus *s,
36                                TStroke *&stroke2transform, double &w,
37                                ToonzExt::Interval &extremes);
38 
39   ToonzExt::Potential *potential_;
40 
41   static TStroke
42       *copyOfLastSelectedStroke_;  // deep copy stroke selected previously
43 
44   int cursorId_;
45 
46 protected:
47   TStroke *stroke2manipulate_;
48 
49   static TStroke *&getLastSelectedStroke();
50 
51   static void setLastSelectedStroke(TStroke *);
52 
53   static int &getLastSelectedDegree();
54 
55   static void setLastSelectedDegree(int degree);
56 
57   static ToonzExt::Intervals &getSpiresList();
58 
59   static ToonzExt::Intervals &getStraightsList();
60 
61   ToonzExt::StrokeParametricDeformer *deformer_;
62 
63   int shortcutKey_;
64 
65   double old_w0_;
66 
67   TPointD old_w0_pos_;
68 
69   // ref to simplify access
70   std::vector<TStroke *> strokes_;
71 
72   StrokeDeformationImpl();
73 
74   /**
75 * Is this the correct deformation?
76 */
77   virtual bool check_(const ContextStatus *) = 0;
78 
79   /**
80 * Retrieve the nearest extremes to point selected.
81 */
82   virtual bool findExtremes_(const ContextStatus *, Interval &) = 0;
83 
84   virtual double findActionLength() = 0;
85 
86 public:
87   virtual ~StrokeDeformationImpl();
88 
89   ToonzExt::Interval getExtremes();
90 
91   static const ContextStatus *&getImplStatus();
92 
getStrokeSelected()93   const TStroke *getStrokeSelected() const {
94     if (getImplStatus()) return this->getImplStatus()->stroke2change_;
95     return 0;
96   }
97 
getCopiedStroke()98   const TStroke *getCopiedStroke() const { return this->getStrokeSelected(); }
99 
100   /**
101 *Wrapper for activate.
102 */
103   virtual bool activate_impl(const ContextStatus *);
104 
105   /**
106 * Modify stroke.
107 */
108   virtual void update_impl(const TPointD &delta);
109 
110   /**
111 * Reduce control points and change stroke.
112 */
113   virtual TStroke *deactivate_impl();
114 
115   bool check(const ContextStatus *);
116 
117   /**
118 * Restore last good status.
119 */
120   virtual void reset();
121 
122   void setPotential(Potential *);
123 
124   /**
125 *Apply a designer on current deformation.
126 */
127   virtual void draw(Designer *);
128 
129   TStroke *getTransformedStroke();
130 
131   ToonzExt::Potential *getPotential();
132 
133   TPointD &oldW0();
134 
getShortcutKey()135   int getShortcutKey() const { return shortcutKey_; }
136 
getCursorId()137   int getCursorId() const { return cursorId_; }
setCursorId(int id)138   void setCursorId(int id) { cursorId_ = id; }
139 };
140 }
141 
142 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
143 #pragma warning(pop)
144 #endif
145 
146 #endif /* STROKEDEFORMATION_IMPL_H */
147 //-----------------------------------------------------------------------------
148 //  End Of File
149 //-----------------------------------------------------------------------------
150