tahoma2d/toonz/sources/include/tparamset.h

273 lines
7.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 TPARAMSET_H
#define TPARAMSET_H
#include "tparam.h"
#include "tparamchange.h"
#include "tgeometry.h"
#include "tpixel.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
// forward declaration
class TParamSetImp;
class TParamSetChange final : public TParamChange {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
std::vector<TParamChange *> m_paramChanges;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TParamSetChange(TParam *param, double firstAffectedFrame,
double lastAffectedFrame,
const std::vector<TParamChange *> &paramChanges)
: TParamChange(param, firstAffectedFrame, lastAffectedFrame, true, false,
false)
, m_paramChanges(paramChanges) {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
~TParamSetChange() { clearPointerContainer(m_paramChanges); }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TParamChange *clone() const { return new TParamSetChange(*this); }
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------------------------
#ifdef _MSC_VER
2016-03-19 06:57:51 +13:00
#pragma warning(push)
#pragma warning(disable : 4251)
#endif
2016-06-15 18:43:10 +12:00
class DVAPI TParamSet : public TParam {
PERSIST_DECLARATION(TParamSet)
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TParamSet(std::string name = "");
TParamSet(const TParamSet &src);
~TParamSet();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addParam(const TParamP &param, const std::string &name);
void insertParam(const TParamP &param, const std::string &name, int index);
void removeParam(const TParamP &param);
void removeAllParam();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getParamCount() const;
TParamP getParam(int index) const;
std::string getParamName(int index) const;
int getParamIdx(const std::string &name) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void getAnimatableParams(std::vector<TParamP> &params, bool recursive = true);
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void addObserver(TParamObserver *observer) override;
void removeObserver(TParamObserver *observer) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void beginParameterChange();
void endParameterChange();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void enableDragging(bool on);
2016-06-19 20:06:29 +12:00
void enableNotification(bool on) override;
bool isNotificationEnabled() const override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool isAnimatable() const override { return true; }
bool isKeyframe(double frame) const override;
void deleteKeyframe(double frame) override;
void clearKeyframes() override;
2016-06-15 18:43:10 +12:00
void assignKeyframe(double frame, const TSmartPointerT<TParam> &src,
2016-06-19 20:06:29 +12:00
double srcFrame, bool changedOnly = false) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void getKeyframes(std::set<double> &frames) const override;
2016-06-15 18:43:10 +12:00
int getKeyframeCount() const;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
double keyframeIndexToFrame(int index) const override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
TParam *clone() const override;
void copy(TParam *src) override;
void loadData(TIStream &) override;
void saveData(TOStream &) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
int getNextKeyframe(double frame) const override;
int getPrevKeyframe(double frame) const override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool hasKeyframes() const override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
std::string getValueAlias(double frame, int precision) override;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
TParamSetImp *m_imp = nullptr;
2016-03-19 06:57:51 +13:00
};
#ifdef _MSC_VER
2016-03-19 06:57:51 +13:00
#pragma warning(pop)
#endif
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
template class DVAPI TSmartPointerT<TParamSet>;
template class DVAPI TDerivedSmartPointerT<TParamSet, TParam>;
#endif
typedef TDerivedSmartPointerT<TParamSet, TParam> TParamSetP;
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class TPointParamObserver {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TPointParamObserver() {}
virtual ~TPointParamObserver() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void onChange(const TParamChange &) = 0;
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------------------------
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
class TPointParam;
template class DVAPI TPersistDeclarationT<TPointParam>;
#endif
//------------------------------------------------------------------------------
class TPointParamImp;
class TDoubleParamP;
class DVAPI TPointParam final : public TParamSet {
2016-06-15 18:43:10 +12:00
PERSIST_DECLARATION(TPointParam)
TPointParamImp *m_data;
bool m_from_plugin;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TPointParam(const TPointD &p = TPointD(), bool from_plugin = false);
TPointParam(const TPointParam &src);
~TPointParam();
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
TParam *clone() const override { return new TPointParam(*this); }
void copy(TParam *src) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPointD getDefaultValue() const;
TPointD getValue(double frame) const;
bool setValue(double frame, const TPointD &p);
void setDefaultValue(const TPointD &p);
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void loadData(TIStream &is) override;
void saveData(TOStream &os) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TDoubleParamP &getX();
TDoubleParamP &getY();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isFromPlugin() const { return m_from_plugin; }
2016-03-19 06:57:51 +13:00
};
DEFINE_PARAM_SMARTPOINTER(TPointParam, TPointD)
//------------------------------------------------------------------------------
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
class TPixelParam;
template class DVAPI TPersistDeclarationT<TPixelParam>;
#endif
2016-06-15 18:43:10 +12:00
class TPixelParamObserver {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TPixelParamObserver() {}
virtual ~TPixelParamObserver() {}
virtual void onChange(const TParamChange &) = 0;
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------------------------
class TPixelParamImp;
class DVAPI TPixelParam final : public TParamSet {
2016-06-15 18:43:10 +12:00
PERSIST_DECLARATION(TPixelParam)
TPixelParamImp *m_data;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TPixelParam(const TPixel32 &pix = TPixel32::Black);
TPixelParam(const TPixelParam &);
~TPixelParam();
2016-06-19 20:06:29 +12:00
TParam *clone() const override { return new TPixelParam(*this); }
void copy(TParam *src) override;
2016-06-15 18:43:10 +12:00
TPixel32 getDefaultValue() const;
TPixelD getValueD(double frame) const;
TPixel32 getValue(double frame) const;
TPixel64 getValue64(double frame) const;
TPixel32 getPremultipliedValue(double frame) const;
void setDefaultValue(const TPixel32 &pix);
bool setValueD(double frame, const TPixelD &pix);
bool setValue(double frame, const TPixel32 &pix);
bool setValue64(double frame, const TPixel64 &pix);
void enableMatte(bool on);
bool isMatteEnabled() const;
2016-06-19 20:06:29 +12:00
void loadData(TIStream &is) override;
void saveData(TOStream &os) override;
2016-06-15 18:43:10 +12:00
TDoubleParamP &getRed();
TDoubleParamP &getGreen();
TDoubleParamP &getBlue();
TDoubleParamP &getMatte();
2016-03-19 06:57:51 +13:00
};
DEFINE_PARAM_SMARTPOINTER(TPixelParam, TPixel32)
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class TRangeParamObserver {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TRangeParamObserver() {}
virtual ~TRangeParamObserver() {}
virtual void onChange(const TParamChange &) = 0;
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------------------------
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
class TRangeParam;
template class DVAPI TPersistDeclarationT<TRangeParam>;
#endif
//------------------------------------------------------------------------------
class TRangeParamImp;
class TDoubleParamP;
class DVAPI TRangeParam final : public TParamSet {
2016-06-15 18:43:10 +12:00
PERSIST_DECLARATION(TRangeParam)
TRangeParamImp *m_data;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TRangeParam(const DoublePair &range = DoublePair(0, 0));
TRangeParam(const TRangeParam &src);
~TRangeParam();
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
TParam *clone() const override { return new TRangeParam(*this); }
void copy(TParam *src) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DoublePair getDefaultValue() const;
DoublePair getValue(double frame) const;
bool setValue(double frame, const DoublePair &v);
void setDefaultValue(const DoublePair &v);
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void loadData(TIStream &is) override;
void saveData(TOStream &os) override;
2016-06-15 18:43:10 +12:00
int getKeyframeCount() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TDoubleParamP &getMin();
TDoubleParamP &getMax();
2016-03-19 06:57:51 +13:00
};
DEFINE_PARAM_SMARTPOINTER(TRangeParam, DoublePair)
#endif