00001 #ifndef _ofxsInteract_H_
00002 #define _ofxsInteract_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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