TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/plugin/interact/ParamPointRelativePoint.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_PLUGIN_PARAMPOINTINCLIPRELATIVEPOINT_HPP_
00002 #define _TUTTLE_PLUGIN_PARAMPOINTINCLIPRELATIVEPOINT_HPP_
00003 
00004 #include "InteractInfos.hpp"
00005 #include "InteractObject.hpp"
00006 #include "ParamPoint.hpp"
00007 #include <tuttle/plugin/ofxToGil/point.hpp>
00008 #include <ofxsParam.h>
00009 
00010 namespace tuttle {
00011 namespace plugin {
00012 namespace interact {
00013 
00014 template<class TFrame, ECoordinateSystem coord>
00015 class ParamPointRelativePoint : public ParamPoint<TFrame, coord>
00016 {
00017         static const ECoordinateSystem notCenteredCoord = CoordinateSystemAxisXY<NotCenteredCoodinate<coord>::value>::value;
00018 public:
00019         ParamPointRelativePoint( const InteractInfos& infos, OFX::Double2DParam* param, const TFrame& relativeFrame, const PointInteract* relativePoint )
00020                 : ParamPoint<TFrame, coord>( infos, param, relativeFrame )
00021                 , _relativePoint( *relativePoint )
00022         {}
00023 
00024         ~ParamPointRelativePoint() {}
00025 
00026 private:
00027         const PointInteract& _relativePoint;
00028 
00029 public:
00030         Point2 getPoint() const
00031         {
00032                 OfxRectD rod = this->_frame.getFrame( this->getTime() );
00033                 Point2 rodSize( rod.x2 - rod.x1, rod.y2 - rod.y1 );
00034                 Point2 relativePoint = _relativePoint.getPoint();
00035                 Point2 paramPoint    = ofxToGil( this->_param.getValue() );
00036                 Point2 point         = pointConvertCoordinateSystem<notCenteredCoord,eCoordinateSystemXY>( paramPoint, rodSize );
00037                 Point2 res           = relativePoint + point;
00038 
00039                 return res;
00040         }
00041 
00042         void setPoint( const Scalar x, const Scalar y )
00043         {
00044                 if( _relativePoint.getSelected() )
00045                         return;
00046                 if( this->_frame.isEnabled() )
00047                 {
00048                         OfxRectD rod = this->_frame.getFrame( this->getTime() );
00049                         Point2 rodSize( rod.x2 - rod.x1, rod.y2 - rod.y1 );
00050                         Point2 point         = pointConvertCoordinateSystem<eCoordinateSystemXY,notCenteredCoord>( Point2( x, y ), rodSize );
00051                         Point2 relativePoint = pointConvertCoordinateSystem<eCoordinateSystemXY,notCenteredCoord>( _relativePoint.getPoint(), rodSize );
00052                         this->_param.setValue( point.x - relativePoint.x, point.y - relativePoint.y );
00053                         return;
00054                 }
00055                 this->_param.setValue( 0, 0 );
00056         }
00057 };
00058 
00059 }
00060 }
00061 }
00062 
00063 #endif
00064