#pragma once #ifndef TCOLORSTYLES_H #define TCOLORSTYLES_H // TnzCore includes #include "tfilepath.h" #include "traster.h" // Qt includes #include #undef DVAPI #undef DVVAR #ifdef TVRENDER_EXPORTS #define DVAPI DV_EXPORT_API #define DVVAR DV_EXPORT_VAR #else #define DVAPI DV_IMPORT_API #define DVVAR DV_IMPORT_VAR #endif //================================================= // Forward declarations class TStroke; class TRegion; class TStrokeProp; class TRegionProp; class TVectorRenderData; class TInputStreamInterface; class TOutputStreamInterface; class TRasterStyleFx; class QStringList; //================================================= //************************************************************************ // TRasterStyleFx definition //************************************************************************ class DVAPI TRasterStyleFx { public: struct Params { TRasterP m_r; TPoint m_p; TRasterP m_rOrig; int m_colorIndex; int m_frame; public: Params(const TRasterP &r, const TPoint &p, const TRasterP &rOrig, int index, int frame) : m_r(r), m_p(p), m_rOrig(rOrig), m_colorIndex(index), m_frame(frame) { assert(m_r); } }; public: virtual ~TRasterStyleFx() {} virtual bool isInkStyle() const = 0; virtual bool isPaintStyle() const = 0; virtual bool inkFxNeedRGBMRaster() const { return false; } virtual bool compute(const Params ¶ms) const = 0; virtual void getEnlargement(int &borderIn, int &borderOut) const { borderIn = borderOut = 0; } }; //************************************************************************ // TColorStyle definition //************************************************************************ /*! \brief Abstract class representing a color style in a Toonz palette. */ class DVAPI TColorStyle : public TSmartObject { public: //! Helper class to declare color styles class Declaration { public: Declaration(TColorStyle *style) { declare(style); } }; enum ParamType { BOOL, //!< Boolean parameter type. INT, //!< Integer parameter type. ENUM, //!< Enum parameter type (maps to integer values). DOUBLE, //!< Double parameter type (getParamType() default). FILEPATH //!< TFilePath parameter type. }; struct double_tag {}; struct bool_tag {}; struct int_tag {}; struct TFilePath_tag {}; struct PickedPosition { TPoint pos = TPoint(); int frame = 0; PickedPosition(TPoint _pos = TPoint(), int _frame = 0) : pos(_pos), frame(_frame) {} inline bool operator==(const PickedPosition &p) const { return (this->pos == p.pos) && (this->frame == p.frame); } inline bool operator!=(const PickedPosition &p) const { return (this->pos != p.pos) || (this->frame != p.frame); } }; private: std::wstring m_name; //!< User-define style name. std::wstring m_globalName; //!< User-define style \a global name. std::wstring m_originalName; //!< If the style is copied from studio palette, //! its original name is stored int m_versionNumber; //!< Style's version number. unsigned int m_flags; //!< Style attributes. bool m_enabled; //!< Style's \a enabled status. bool m_isEditedFromOriginal; //keyframe styles \p a and \p b, it calculates their linear interpolation at parameter \p t and assigns the result to this style instance. \param a Style value at parameter t = 0. \param b Style value at parameter t = 1. \param t Interpolation parameter. */ void assignBlend(const TColorStyle &a, const TColorStyle &b, double t); //!< Assigns the linear interpolation between the //! supplied styles. // Description-related functions /*! \detail For example for a stroke style we have "Constant", "Chain", "Rope", "Tulle", etc... */ virtual QString getDescription() const = 0; //!< Return a brief description of the style. virtual QString getParamNames(int index) const; //!< Return the string that identifies the \a index-th parameter. // I/O-related functions virtual int getTagId() const = 0; //!< Returns an unique number representing the style. virtual void getObsoleteTagIds(std::vector &) const {}; //!< \deprecated void save(TOutputStreamInterface &) const; //!< Calls the local //! implementation of saveData() //! passing it also the name and //! the tagId of the style. static TColorStyle *load(TInputStreamInterface &); //!< Loads the style from //! disk. Calls the local //! implementation of //! loadData(). static TColorStyle *create( int tagId); //!< Creates a new style with identifier equal to \a tagId. static void declare( TColorStyle *style); //!< Puts the style in the table of actual styles. static void getAllTags(std::vector &tags); // Misc functions /*! \detail It is used when updates must be done after changes or creation of new styles. */ void invalidateIcon() { m_validIcon = false; } //!< Sets a flag that defines the style's icon validity. virtual const TRaster32P &getIcon( const TDimension &d); //!< Returns an image representing the style. bool isEnabled() const { return m_enabled; } //!< Returns whether the style can be used. void enable(bool on) { m_enabled = on; } //!< Sets the style's \a enabled status int getVersionNumber() const { return m_versionNumber; } //!< Returns the version number of the style. protected: virtual void makeIcon(const TDimension &d); virtual void loadData(TInputStreamInterface &) = 0; virtual void saveData(TOutputStreamInterface &) const = 0; virtual void loadData(int, TInputStreamInterface &) { } //!< \deprecated Backward compatibility void updateVersionNumber(); protected: TColorStyle &operator=( const TColorStyle &other); //!< Copies another style \a except its icon }; //-------------------------------------------------------------------------- #ifdef _WIN32 template class DVAPI TSmartPointerT; #endif typedef TSmartPointerT TColorStyleP; #endif // TCOLORSTYLES_H