Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

ofxsInteract.h

Go to the documentation of this file.
00001 #ifndef _ofxsInteract_H_
00002 #define _ofxsInteract_H_
00003 /*
00004 OFX Support Library, a library that skins the OFX plug-in API with C++ classes.
00005 Copyright (C) 2004-2005 The Foundry Visionmongers Ltd
00006 Author Bruno Nicoletti bruno@thefoundry.co.uk
00007 
00008 Redistribution and use in source and binary forms, with or without
00009 modification, are permitted provided that the following conditions are met:
00010 
00011 * Redistributions of source code must retain the above copyright notice,
00012 this list of conditions and the following disclaimer.
00013 * Redistributions in binary form must reproduce the above copyright notice,
00014 this list of conditions and the following disclaimer in the documentation
00015 and/or other materials provided with the distribution.
00016 * Neither the name The Foundry Visionmongers Ltd, nor the names of its 
00017 contributors may be used to endorse or promote products derived from this
00018 software without specific prior written permission.
00019 
00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00024 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00027 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 
00031 The Foundry Visionmongers Ltd
00032 1 Wardour St
00033 London W1D 6PA
00034 England
00035 
00036 
00037 
00038 */
00039 
00045 #include "ofxsParam.h"
00046 
00047 #include <list>
00048 
00050 #define mDeclareProtectedAssignAndCC(CLASS) \
00051   CLASS &operator=(const CLASS &v1) {assert(false); return *this;}      \
00052   CLASS(const CLASS &v) {assert(false); } 
00053 
00056 namespace OFX {
00057 
00059   class ImageEffect;
00060 
00062   struct InteractArgs {
00064     InteractArgs(const PropertySet &props);
00065     double          time;              
00066     OfxPointD       renderScale;       
00067   };
00068 
00070   struct DrawArgs : public InteractArgs {
00071     DrawArgs(const PropertySet &props);
00072 
00073     OfxPointD       pixelScale;        
00074     OfxRGBColourD   backGroundColour;  
00075   };
00076 
00078   struct PenArgs : public InteractArgs {
00079     PenArgs(const PropertySet &props);
00080 
00081     OfxPointD       pixelScale;        
00082     OfxPointD       penPosition;       
00083     double          penPressure;       
00084   };
00085 
00093   struct KeyArgs : public InteractArgs {
00094     KeyArgs(const PropertySet &props);
00095 
00096     int             keySymbol;         
00097     std::string     keyString;         
00098   };
00099 
00101   struct FocusArgs : public InteractArgs {
00102     FocusArgs(const PropertySet &props);
00103 
00104     OfxPointD       pixelScale;        
00105     OfxRGBColourD   backGroundColour;  
00106   };
00107 
00110   class Interact {
00111   protected :
00112     OfxInteractHandle  _interactHandle;     
00113     PropertySet        _interactProperties; 
00114     std::list<Param *> _slaveParams;        
00115     ImageEffect *_effect;                   
00117   public : 
00119     Interact(OfxInteractHandle handle);
00120 
00122     virtual ~Interact(); 
00123 
00124     PropertySet &getProperties() { return _interactProperties; }
00125 
00127     int getBitDepth(void) const;
00128 
00130     bool hasAlpha(void) const;
00131 
00133     OfxPointD getPixelScale(void) const;
00134 
00136     OfxRGBColourD getBackgroundColour(void) const;
00137 
00139     void addParamToSlaveTo(Param *p);
00140 
00142     void removeParamToSlaveTo(Param *p);
00143 
00145     void requestRedraw(void) const;
00146 
00148     void swapBuffers(void) const;
00149 
00151     // override the below in derived classes to do something useful
00152 
00154     virtual bool draw(const DrawArgs &args);
00155 
00161     virtual bool penMotion(const PenArgs &args);
00162 
00168     virtual bool penDown(const PenArgs &args);
00169 
00175     virtual bool penUp(const PenArgs &args);
00176 
00182     virtual bool keyDown(const KeyArgs &args);
00183 
00189     virtual bool keyUp(const KeyArgs &args);
00190 
00196     virtual bool keyRepeat(const KeyArgs &args);
00197 
00199     virtual void gainFocus(const FocusArgs &args);
00200 
00202     virtual void loseFocus(const FocusArgs &args);
00203   };
00204 
00206   class OverlayInteract : public Interact {
00207   public :
00209     OverlayInteract(OfxInteractHandle handle);
00210 
00212     virtual ~OverlayInteract();
00213   };
00214 
00215   class InteractDescriptor
00216   {
00217   public:
00218     InteractDescriptor():_props(0) {}
00219     virtual ~InteractDescriptor() {}
00220     void setPropertySet(OFX::PropertySet* props){ _props = props; }
00221     virtual Interact* createInstance(OfxInteractHandle handle, ImageEffect *effect) = 0;
00222     void setHasAlpha();
00223     bool getHasAlpha() const;
00224     void setBitDepth();
00225     int getBitDepth() const;
00226     virtual OfxPluginEntryPoint* getMainEntry() = 0;
00227     virtual void describe() {}
00228   protected:
00229     OFX::PropertySet* _props;
00230   };
00231 
00232   typedef InteractDescriptor EffectOverlayDescriptor;
00233 
00234   class ParamInteractDescriptor : public InteractDescriptor
00235   {
00236   public:
00237     ParamInteractDescriptor():InteractDescriptor(){}
00238     virtual ~ParamInteractDescriptor() {}
00239     void setInteractSizeAspect(double asp);
00240     void setInteractMinimumSize(int x, int y);
00241     void setInteractPreferredSize(int x, int y);
00242     virtual void setParamName(const std::string& pName) { _paramName = pName; }
00243   protected:
00244     std::string _paramName;
00245   };
00246 
00247   class ParamInteract : public Interact 
00248   {
00249   public:
00250     ParamInteract(OfxInteractHandle handle, ImageEffect* effect);
00251     virtual ~ParamInteract() {}
00252     double getInteractSizeAspect() const;
00253     OfxPointI getInteractMinimumSize() const;
00254     OfxPointI getInteractPreferredSize() const;
00255     OfxPointI getInteractSize() const;
00256   protected:
00257     ImageEffect* _effect;
00258   };
00259 
00260   namespace Private
00261   {
00262     OfxStatus interactMainEntry(const char              *actionRaw,
00263       const void                *handleRaw,
00264       OfxPropertySetHandle       inArgsRaw,
00265       OfxPropertySetHandle       outArgsRaw,
00266       InteractDescriptor& desc);
00267   }
00268 
00269   template<class DESC>
00270   class InteractMainEntry
00271   {
00272   protected:
00273     static OfxStatus overlayInteractMainEntry(const char *action, const void* handle, OfxPropertySetHandle in, OfxPropertySetHandle out)
00274     {
00275       static DESC desc;
00276       return OFX::Private::interactMainEntry(action, handle, in, out, desc);
00277     }
00278   };
00279 
00280   template<class DESC, class INSTANCE>
00281   class DefaultEffectOverlayDescriptor : public EffectOverlayDescriptor, public InteractMainEntry<DESC>
00282   {
00283   public:
00284     Interact* createInstance(OfxInteractHandle handle, ImageEffect *effect) { return new INSTANCE(handle, effect); }
00285     virtual OfxPluginEntryPoint* getMainEntry() { return InteractMainEntry<DESC>::overlayInteractMainEntry; }
00286   };
00287 
00288   template<class DESC, class INSTANCE>
00289   class DefaultParamInteractDescriptor : public ParamInteractDescriptor, public InteractMainEntry<DESC>
00290   {
00291   public:
00292     Interact* createInstance(OfxInteractHandle handle, ImageEffect *effect) { return new INSTANCE(handle, effect, _paramNameStatic); }
00293     virtual OfxPluginEntryPoint* getMainEntry() { return InteractMainEntry<DESC>::overlayInteractMainEntry; }
00294     virtual void setParamName(const std::string& pName) { _paramNameStatic = pName; }
00295   protected:
00296     static std::string _paramNameStatic;
00297   };
00298 
00299   template<class DESC, class INSTANCE> std::string OFX::DefaultParamInteractDescriptor<DESC, INSTANCE>::_paramNameStatic;
00300 };
00301 
00302 
00303 #undef mDeclareProtectedAssignAndCC
00304 
00305 #endif
00306 

Generated on Thu Oct 9 13:03:49 2008 for OFX Support by  doxygen 1.3.9.1