tahoma2d/toonz/sources/include/tparamcontainer.h

120 lines
3.1 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TPARAMCONTAINER_INCLUDED
#define TPARAMCONTAINER_INCLUDED
2016-04-14 22:15:09 +12:00
#include <memory>
2016-03-19 06:57:51 +13:00
#include "tparam.h"
//#include "tfx.h"
#include "tcommon.h"
#undef DVAPI
#undef DVVAR
#ifdef TPARAM_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
class TIStream;
class TOStream;
class TParamObserver;
class TParam;
2016-06-15 18:43:10 +12:00
class DVAPI TParamVar {
std::string m_name;
bool m_isHidden;
// Flag for an obsolete parameter used for maintaining backward-compatiblity.
// - The obsolete parameter will call a special function
// (TFx::onObsoleteParameterLoaded) on loaded which enables to do some special
// action. (e.g. converting to a new parameter etc.)
// - The obsolete parameter will not be saved.
bool m_isObsolete;
2016-06-15 18:43:10 +12:00
TParamObserver *m_paramObserver;
2016-03-19 06:57:51 +13:00
public:
TParamVar(std::string name, bool hidden = false, bool obsolete = false)
: m_name(name)
, m_isHidden(hidden)
, m_isObsolete(obsolete)
, m_paramObserver(0) {}
2016-06-15 18:43:10 +12:00
virtual ~TParamVar() {}
virtual TParamVar *clone() const = 0;
std::string getName() const { return m_name; }
bool isHidden() const { return m_isHidden; }
void setIsHidden(bool hidden) { m_isHidden = hidden; }
bool isObsolete() const { return m_isObsolete; }
virtual void setParam(TParam *param) = 0;
virtual TParam *getParam() const = 0;
2016-06-15 18:43:10 +12:00
void setParamObserver(TParamObserver *obs);
2016-03-19 06:57:51 +13:00
};
template <class T>
class TParamVarT final : public TParamVar {
2018-07-10 20:35:03 +12:00
// Very dirty fix for link fx, separating the variable between the plugin fx
// and the built-in fx.
// Note that for now link fx is available only with built-in fx, since m_var
// must be "pointer to pointer" of parameter to make the link fx to work
// properly.
T *m_var = nullptr;
TParamP m_pluginVar = 0;
2016-03-19 06:57:51 +13:00
public:
2018-07-10 20:35:03 +12:00
TParamVarT(std::string name, T *var = nullptr, TParamP pluginVar = 0,
bool hidden = false, bool obsolete = false)
: TParamVar(name, hidden), m_var(var), m_pluginVar(pluginVar) {}
TParamVarT() = delete;
void setParam(TParam *param) {
if (m_var)
*m_var = TParamP(param);
else
m_pluginVar = TParamP(param);
}
virtual TParam *getParam() const {
if (m_var)
return m_var->getPointer();
else
return m_pluginVar.getPointer();
}
TParamVar *clone() const {
return new TParamVarT<T>(getName(), m_var, m_pluginVar, isHidden());
2016-06-15 18:43:10 +12:00
}
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
class DVAPI TParamContainer {
class Imp;
std::unique_ptr<Imp> m_imp;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TParamContainer();
~TParamContainer();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void add(TParamVar *var);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getParamCount() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isParamHidden(int index) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TParam *getParam(int index) const;
std::string getParamName(int index) const;
TParam *getParam(std::string name) const;
TParamVar *getParamVar(std::string name) const;
2016-06-15 18:43:10 +12:00
const TParamVar *getParamVar(int index) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void unlink();
void link(const TParamContainer *src);
void copy(const TParamContainer *src);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setParamObserver(TParamObserver *);
TParamObserver *getParamObserver() const;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
TParamContainer(const TParamContainer &);
TParamContainer &operator=(const TParamContainer &);
2016-03-19 06:57:51 +13:00
};
#endif