Gnash
0.8.10
|
00001 // FillStyle.h: variant fill styles 00002 // 00003 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 00004 // Free Software Foundation, Inc. 00005 // 00006 // This program is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 00020 #ifndef GNASH_FILL_STYLE_H 00021 #define GNASH_FILL_STYLE_H 00022 00023 #include <boost/variant.hpp> 00024 #include <vector> 00025 #include <iosfwd> 00026 #include <boost/intrusive_ptr.hpp> 00027 #include <cassert> 00028 00029 #include "SWFMatrix.h" 00030 #include "SWF.h" 00031 #include "RGBA.h" 00032 00033 namespace gnash { 00034 class movie_definition; 00035 class CachedBitmap; 00036 } 00037 00038 namespace gnash { 00039 00040 class GradientRecord 00041 { 00042 public: 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 00203 const GradientRecords &getRecords() const { 00204 return _gradients; 00205 } 00206 00208 size_t recordCount() const { 00209 return _gradients.size(); 00210 } 00211 00213 // 00215 const GradientRecord& record(size_t i) const { 00216 assert(i < _gradients.size()); 00217 return _gradients[i]; 00218 } 00219 00221 // 00223 void setFocalPoint(double d); 00224 00226 // 00228 double focalPoint() const { 00229 return _focalPoint; 00230 } 00231 00232 SpreadMode spreadMode; 00233 InterpolationMode interpolation; 00234 00235 private: 00236 00237 double _focalPoint; 00238 GradientRecords _gradients; 00239 Type _type; 00240 SWFMatrix _matrix; 00241 }; 00242 00244 // 00246 struct DSOEXPORT SolidFill 00247 { 00248 public: 00249 00251 explicit SolidFill(const rgba& c) 00252 : 00253 _color(c) 00254 { } 00255 00257 SolidFill(const SolidFill& other) 00258 : 00259 _color(other._color) 00260 { } 00261 00263 void setLerp(const SolidFill& a, const SolidFill& b, double ratio) { 00264 _color = lerp(a.color(), b.color(), ratio); 00265 } 00266 00268 rgba color() const { 00269 return _color; 00270 } 00271 00272 private: 00273 rgba _color; 00274 }; 00275 00277 // 00281 class DSOEXPORT FillStyle 00282 { 00283 public: 00284 00285 typedef boost::variant<BitmapFill, SolidFill, GradientFill> Fill; 00286 00288 // 00292 template<typename T> FillStyle(const T& f) : fill(f) {} 00293 00294 FillStyle(const FillStyle& other) 00295 : 00296 fill(other.fill) 00297 { } 00298 00299 Fill fill; 00300 00301 }; 00302 00304 // 00307 void setLerp(FillStyle& f, const FillStyle& a, const FillStyle& b, double t); 00308 00310 DSOEXPORT std::ostream& operator<<(std::ostream& os, 00311 const BitmapFill::SmoothingPolicy& p); 00312 00314 std::ostream& operator<<(std::ostream& os, const FillStyle& fs); 00315 00317 std::ostream& operator<<(std::ostream& o, GradientFill::Type t); 00318 00320 std::ostream& operator<<(std::ostream& o, GradientFill::SpreadMode t); 00321 00323 std::ostream& operator<<(std::ostream& o, GradientFill::InterpolationMode t); 00324 00325 } // namespace gnash 00326 00327 #endif 00328 00329 // Local Variables: 00330 // mode: C++ 00331 // indent-tabs-mode: nil 00332 // End: