Gnash 0.8.10dev
|
00001 // FillStyle.h: variant fill styles 00002 // 00003 // Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 #ifndef GNASH_FILL_STYLE_H 00020 #define GNASH_FILL_STYLE_H 00021 00022 #include <boost/variant.hpp> 00023 #include <vector> 00024 #include <iosfwd> 00025 #include <boost/intrusive_ptr.hpp> 00026 #include <cassert> 00027 00028 #include "SWFMatrix.h" 00029 #include "SWF.h" 00030 #include "RGBA.h" 00031 00032 namespace gnash { 00033 class movie_definition; 00034 class CachedBitmap; 00035 } 00036 00037 namespace gnash { 00038 00039 class GradientRecord 00040 { 00041 public: 00042 00043 GradientRecord(boost::uint8_t ratio, const rgba& color) 00044 : 00045 ratio(ratio), 00046 color(color) 00047 {} 00048 00049 //data: 00050 boost::uint8_t ratio; 00051 rgba color; 00052 }; 00053 00055 // 00058 // 00062 // 00065 // 00067 // 00070 class DSOEXPORT BitmapFill 00071 { 00072 public: 00073 00075 enum SmoothingPolicy { 00076 SMOOTHING_UNSPECIFIED, 00077 SMOOTHING_ON, 00078 SMOOTHING_OFF 00079 }; 00080 00082 // 00085 enum Type { 00086 CLIPPED, 00087 TILED 00088 }; 00089 00091 // 00093 BitmapFill(Type t, const CachedBitmap* bi, const SWFMatrix& m, 00094 SmoothingPolicy pol); 00095 00097 BitmapFill(SWF::FillType t, movie_definition* md, boost::uint16_t id, 00098 const SWFMatrix& m); 00099 00101 ~BitmapFill(); 00102 00104 // 00107 BitmapFill(const BitmapFill& other); 00108 00109 BitmapFill& operator=(const BitmapFill& other); 00110 00112 void setLerp(const BitmapFill& a, const BitmapFill& b, double ratio); 00113 00115 // 00117 Type type() const { 00118 return _type; 00119 } 00120 00122 SmoothingPolicy smoothingPolicy() const { 00123 return _smoothingPolicy; 00124 } 00125 00127 const CachedBitmap* bitmap() const; 00128 00130 const SWFMatrix& matrix() const { 00131 return _matrix; 00132 } 00133 00134 private: 00135 00136 Type _type; 00137 00138 SmoothingPolicy _smoothingPolicy; 00139 00140 SWFMatrix _matrix; 00141 00143 mutable boost::intrusive_ptr<const CachedBitmap> _bitmapInfo; 00144 00146 movie_definition* _md; 00147 00148 // The id of the tag containing the bitmap 00149 boost::uint16_t _id; 00150 }; 00151 00153 class DSOEXPORT GradientFill 00154 { 00155 public: 00156 00158 // 00160 enum Type { 00161 LINEAR, 00162 RADIAL 00163 }; 00164 00165 enum SpreadMode { 00166 PAD, 00167 REPEAT, 00168 REFLECT 00169 }; 00170 00171 enum InterpolationMode { 00172 RGB, 00173 LINEAR_RGB 00174 }; 00175 00176 typedef std::vector<GradientRecord> GradientRecords; 00177 00179 // 00181 // 00184 GradientFill(Type t, const SWFMatrix& m, 00185 const GradientRecords& = GradientRecords()); 00186 00187 Type type() const { 00188 return _type; 00189 } 00190 00191 const SWFMatrix& matrix() const { 00192 return _matrix; 00193 } 00194 00196 void setLerp(const GradientFill& a, const GradientFill& b, double ratio); 00197 00198 void setRecords(const GradientRecords& recs) { 00199 assert(recs.size() > 1); 00200 _gradients = recs; 00201 } 00202 00204 size_t recordCount() const { 00205 return _gradients.size(); 00206 } 00207 00209 // 00211 const GradientRecord& record(size_t i) const { 00212 assert(i < _gradients.size()); 00213 return _gradients[i]; 00214 } 00215 00217 // 00219 void setFocalPoint(double d); 00220 00222 // 00224 double focalPoint() const { 00225 return _focalPoint; 00226 } 00227 00228 SpreadMode spreadMode; 00229 InterpolationMode interpolation; 00230 00231 private: 00232 00233 double _focalPoint; 00234 GradientRecords _gradients; 00235 Type _type; 00236 SWFMatrix _matrix; 00237 }; 00238 00240 // 00242 struct DSOEXPORT SolidFill 00243 { 00244 public: 00245 00247 explicit SolidFill(const rgba& c) 00248 : 00249 _color(c) 00250 {} 00251 00253 SolidFill(const SolidFill& other) 00254 : 00255 _color(other._color) 00256 {} 00257 00259 void setLerp(const SolidFill& a, const SolidFill& b, double ratio) { 00260 _color.set_lerp(a.color(), b.color(), ratio); 00261 } 00262 00264 rgba color() const { 00265 return _color; 00266 } 00267 00268 private: 00269 rgba _color; 00270 }; 00271 00273 // 00277 class DSOEXPORT FillStyle 00278 { 00279 public: 00280 00281 typedef boost::variant<BitmapFill, SolidFill, GradientFill> Fill; 00282 00284 // 00288 template<typename T> FillStyle(const T& f) : fill(f) {} 00289 00290 FillStyle(const FillStyle& other) 00291 : 00292 fill(other.fill) 00293 {} 00294 00295 Fill fill; 00296 00297 }; 00298 00300 // 00303 void setLerp(FillStyle& f, const FillStyle& a, const FillStyle& b, double t); 00304 00305 DSOEXPORT std::ostream& operator<<(std::ostream& os, 00306 const BitmapFill::SmoothingPolicy& p); 00307 00308 } // namespace gnash 00309 00310 #endif 00311 00312 00313 // Local Variables: 00314 // mode: C++ 00315 // indent-tabs-mode: t 00316 // End: