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 MotionType() 00033 : _mode(eMotionNone) 00034 , _axis(eAxisNone) 00035 {} 00036 00037 EMotion _mode; 00038 EAxis _axis; 00039 }; 00040 00041 template<class Point> 00042 inline EAxis clicPoint( const Point& point, const Point& mouse, const double marge ) 00043 { 00044 Point dist; 00045 dist.x = std::abs( point.x - mouse.x ); 00046 dist.y = std::abs( point.y - mouse.y ); 00047 00048 const double bigMarge = marge * 3.0; 00049 const double tinyMarge = marge * 0.5; 00050 if( dist.x < marge && dist.y < marge ) 00051 { 00052 return eAxisXY; 00053 } 00054 else if( dist.y < tinyMarge && dist.x < bigMarge ) 00055 { 00056 return eAxisX; 00057 } 00058 else if( dist.x < tinyMarge && dist.y < bigMarge ) 00059 { 00060 return eAxisY; 00061 } 00062 return eAxisNone; 00063 } 00064 00065 /** 00066 * @brief check if the mouse clic intersect a point 00067 * @return the type of intersection (None, XY, X, Y) 00068 * @param point the ofx parameter (in normalized space) 00069 * @param mouse the mouse clic 00070 */ 00071 inline EAxis clicDouble2D( const OFX::Double2DParam& point, const OfxPointD& mouse, const double marge ) 00072 { 00073 OfxPointD p = point.getValue(); 00074 00075 return clicPoint<>( p, mouse, marge ); 00076 } 00077 00078 inline EAxis clicDouble2D( const OFX::Double2DParam* point, const OfxPointD& mouse, const double marge ) 00079 { 00080 return clicDouble2D( *point, mouse, marge ); 00081 } 00082 00083 } 00084 } 00085 } 00086 00087 #endif 00088