TuttleOFX
1
|
00001 #ifndef _TUTTLE_PLUGIN_INTERACT_HPP_ 00002 #define _TUTTLE_PLUGIN_INTERACT_HPP_ 00003 00004 #include <ofxsInteract.h> 00005 #include <ofxsParam.h> 00006 #include <tuttle/plugin/opengl/gl.h> 00007 00008 #include <cmath> 00009 00010 namespace tuttle { 00011 namespace plugin { 00012 namespace interact { 00013 00014 enum EMotion 00015 { 00016 eMotionNone, 00017 eMotionTranslate, 00018 eMotionRotate, 00019 eMotionScale 00020 }; 00021 00022 enum EAxis 00023 { 00024 eAxisNone, 00025 eAxisXY, 00026 eAxisX, 00027 eAxisY 00028 }; 00029 00030 struct MotionType 00031 { 00032 EMotion _mode; 00033 EAxis _axis; 00034 }; 00035 00036 template<class Point> 00037 inline EAxis clicPoint( const Point& point, const Point& mouse, const double marge ) 00038 { 00039 Point dist; 00040 dist.x = std::abs( point.x - mouse.x ); 00041 dist.y = std::abs( point.y - mouse.y ); 00042 00043 const double bigMarge = marge * 3.0; 00044 const double tinyMarge = marge * 0.5; 00045 if( dist.x < marge && dist.y < marge ) 00046 { 00047 return eAxisXY; 00048 } 00049 else if( dist.y < tinyMarge && dist.x < bigMarge ) 00050 { 00051 return eAxisX; 00052 } 00053 else if( dist.x < tinyMarge && dist.y < bigMarge ) 00054 { 00055 return eAxisY; 00056 } 00057 return eAxisNone; 00058 } 00059 00060 /** 00061 * @brief check if the mouse clic intersect a point 00062 * @return the type of intersection (None, XY, X, Y) 00063 * @param point the ofx parameter (in normalized space) 00064 * @param mouse the mouse clic 00065 */ 00066 inline EAxis clicDouble2D( const OFX::Double2DParam& point, const OfxPointD& mouse, const double marge ) 00067 { 00068 OfxPointD p = point.getValue(); 00069 00070 return clicPoint<>( p, mouse, marge ); 00071 } 00072 00073 inline EAxis clicDouble2D( const OFX::Double2DParam* point, const OfxPointD& mouse, const double marge ) 00074 { 00075 return clicDouble2D( *point, mouse, marge ); 00076 } 00077 00078 } 00079 } 00080 } 00081 00082 #endif 00083