TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/OfxhInteract.hpp
Go to the documentation of this file.
00001 /*
00002  * Software License :
00003  *
00004  * Copyright (c) 2007-2009, The Open Effects Association Ltd.  All Rights Reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * Redistributions of source code must retain the above copyright notice,
00010  *    this list of conditions and the following disclaimer.
00011  * Redistributions in binary form must reproduce the above copyright notice,
00012  *    this list of conditions and the following disclaimer in the documentation
00013  *    and/or other materials provided with the distribution.
00014  * Neither the name The Open Effects Association Ltd, nor the names of its
00015  *    contributors may be used to endorse or promote products derived from this
00016  *    software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00022  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00023  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00024  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00025  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00027  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _TUTTLE_HOST_OFX_INTERACT_HPP_
00031 #define _TUTTLE_HOST_OFX_INTERACT_HPP_
00032 
00033 #include "property/OfxhSet.hpp"
00034 #include "property/OfxhGetHook.hpp"
00035 #include "property/OfxhNotifyHook.hpp"
00036 #include "OfxhException.hpp"
00037 
00038 #include <ofxInteract.h>
00039 
00040 namespace tuttle {
00041 namespace host {
00042 namespace ofx {
00043 namespace interact {
00044 
00045 class OfxhInteractBase
00046 {
00047 public:
00048         OfxhInteractBase()
00049         : _magic(kMagic)
00050         {}
00051         virtual ~OfxhInteractBase() = 0;
00052         
00053 private:
00054         static const int kMagic = 0x09012013; ///< magic number for Interact, and current day :-)
00055         const int _magic; ///< to check for handles being nice
00056         
00057 public:
00058         bool verifyMagic() const { return this != NULL && _magic == kMagic; }
00059         
00060         /// grab a handle on the parameter for passing to the C API
00061         OfxInteractHandle getHandle() { return ( OfxInteractHandle ) this; }
00062 
00063 #ifndef SWIG
00064         /// get the property handle for this instance/descriptor
00065         virtual OfxPropertySetHandle getPropHandle() = 0;
00066 #endif
00067 };
00068 
00069 /// state the interact can be in
00070 enum State
00071 {
00072         eUninitialised,
00073         eDescribed,
00074         eCreated,
00075         eFailed
00076 };
00077 
00078 /// Descriptor for an interact. Interacts all share a single description
00079 class OfxhInteractDescriptor : public OfxhInteractBase
00080 {
00081 protected:
00082         property::OfxhSet _properties; ///< its props
00083         State _state;      ///< how is it feeling today
00084         OfxPluginEntryPoint* _entryPoint;  ///< the entry point for this overlay
00085 
00086 public:
00087         /// CTOR
00088         OfxhInteractDescriptor();
00089 
00090         /// dtor
00091         virtual ~OfxhInteractDescriptor();
00092 
00093         /// set the main entry points
00094         void setEntryPoint( OfxPluginEntryPoint* entryPoint ) { _entryPoint = entryPoint; }
00095 
00096         /// call describe on this descriptor, returns true if all went well
00097         bool describe( int bitDepthPerComponent, bool hasAlpha );
00098 
00099         /// grab a handle on the properties of this parameter for the C api
00100         OfxPropertySetHandle getPropHandle() { return _properties.getHandle(); }
00101 
00102         /// get prop set
00103         const property::OfxhSet& getProperties() const { return _properties; }
00104 
00105         /// get a non const prop set
00106         property::OfxhSet& getProperties() { return _properties; }
00107 
00108         /// call the entry point with action and the given args
00109         OfxStatus callEntry( const char*          action,
00110                              void*                handle,
00111                              OfxPropertySetHandle inArgs,
00112                              OfxPropertySetHandle outArgs ) const;
00113 
00114         /// what is it's state?
00115         State getState() const { return _state; }
00116 };
00117 
00118 /// a generic interact, it doesn't belong to anything in particular
00119 /// we need to generify this slighty more and remove the renderscale args
00120 /// into a derived class, as they only belong to image effect plugins
00121 class OfxhInteract : public OfxhInteractBase
00122         , protected property::OfxhGetHook
00123 {
00124 protected:
00125         const OfxhInteractDescriptor& _descriptor; ///< who we are
00126         property::OfxhSet _properties;  ///< its props
00127         State _state;      ///< how is it feeling today
00128         void* _effectInstance; ///< this is ugly, we need a base class to all plugin instances at some point.
00129         property::OfxhSet _argProperties;
00130 
00131         /// initialise the argument properties
00132         void initArgProp( OfxTime          time,
00133                           const OfxPointD& renderScale );
00134 
00135         /// set pen props in the args
00136         void setPenArgProps( const OfxPointD& penPos,
00137                              const OfxPointI& penPosViewport,
00138                              double           pressure );
00139 
00140         /// set key args in the props
00141         void setKeyArgProps( int   key,
00142                              char* keyString );
00143 
00144 public:
00145         OfxhInteract( const OfxhInteractDescriptor& desc, void* effectInstance );
00146 
00147         virtual ~OfxhInteract();
00148 
00149         /// what is it's state?
00150         State getState() const { return _state; }
00151 
00152         /// grab a handle on the properties of this parameter for the C api
00153         OfxPropertySetHandle getPropHandle() { return _properties.getHandle(); }
00154 
00155         /// get prop set
00156         const property::OfxhSet& getProperties() const { return _properties; }
00157 
00158         /// call the entry point in the descriptor with action and the given args
00159         OfxStatus callEntry( const char*        action,
00160                              property::OfxhSet* inArgs );
00161 
00162         /// hooks to kOfxInteractPropViewportSize in the property set
00163         /// this is actually redundant and is to be deprecated
00164         virtual void getViewportSize( int& width, int& height ) const = 0;
00165 
00166         // hooks to live kOfxInteractPropPixelScale in the property set
00167         virtual void getPixelScale( double& xScale, double& yScale ) const = 0;
00168 
00169         // hooks to kOfxInteractPropBackgroundColour in the property set
00170         virtual void getBackgroundColour( double& r, double& g, double& b ) const = 0;
00171 
00172         /// implement
00173         virtual void swapBuffers() OFX_EXCEPTION_SPEC = 0;
00174 
00175         /// implement this
00176         virtual void redraw() OFX_EXCEPTION_SPEC = 0;
00177 
00178         /// returns the params the interact uses
00179         virtual void getSlaveToParam( std::vector<std::string>& params ) const;
00180 
00181         // don't know what to do
00182         virtual void reset( const std::string& name ) OFX_EXCEPTION_SPEC;
00183 
00184         /// call create instance
00185         virtual void createInstanceAction() OFX_EXCEPTION_SPEC;
00186 
00187         // interact action - kOfxInteractActionDraw
00188         //
00189         // Params -
00190         //
00191         //    time              - the effect time at which changed occured
00192         //    renderScale       - the render scale
00193         virtual void drawAction( OfxTime time, const OfxPointD& renderScale )  OFX_EXCEPTION_SPEC;
00194 
00195         // interact action - kOfxInteractActionPenMotion
00196         //
00197         // Params  -
00198         //
00199         //    time              - the effect time at which changed occured
00200         //    renderScale       - the render scale
00201         //    penX              - the X position
00202         //    penY              - the Y position
00203         //    pressure          - the pen pressue 0 to 1
00204         virtual void penMotionAction( OfxTime          time,
00205                                       const OfxPointD& renderScale,
00206                                       const OfxPointD& penPos,
00207                                       const OfxPointI& penPosViewport,
00208                                       double           pressure ) OFX_EXCEPTION_SPEC;
00209 
00210         // interact action - kOfxInteractActionPenUp
00211         //
00212         // Params  -
00213         //
00214         //    time              - the effect time at which changed occured
00215         //    renderScale       - the render scale
00216         //    penX              - the X position
00217         //    penY              - the Y position
00218         //    pressure          - the pen pressue 0 to 1
00219         virtual void penUpAction( OfxTime          time,
00220                                   const OfxPointD& renderScale,
00221                                   const OfxPointD& penPos,
00222                                   const OfxPointI& penPosViewport,
00223                                   double           pressure ) OFX_EXCEPTION_SPEC;
00224 
00225         // interact action - kOfxInteractActionPenDown
00226         //
00227         // Params  -
00228         //
00229         //    time              - the effect time at which changed occured
00230         //    renderScale       - the render scale
00231         //    penX              - the X position
00232         //    penY              - the Y position
00233         //    pressure          - the pen pressue 0 to 1
00234         virtual void penDownAction( OfxTime          time,
00235                                     const OfxPointD& renderScale,
00236                                     const OfxPointD& penPos,
00237                                     const OfxPointI& penPosViewport,
00238                                     double           pressure ) OFX_EXCEPTION_SPEC;
00239 
00240         // interact action - kOfxInteractActionkeyDown
00241         //
00242         // Params  -
00243         //
00244         //    time              - the effect time at which changed occured
00245         //    renderScale       - the render scale
00246         //    key               - the pressed key
00247         //    keyString         - the pressed key string
00248         virtual void keyDownAction( OfxTime          time,
00249                                     const OfxPointD& renderScale,
00250                                     int              key,
00251                                     char*            keyString ) OFX_EXCEPTION_SPEC;
00252 
00253         // interact action - kOfxInteractActionkeyUp
00254         //
00255         // Params  -
00256         //
00257         //    time              - the effect time at which changed occured
00258         //    renderScale       - the render scale
00259         //    key               - the pressed key
00260         //    keyString         - the pressed key string
00261         virtual void keyUpAction( OfxTime          time,
00262                                   const OfxPointD& renderScale,
00263                                   int              key,
00264                                   char*            keyString ) OFX_EXCEPTION_SPEC;
00265 
00266         // interact action - kOfxInteractActionkeyRepeat
00267         //
00268         // Params  -
00269         //
00270         //    time              - the effect time at which changed occured
00271         //    renderScale       - the render scale
00272         //    key               - the pressed key
00273         //    keyString         - the pressed key string
00274         virtual void keyRepeatAction( OfxTime          time,
00275                                       const OfxPointD& renderScale,
00276                                       int              key,
00277                                       char*            keyString ) OFX_EXCEPTION_SPEC;
00278 
00279         // interact action - kOfxInteractActionLoseFocus
00280         //
00281         // Params -
00282         //
00283         //    time              - the effect time at which changed occured
00284         //    renderScale       - the render scale
00285         virtual void gainFocusAction( OfxTime          time,
00286                                       const OfxPointD& renderScale ) OFX_EXCEPTION_SPEC;
00287 
00288         // interact action - kOfxInteractActionLoseFocus
00289         //
00290         // Params -
00291         //
00292         //    time              - the effect time at which changed occured
00293         //    renderScale       - the render scale
00294         virtual void loseFocusAction( OfxTime          time,
00295                                       const OfxPointD& renderScale ) OFX_EXCEPTION_SPEC;
00296 };
00297 
00298 }
00299 }
00300 }
00301 }
00302 
00303 #endif