• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

FillStyle.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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" // for rgba type
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     //data:
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     // The id of the tag containing the bitmap
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 } // namespace gnash
00327 
00328 #endif 
00329 
00330 
00331 // Local Variables:
00332 // mode: C++
00333 // indent-tabs-mode: t
00334 // End:

Generated on Thu Sep 30 2010 14:34:58 for Gnash by  doxygen 1.7.1