#ifndef _ofxsInteract_H_
#define _ofxsInteract_H_
#include "ofxsParam.h"
#include <list>
#define mDeclareProtectedAssignAndCC(CLASS) \
CLASS &operator=(const CLASS &) {assert(false); return *this;} \
CLASS(const CLASS &) {assert(false); }
namespace OFX {
class ImageEffect;
struct InteractArgs {
InteractArgs(const PropertySet &props);
double time;
OfxPointD renderScale;
};
struct DrawArgs : public InteractArgs {
DrawArgs(const PropertySet &props);
#ifdef kOfxInteractPropViewportSize
OfxPointD viewportSize;
#endif
OfxPointD pixelScale;
OfxRGBColourD backGroundColour;
};
struct PenArgs : public InteractArgs {
PenArgs(const PropertySet &props);
#ifdef kOfxInteractPropViewportSize
OfxPointD viewportSize;
#endif
OfxPointD pixelScale;
OfxRGBColourD backGroundColour;
OfxPointD penPosition;
OfxPointD penViewportPosition;
double penPressure;
};
struct KeyArgs : public InteractArgs {
KeyArgs(const PropertySet &props);
int keySymbol;
std::string keyString;
};
struct FocusArgs : public InteractArgs {
FocusArgs(const PropertySet &props);
OfxPointD viewportSize;
OfxPointD pixelScale;
OfxRGBColourD backGroundColour;
};
class Interact {
protected :
OfxInteractHandle _interactHandle;
PropertySet _interactProperties;
std::list<Param *> _slaveParams;
ImageEffect *_effect;
public :
Interact(OfxInteractHandle handle);
virtual ~Interact();
PropertySet &getProperties() { return _interactProperties; }
int getBitDepth(void) const;
bool hasAlpha(void) const;
OfxPointD getPixelScale(void) const;
bool getSuggestedColour(OfxRGBColourD &c) const;
OfxRGBColourD getBackgroundColour(void) const;
void addParamToSlaveTo(Param *p);
void removeParamToSlaveTo(Param *p);
void requestRedraw(void) const;
void swapBuffers(void) const;
virtual bool draw(const DrawArgs &args);
virtual bool penMotion(const PenArgs &args);
virtual bool penDown(const PenArgs &args);
virtual bool penUp(const PenArgs &args);
virtual bool keyDown(const KeyArgs &args);
virtual bool keyUp(const KeyArgs &args);
virtual bool keyRepeat(const KeyArgs &args);
virtual void gainFocus(const FocusArgs &args);
virtual void loseFocus(const FocusArgs &args);
};
class OverlayInteract : public Interact {
public :
OverlayInteract(OfxInteractHandle handle);
virtual ~OverlayInteract();
};
class InteractDescriptor
{
public:
InteractDescriptor():_props(0) {}
virtual ~InteractDescriptor() {}
void setPropertySet(OFX::PropertySet* props){ _props = props; }
virtual Interact* createInstance(OfxInteractHandle handle, ImageEffect *effect) = 0;
void setHasAlpha();
bool getHasAlpha() const;
void setBitDepth();
int getBitDepth() const;
virtual OfxPluginEntryPoint* getMainEntry() = 0;
virtual void describe() {}
protected:
OFX::PropertySet* _props;
};
typedef InteractDescriptor EffectOverlayDescriptor;
class ParamInteractDescriptor : public InteractDescriptor
{
public:
ParamInteractDescriptor():InteractDescriptor(){}
virtual ~ParamInteractDescriptor() {}
void setInteractSizeAspect(double asp);
void setInteractMinimumSize(int x, int y);
void setInteractPreferredSize(int x, int y);
virtual void setParamName(const std::string& pName) { _paramName = pName; }
protected:
std::string _paramName;
};
class ParamInteract : public Interact
{
public:
ParamInteract(OfxInteractHandle handle, ImageEffect* effect);
virtual ~ParamInteract() {}
double getInteractSizeAspect() const;
OfxPointI getInteractMinimumSize() const;
OfxPointI getInteractPreferredSize() const;
OfxPointI getInteractSize() const;
protected:
ImageEffect* _effect;
};
namespace Private
{
OfxStatus interactMainEntry(const char *actionRaw,
const void *handleRaw,
OfxPropertySetHandle inArgsRaw,
OfxPropertySetHandle outArgsRaw,
InteractDescriptor& desc);
}
template<class DESC>
class InteractMainEntry
{
protected:
static OfxStatus overlayInteractMainEntry(const char *action, const void* handle, OfxPropertySetHandle in, OfxPropertySetHandle out)
{
static DESC desc;
return OFX::Private::interactMainEntry(action, handle, in, out, desc);
}
};
template<class DESC, class INSTANCE>
class DefaultEffectOverlayDescriptor : public EffectOverlayDescriptor, public InteractMainEntry<DESC>
{
public:
Interact* createInstance(OfxInteractHandle handle, ImageEffect *effect) { return new INSTANCE(handle, effect); }
virtual OfxPluginEntryPoint* getMainEntry() { return InteractMainEntry<DESC>::overlayInteractMainEntry; }
};
template<class DESC, class INSTANCE>
class DefaultParamInteractDescriptor : public ParamInteractDescriptor, public InteractMainEntry<DESC>
{
public:
Interact* createInstance(OfxInteractHandle handle, ImageEffect *effect) { return new INSTANCE(handle, effect, _paramNameStatic); }
virtual OfxPluginEntryPoint* getMainEntry() { return InteractMainEntry<DESC>::overlayInteractMainEntry; }
virtual void setParamName(const std::string& pName) { _paramNameStatic = pName; }
protected:
static std::string _paramNameStatic;
};
template<class DESC, class INSTANCE> std::string OFX::DefaultParamInteractDescriptor<DESC, INSTANCE>::_paramNameStatic;
};
#undef mDeclareProtectedAssignAndCC
#endif