1 #pragma once 2 3 #ifndef _RASTERSTYLES_H_ 4 #define _RASTERSTYLES_H_ 5 6 #include "tcolorstyles.h" 7 8 #include "traster.h" 9 10 #include <QCoreApplication> 11 12 class TStroke; 13 class TRegion; 14 class TStrokeProp; 15 class TRegionProp; 16 class TInputStreamInterface; 17 class TOutputStreamInterface; 18 19 //============================================================================= 20 21 class TAirbrushRasterStyle : public TColorStyle, public TRasterStyleFx { 22 protected: 23 TPixel32 m_color; 24 double m_blur; 25 26 public: TAirbrushRasterStyle(const TPixel32 & color,double blur)27 TAirbrushRasterStyle(const TPixel32 &color, double blur) 28 : m_color(color), m_blur(blur) {} 29 30 TColorStyle *clone() const override; 31 32 public: 33 // n.b. per un plain color: isRasterStyle() == true, ma getRasterStyleFx() = 0 34 makeStrokeProp(const TStroke * stroke)35 TStrokeProp *makeStrokeProp(const TStroke *stroke) override { return 0; } makeRegionProp(const TRegion * region)36 TRegionProp *makeRegionProp(const TRegion *region) override { return 0; } getRasterStyleFx()37 TRasterStyleFx *getRasterStyleFx() override { return this; } 38 isRegionStyle()39 bool isRegionStyle() const override { return false; } isStrokeStyle()40 bool isStrokeStyle() const override { return false; } isRasterStyle()41 bool isRasterStyle() const override { return true; } getEnlargement(int & borderIn,int & borderOut)42 void getEnlargement(int &borderIn, int &borderOut) const override { 43 borderIn = tceil(2 * m_blur); 44 borderOut = tceil(m_blur); 45 } 46 hasMainColor()47 bool hasMainColor() const override { return true; } getMainColor()48 TPixel32 getMainColor() const override { return m_color; } setMainColor(const TPixel32 & color)49 void setMainColor(const TPixel32 &color) override { m_color = color; } 50 getColorParamCount()51 int getColorParamCount() const override { return 1; } getColorParamValue(int index)52 TPixel32 getColorParamValue(int index) const override { return m_color; } setColorParamValue(int index,const TPixel32 & color)53 void setColorParamValue(int index, const TPixel32 &color) override { 54 m_color = color; 55 } 56 getDescription()57 QString getDescription() const override { 58 return QCoreApplication::translate("TAirbrushRasterStyle", "Airbrush"); 59 } 60 getParamCount()61 int getParamCount() const override { return 1; } getParamType(int index)62 TColorStyle::ParamType getParamType(int index) const override { 63 assert(index == 0); 64 return TColorStyle::DOUBLE; 65 } 66 getParamNames(int index)67 QString getParamNames(int index) const override { 68 assert(index == 0); 69 return QCoreApplication::translate("TAirbrushRasterStyle", "Blur value"); 70 } getParamRange(int index,double & min,double & max)71 void getParamRange(int index, double &min, double &max) const override { 72 assert(index == 0); 73 min = 0; 74 max = 30; 75 } getParamValue(TColorStyle::double_tag,int index)76 double getParamValue(TColorStyle::double_tag, int index) const override { 77 assert(index == 0); 78 return m_blur; 79 } setParamValue(int index,double value)80 void setParamValue(int index, double value) override { 81 assert(index == 0); 82 m_blur = value; 83 } 84 85 void invalidateIcon(); 86 87 // const TRaster32P &getIcon(const TDimension &d) {assert(false);return 88 // (TRaster32P)0;} 89 getAverageColor()90 TPixel32 getAverageColor() const override { return m_color; } 91 getTagId()92 int getTagId() const override { return 1150; } 93 isInkStyle()94 bool isInkStyle() const override { return true; } isPaintStyle()95 bool isPaintStyle() const override { return false; } 96 97 bool compute(const Params ¶ms) const override; 98 99 protected: 100 void makeIcon(const TDimension &d) override; 101 102 void arrangeIcon(const TDimension &d, const TRasterP &normalIc); 103 104 void loadData(TInputStreamInterface &) override; 105 void saveData(TOutputStreamInterface &) const override; 106 107 // per la compatibilita' con il passato loadData(int oldId,TInputStreamInterface &)108 void loadData(int oldId, TInputStreamInterface &) override{}; 109 }; 110 111 //============================================================================= 112 113 class TBlendRasterStyle final : public TAirbrushRasterStyle { 114 public: TBlendRasterStyle(const TPixel32 & color,double blur)115 TBlendRasterStyle(const TPixel32 &color, double blur) 116 : TAirbrushRasterStyle(color, blur) {} 117 TColorStyle *clone() const override; 118 getTagId()119 int getTagId() const override { return 1160; } 120 getDescription()121 QString getDescription() const override { 122 return QCoreApplication::translate("TBlendRasterStyle", "Blend"); 123 } 124 125 void makeIcon(const TDimension &d) override; 126 127 bool compute(const TRasterStyleFx::Params ¶ms) const override; 128 129 private: 130 double computeFactor(const TRasterStyleFx::Params ¶ms) const; 131 }; 132 133 //============================================================================= 134 135 class TNoColorRasterStyle final : public TColorStyle, TRasterStyleFx { 136 public: TNoColorRasterStyle()137 TNoColorRasterStyle() {} clone()138 TColorStyle *clone() const override { return new TNoColorRasterStyle(*this); } 139 140 // n.b. per un plain color: isRasterStyle() == true, ma getRasterStyleFx() = 0 141 makeStrokeProp(const TStroke * stroke)142 TStrokeProp *makeStrokeProp(const TStroke *stroke) override { return 0; } makeRegionProp(const TRegion * region)143 TRegionProp *makeRegionProp(const TRegion *region) override { return 0; } getRasterStyleFx()144 TRasterStyleFx *getRasterStyleFx() override { return this; } 145 isRegionStyle()146 bool isRegionStyle() const override { return false; } isStrokeStyle()147 bool isStrokeStyle() const override { return false; } isRasterStyle()148 bool isRasterStyle() const override { return true; } 149 getDescription()150 QString getDescription() const override { 151 return QCoreApplication::translate("TNoColorRasterStyle", "Markup"); 152 } 153 hasMainColor()154 bool hasMainColor() { return false; } 155 // TPixel32 getMainColor() const {return m_color;} 156 // void setMainColor(const TPixel32 &color) {m_color = color;} 157 getColorParamCount()158 int getColorParamCount() const override { return 0; } getColorParamValue(int index)159 TPixel32 getColorParamValue(int index) const override { 160 assert(false); 161 return TPixel32(); 162 } setColorParamValue(int index,const TPixel32 & color)163 void setColorParamValue(int index, const TPixel32 &color) override { 164 assert(false); 165 } 166 getTagId()167 int getTagId() const override { return 1151; } 168 isInkStyle()169 bool isInkStyle() const override { return true; } isPaintStyle()170 bool isPaintStyle() const override { return true; } 171 compute(const Params & params)172 bool compute(const Params ¶ms) const override { return false; } 173 174 protected: 175 void makeIcon(const TDimension &d) override; 176 loadData(TInputStreamInterface &)177 void loadData(TInputStreamInterface &) override{}; saveData(TOutputStreamInterface &)178 void saveData(TOutputStreamInterface &) const override{}; 179 180 // per la compatibilita' con il passato loadData(int oldId,TInputStreamInterface &)181 void loadData(int oldId, TInputStreamInterface &) override{}; 182 }; 183 184 #endif 185