1 #pragma once
2 
3 #ifndef MYPAINTBRUSHSTYLE_H
4 #define MYPAINTBRUSHSTYLE_H
5 
6 #include "mypaint.h"
7 
8 // TnzCore includes
9 #include "imagestyles.h"
10 
11 #undef DVAPI
12 #undef DVVAR
13 
14 #ifdef TOONZLIB_EXPORTS
15 #define DVAPI DV_EXPORT_API
16 #define DVVAR DV_EXPORT_VAR
17 #else
18 #define DVAPI DV_IMPORT_API
19 #define DVVAR DV_IMPORT_VAR
20 #endif
21 
22 //**********************************************************************************
23 //    TMyPaintBrushStyle declaration
24 //**********************************************************************************
25 
26 class DVAPI TMyPaintBrushStyle final : public TColorStyle, TImageStyle {
27 private:
28   TFilePath m_path;
29   TFilePath m_fullpath;
30   mypaint::Brush m_brushOriginal;
31   mypaint::Brush m_brushModified;
32   TRasterP m_preview;
33   TPixel32 m_color;
34 
35   std::map<MyPaintBrushSetting, float> m_baseValues;
36 
37   TFilePath decodePath(const TFilePath &path) const;
38   void loadBrush(const TFilePath &path);
39 
40 public:
41   TMyPaintBrushStyle();
42   TMyPaintBrushStyle(const TFilePath &path);
43   TMyPaintBrushStyle(const TMyPaintBrushStyle &other);
44   ~TMyPaintBrushStyle();
45 
clone()46   TColorStyle *clone() const override { return new TMyPaintBrushStyle(*this); }
47 
48   TColorStyle &copy(const TColorStyle &other) override;
49 
50   static std::string getBrushType();
51   static TFilePathSet getBrushesDirs();
52 
getPath()53   const TFilePath &getPath() const { return m_path; }
getBrush()54   const mypaint::Brush &getBrush() const { return m_brushModified; }
getPreview()55   const TRasterP &getPreview() const { return m_preview; }
56 
makeStrokeProp(const TStroke *)57   TStrokeProp *makeStrokeProp(const TStroke * /* stroke */) override {
58     return 0;
59   }
makeRegionProp(const TRegion *)60   TRegionProp *makeRegionProp(const TRegion * /* region */) override {
61     return 0;
62   }
isRegionStyle()63   bool isRegionStyle() const override { return false; }
isStrokeStyle()64   bool isStrokeStyle() const override { return true; }
65 
hasMainColor()66   bool hasMainColor() const override { return true; }
getMainColor()67   TPixel32 getMainColor() const override { return m_color; }
setMainColor(const TPixel32 & color)68   void setMainColor(const TPixel32 &color) override { m_color = color; }
69 
getTagId()70   int getTagId() const override { return 4001; }
71 
72   QString getDescription() const override;
73 
74   void setBaseValue(MyPaintBrushSetting id, bool enable, float value);
75   void resetBaseValues();
76 
setBaseValue(MyPaintBrushSetting id,float value)77   void setBaseValue(MyPaintBrushSetting id, float value) {
78     setBaseValue(id, true, value);
79   }
80 
setBaseValueEnabled(MyPaintBrushSetting id,bool enable)81   void setBaseValueEnabled(MyPaintBrushSetting id, bool enable) {
82     setBaseValue(id, enable, getBaseValue(id));
83   }
84 
getBaseValues()85   const std::map<MyPaintBrushSetting, float> getBaseValues() const {
86     return m_baseValues;
87   }
88 
getBaseValue(MyPaintBrushSetting id)89   float getBaseValue(MyPaintBrushSetting id) const {
90     std::map<MyPaintBrushSetting, float>::const_iterator i =
91         m_baseValues.find(id);
92     return i == m_baseValues.end() ? m_brushOriginal.getBaseValue(id)
93                                    : i->second;
94   }
95 
getBaseValueEnabled(MyPaintBrushSetting id)96   bool getBaseValueEnabled(MyPaintBrushSetting id) const {
97     std::map<MyPaintBrushSetting, float>::const_iterator i =
98         m_baseValues.find(id);
99     return i != m_baseValues.end();
100   }
101 
102   int getParamCount() const override;
103   QString getParamNames(int index) const override;
104   ParamType getParamType(int index) const override;
105   bool hasParamDefault(int index) const override;
106   void setParamDefault(int index) override;
107   bool isParamDefault(int index) const override;
108   void getParamRange(int index, double &min, double &max) const override;
109   void setParamValue(int index, double value) override;
110   double getParamValue(double_tag, int index) const override;
111 
112 protected:
113   void makeIcon(const TDimension &d) override;
114   void loadData(TInputStreamInterface &) override;
115   void saveData(TOutputStreamInterface &) const override;
116 };
117 
118 #endif
119