TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/plugin/interact/InteractScene.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_PLUGIN_INTERACTSCENE_HPP_
00002 #define _TUTTLE_PLUGIN_INTERACTSCENE_HPP_
00003 
00004 #include "InteractInfos.hpp"
00005 #include "InteractObject.hpp"
00006 #include "IsActiveFunctor.hpp"
00007 #include "Color.hpp"
00008 #include "SelectionManipulator.hpp"
00009 
00010 #include <terry/globals.hpp>
00011 
00012 #include <ofxsParam.h>
00013 
00014 #include <boost/ptr_container/ptr_vector.hpp>
00015 #include <utility>
00016 
00017 namespace tuttle {
00018 namespace plugin {
00019 namespace interact {
00020 
00021 /**
00022  * @brief To create a group of overlay/interact objects.
00023  * Inherit from InteractObject, because a group of overlay/interact objects is itself an overlay/interact object.
00024  */
00025 class InteractScene : public InteractObject
00026 {
00027 public:
00028         typedef double Scalar;
00029         typedef boost::gil::point2<Scalar> Point2;
00030         typedef boost::ptr_vector<InteractObject> InteractObjectsVector;
00031         typedef boost::ptr_vector<IsActiveFunctor> IsActiveFunctorVector;
00032         typedef boost::ptr_vector<IColor> ColorVector;
00033 
00034         typedef std::pair< InteractObject*, Point2 > SelectedObject;
00035         typedef std::vector< SelectedObject > SelectedObjectVector;
00036 
00037 public:
00038         InteractScene( OFX::ParamSet& params, const InteractInfos& infos );
00039         virtual ~InteractScene();
00040         
00041 private:
00042         OFX::ParamSet& _params;
00043         const InteractInfos& _infos;
00044         bool _mouseDown;
00045         MotionType _motionType;
00046 
00047         InteractObjectsVector _objects;
00048         IsActiveFunctorVector _isActive;
00049         ColorVector _colors;
00050 
00051         Point2 _beginPenPosition;
00052 
00053         bool _multiSelectionEnabled;
00054         bool _creatingSelection;
00055         InteractObject* _manipulator;
00056         IColor* _manipulatorColor;
00057         bool _hasSelection;
00058         SelectedObjectVector _selected;
00059         OfxRectD _selectionRect;
00060         
00061 public:
00062         InteractObjectsVector&       getObjects()       { return _objects; }
00063         const InteractObjectsVector& getObjects() const { return _objects; }
00064         
00065         void push_back( InteractObject* obj, IsActiveFunctor* isActive = new AlwaysActiveFunctor<>(), IColor* color = new Color() )
00066         {
00067                 _objects.push_back( obj );
00068                 _isActive.push_back( isActive );
00069                 _colors.push_back( color );
00070         }
00071         void setManipulator( InteractObject* obj, IColor* color = new Color() )
00072         {
00073                 _manipulator = obj;
00074                 _manipulatorColor = color;
00075         }
00076 
00077 
00078         bool draw( const OFX::DrawArgs& args ) const;
00079 
00080         bool penMotion( const OFX::PenArgs& args );
00081 
00082         bool penDown( const OFX::PenArgs& args );
00083 
00084         bool penUp( const OFX::PenArgs& args );
00085 
00086 private:
00087         SelectedObjectVector&       getSelectedObjects()       { return _selected; }
00088         const SelectedObjectVector& getSelectedObjects() const { return _selected; }
00089 
00090         bool drawSelection( const OFX::DrawArgs& args ) const;
00091 
00092         void translate( const Point2& vec );
00093         void rotate( const Point2& center, const Point2& from, const Point2& vec );
00094         void scale( const Point2& center, const Point2& factor );
00095 };
00096 
00097 }
00098 }
00099 }
00100 
00101 #endif