TuttleOFX
1
|
00001 #ifndef _TUTTLE_PLUGIN_PARAMTANGENT_HPP_ 00002 #define _TUTTLE_PLUGIN_PARAMTANGENT_HPP_ 00003 00004 #include "Frame.hpp" 00005 #include "InteractInfos.hpp" 00006 #include "InteractObject.hpp" 00007 #include "PointInteract.hpp" 00008 #include "interact.hpp" 00009 #include "ParamPoint.hpp" 00010 #include <tuttle/plugin/ofxToGil/point.hpp> 00011 #include <tuttle/plugin/numeric/coordinateSystem.hpp> 00012 00013 #include <ofxsParam.h> 00014 00015 namespace tuttle { 00016 namespace plugin { 00017 namespace interact { 00018 00019 template<class TFrame, ECoordinateSystem coord> 00020 class ParamTangent : public ParamPoint<TFrame, coord> 00021 { 00022 00023 public: 00024 typedef ParamPoint<TFrame, coord> PPoint; 00025 typedef PPoint Parent; 00026 00027 ParamTangent( const InteractInfos& infos, 00028 OFX::Double2DParam* pCenter, 00029 OFX::Double2DParam* pTanA, 00030 OFX::Double2DParam* pTanB, 00031 const TFrame& frame ) 00032 : Parent( infos, pCenter, frame ) 00033 , _paramTanA( infos, pTanA, frame ) 00034 , _paramTanB( infos, pTanB, frame ) 00035 , _selectType( eSelectTypeNone ) 00036 { 00037 } 00038 00039 virtual ~ParamTangent( ) { } 00040 00041 protected: 00042 PPoint _paramTanA; 00043 PPoint _paramTanB; 00044 Point2 _previousTanVec; 00045 00046 enum ESelectType 00047 { 00048 eSelectTypeNone, 00049 eSelectTypeTanA, 00050 eSelectTypeTanB, 00051 eSelectTypeCenter 00052 }; 00053 ESelectType _selectType; 00054 00055 public: 00056 bool draw( const OFX::DrawArgs& args ) const; 00057 00058 MotionType intersect( const OFX::PenArgs& args ); 00059 00060 virtual void translate( const Point2& previous, const Point2& vec ) 00061 { 00062 const Point2 p = this->getPosition(); 00063 switch( _selectType ) 00064 { 00065 case eSelectTypeCenter: 00066 { 00067 const Point2 inv = previous - p; 00068 const Point2 realVec = inv + vec; 00069 Parent::setPosition( previous + vec ); 00070 _paramTanA.setPosition( _paramTanA.getPoint() + realVec ); 00071 _paramTanB.setPosition( _paramTanB.getPoint() + realVec ); 00072 break; 00073 } 00074 case eSelectTypeTanA: 00075 { 00076 const Point2 newpA = previous + _previousTanVec + vec; 00077 _paramTanA.setPosition( newpA ); 00078 // symetric around center 00079 _paramTanB.setPosition( 2*p - newpA ); 00080 break; 00081 } 00082 case eSelectTypeTanB: 00083 { 00084 const Point2 newpB = previous + _previousTanVec + vec; 00085 _paramTanB.setPosition( newpB ); 00086 // symetric around center 00087 _paramTanA.setPosition( 2*p - newpB ); 00088 break; 00089 } 00090 case eSelectTypeNone: 00091 break; 00092 } 00093 } 00094 }; 00095 00096 template<class TFrame, ECoordinateSystem coord> 00097 bool ParamTangent<TFrame, coord>::draw( const OFX::DrawArgs& args ) const 00098 { 00099 Parent::draw( args ); 00100 _paramTanA.draw( args ); 00101 _paramTanB.draw( args ); 00102 00103 Point2 pA = _paramTanA.getPoint( ); 00104 Point2 pB = _paramTanB.getPoint( ); 00105 00106 glBegin( GL_LINE ); 00107 glVertex2f( pA.x, pA.y ); 00108 glVertex2f( pB.x, pB.y ); 00109 glEnd( ); 00110 00111 return true; 00112 } 00113 00114 template<class TFrame, ECoordinateSystem coord> 00115 MotionType ParamTangent<TFrame, coord>::intersect( const OFX::PenArgs& args ) 00116 { 00117 MotionType m; 00118 m._mode = eMotionTranslate; 00119 m._axis = eAxisXY; 00120 00121 if( _paramTanA.intersect( args )._axis == eAxisXY ) 00122 { 00123 _selectType = eSelectTypeTanA; 00124 _previousTanVec = _paramTanA.getPosition() - this->getPosition(); 00125 return m; 00126 } 00127 if( _paramTanB.intersect( args )._axis == eAxisXY ) 00128 { 00129 _selectType = eSelectTypeTanB; 00130 _previousTanVec = _paramTanB.getPosition() - this->getPosition(); 00131 return m; 00132 } 00133 if( Parent::intersect( args )._axis == eAxisXY ) 00134 { 00135 _selectType = eSelectTypeCenter; 00136 _previousTanVec = Point2(0,0); 00137 return m; 00138 } 00139 m._mode = eMotionNone; 00140 m._axis = eAxisNone; 00141 return m; 00142 } 00143 00144 } 00145 } 00146 } 00147 00148 #endif 00149