Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef GNASH_FILL_STYLE_H
00019 #define GNASH_FILL_STYLE_H
00020
00021 #include <boost/variant.hpp>
00022 #include <vector>
00023 #include <iosfwd>
00024 #include <boost/optional.hpp>
00025 #include <boost/intrusive_ptr.hpp>
00026 #include <cassert>
00027
00028 #include "SWFMatrix.h"
00029 #include "CachedBitmap.h"
00030 #include "SWF.h"
00031 #include "RGBA.h"
00032
00033 namespace gnash {
00034
00035 class SWFStream;
00036 class movie_definition;
00037 class Renderer;
00038 class RunResources;
00039
00040 class GradientRecord
00041 {
00042 public:
00043
00044 GradientRecord(boost::uint8_t ratio, const rgba& color)
00045 :
00046 ratio(ratio),
00047 color(color)
00048 {}
00049
00050
00051 boost::uint8_t ratio;
00052 rgba color;
00053 };
00054
00055
00057
00060
00064
00066
00069 class DSOEXPORT BitmapFill
00070 {
00071 public:
00072
00074 enum SmoothingPolicy {
00075 SMOOTHING_UNSPECIFIED,
00076 SMOOTHING_ON,
00077 SMOOTHING_OFF
00078 };
00079
00081
00084 enum Type {
00085 CLIPPED,
00086 TILED
00087 };
00088
00090
00092 BitmapFill(Type t, const CachedBitmap* bi, const SWFMatrix& m,
00093 SmoothingPolicy pol)
00094 :
00095 _type(t),
00096 _smoothingPolicy(pol),
00097 _matrix(m),
00098 _bitmapInfo(bi),
00099 _md(0),
00100 _id(0)
00101 {
00102 }
00103
00105 BitmapFill(SWF::FillType t, movie_definition* md, boost::uint16_t id,
00106 const SWFMatrix& m);
00107
00109
00112 BitmapFill(const BitmapFill& other)
00113 :
00114 _type(other._type),
00115 _smoothingPolicy(other._smoothingPolicy),
00116 _matrix(other._matrix),
00117 _bitmapInfo(other._bitmapInfo),
00118 _md(other._md),
00119 _id(other._id)
00120 {}
00121
00123 void setLerp(const BitmapFill& a, const BitmapFill& b, double ratio);
00124
00126
00128 Type type() const {
00129 return _type;
00130 }
00131
00133 SmoothingPolicy smoothingPolicy() const {
00134 return _smoothingPolicy;
00135 }
00136
00138 const CachedBitmap* bitmap() const;
00139
00141 const SWFMatrix& matrix() const {
00142 return _matrix;
00143 }
00144
00145 private:
00146
00147 Type _type;
00148
00149 SmoothingPolicy _smoothingPolicy;
00150
00151 SWFMatrix _matrix;
00152
00154 mutable boost::intrusive_ptr<const CachedBitmap> _bitmapInfo;
00155
00157 movie_definition* _md;
00158
00159
00160 boost::uint16_t _id;
00161 };
00162
00163
00165
00167 class DSOEXPORT GradientFill
00168 {
00169 public:
00170
00172
00174 enum Type {
00175 LINEAR,
00176 RADIAL
00177 };
00178
00179 enum SpreadMode {
00180 PAD,
00181 REPEAT,
00182 REFLECT
00183 };
00184
00185 typedef std::vector<GradientRecord> GradientRecords;
00186
00188
00190
00193 GradientFill(Type t, const SWFMatrix& m,
00194 const GradientRecords& = GradientRecords());
00195
00196 Type type() const {
00197 return _type;
00198 }
00199
00200 const SWFMatrix& matrix() const {
00201 return _matrix;
00202 }
00203
00205 void setLerp(const GradientFill& a, const GradientFill& b, double ratio);
00206
00207 void setRecords(const GradientRecords& recs) {
00208 assert(recs.size() > 1);
00209 _gradients = recs;
00210 }
00211
00213 size_t recordCount() const {
00214 return _gradients.size();
00215 }
00216
00218
00220 const GradientRecord& record(size_t i) const {
00221 assert(i < _gradients.size());
00222 return _gradients[i];
00223 }
00224
00226
00228 void setFocalPoint(double d);
00229
00231
00233 double focalPoint() const {
00234 return _focalPoint;
00235 }
00236
00237 SpreadMode spreadMode;
00238 SWF::InterpolationMode interpolation;
00239
00240 private:
00241
00242 double _focalPoint;
00243 GradientRecords _gradients;
00244 Type _type;
00245 SWFMatrix _matrix;
00246 };
00247
00249
00251 struct DSOEXPORT SolidFill
00252 {
00253 public:
00254
00256 explicit SolidFill(const rgba& c)
00257 :
00258 _color(c)
00259 {}
00260
00262 SolidFill(const SolidFill& other)
00263 :
00264 _color(other._color)
00265 {}
00266
00268 void setLerp(const SolidFill& a, const SolidFill& b, double ratio) {
00269 _color.set_lerp(a.color(), b.color(), ratio);
00270 }
00271
00273 rgba color() const {
00274 return _color;
00275 }
00276
00277 private:
00278 rgba _color;
00279 };
00280
00282
00286 class DSOEXPORT FillStyle
00287 {
00288 public:
00289
00290 typedef boost::variant<BitmapFill, SolidFill, GradientFill> Fill;
00291
00293
00297 template<typename T> FillStyle(const T& f) : fill(f) {}
00298
00299 FillStyle(const FillStyle& other)
00300 :
00301 fill(other.fill)
00302 {}
00303
00304 Fill fill;
00305
00306 };
00307
00309
00312 void setLerp(FillStyle& f, const FillStyle& a, const FillStyle& b, double t);
00313
00315 typedef std::pair<FillStyle, boost::optional<FillStyle> > OptionalFillPair;
00316
00318
00320 OptionalFillPair readFills(SWFStream& in, SWF::TagType t, movie_definition& m,
00321 bool readMorph);
00322
00323 DSOEXPORT std::ostream& operator<<(std::ostream& os,
00324 const BitmapFill::SmoothingPolicy& p);
00325
00326 }
00327
00328 #endif
00329
00330
00331
00332
00333
00334