1 #pragma once 2 3 #ifndef STROKE_DEFORMATION_H 4 #define STROKE_DEFORMATION_H 5 6 /** 7 * @author Fabrizio Morciano <fabrizio.morciano@gmail.com> 8 */ 9 10 #include "tcommon.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 "tgeometry.h" 23 //#include "ext/TriParam.h" 24 #include "ext/Types.h" 25 #include "ext/ContextStatus.h" 26 27 #include <vector> 28 29 // forward declarations 30 31 class TStroke; 32 33 #if defined(_MSC_VER) && (_MSC_VER <= 1200) 34 // to avoid annoying warning 35 #pragma warning(push) 36 #pragma warning(disable : 4251) 37 #endif 38 39 namespace ToonzExt { 40 class Designer; 41 class Potential; 42 class StrokeParametricDeformer; 43 class StrokeDeformationImpl; 44 45 //=========================================================================== 46 47 /** 48 * @brief This class is the interface for manipulation 49 * algorihms. 50 * 51 * StrokeDeformation is a wrapper for for StrokeDeformationImpl, 52 * its function is to verify state and parameteres before 53 * to call the implementation methods of deformation. 54 * 55 * There is an internal status to verify that actions: 56 * @arg @c CREATED on constructor 57 * @arg @c ACTIVE on active 58 * @arg @c UPDATING on updating 59 * @arg @c DEACTIVE on deactive 60 * 61 * If some error of state occurs @c reset method is called. 62 * ContextStatus contains information about deformation parameter, 63 * and it occurs to reduce the number of parameters required. 64 */ 65 class DVAPI StrokeDeformation { 66 private: 67 StrokeDeformationImpl *deformationImpl_; 68 69 /** 70 *@brief Internal status. 71 */ 72 enum StrokeDeformationState { CREATED, ACTIVE, UPDATING, DEACTIVE, RESETTED }; 73 74 StrokeDeformationState state_; 75 76 /** 77 *@brief Recover from an invalid state 78 */ 79 void recover(); 80 81 /** 82 *@brief Retrieve the current deformator. 83 */ 84 StrokeDeformationImpl *retrieveDeformator(const ContextStatus *status); 85 86 public: 87 StrokeDeformation(); 88 89 ~StrokeDeformation(); 90 91 /** 92 *@brief Init deformation and add control points. 93 */ 94 void activate(const ContextStatus *); 95 96 /** 97 *@brief Modify stroke. 98 */ 99 void update(const TPointD &delta); 100 101 /** 102 *@brief Return a stroke deformed. 103 *@return A stroke deformed. 104 */ 105 TStroke *deactivate(); 106 107 /** 108 *@brief Clear inner status of Deformation. 109 */ 110 void reset(); 111 112 /** 113 *@brief Just select correct Deformation. 114 */ 115 void check(const ContextStatus *); 116 117 /** 118 *@brief Apply a designer on current deformation. 119 */ 120 void draw(Designer *); 121 122 /** 123 *@brief Retrieve valid extremes for current manipulator/deformator. 124 */ 125 ToonzExt::Interval getExtremes() const; 126 127 /** 128 *@brief Return the stroke selected from user. 129 */ 130 const TStroke *getStroke() const; 131 132 /** 133 *@brief Return the stroke selected from user. 134 */ 135 const TStroke *getCopiedStroke() const; 136 137 /** 138 *@brief Return a reference to the stroke created to be manipulated. 139 *@note This stroke is different from stroke selected by user. 140 *@sa getStroke 141 */ 142 const TStroke *getTransformedStroke() const; 143 144 /** 145 *@brief Return the internal status of current deformation. 146 *@sa ContextStatus 147 */ 148 const ContextStatus *getStatus() const; 149 150 /** 151 *@brief Retrieve cursor associated to current deformator. 152 */ 153 int getCursorId() const; 154 155 #ifdef _DEBUG 156 /** 157 *@brief Return the potential used in implementation. 158 *@note This is useful just for debug, please do not use directly. 159 *@sa Potential 160 */ 161 const Potential *getPotential() const; 162 163 /** 164 *@brief Return the potential used in implementation. 165 *@note This is useful just for debug, please do not use directly. 166 *@sa Potential 167 */ 168 const StrokeDeformationImpl *getDeformationImpl() const; 169 #endif 170 }; 171 } 172 173 #if defined(_MSC_VER) && (_MSC_VER <= 1200) 174 #pragma warning(pop) 175 #endif 176 177 #endif /* STROKE_DEFORMATION_H */ 178 //----------------------------------------------------------------------------- 179 // End Of File 180 //----------------------------------------------------------------------------- 181