Gnash  0.8.11dev
FillStyle.h
Go to the documentation of this file.
1 // FillStyle.h: variant fill styles
2 //
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc.
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #ifndef GNASH_FILL_STYLE_H
21 #define GNASH_FILL_STYLE_H
22 
23 #include <boost/variant.hpp>
24 #include <vector>
25 #include <iosfwd>
26 #include <boost/intrusive_ptr.hpp>
27 #include <cassert>
28 
29 #include "SWFMatrix.h"
30 #include "SWF.h"
31 #include "RGBA.h"
32 
33 namespace gnash {
34  class movie_definition;
35  class CachedBitmap;
36 }
37 
38 namespace gnash {
39 
41 {
42 public:
43  GradientRecord(boost::uint8_t ratio, const rgba& color)
44  :
45  ratio(ratio),
46  color(color)
47  { }
48 
49  //data:
50  boost::uint8_t ratio;
52 };
53 
55 //
58 //
62 //
65 //
67 //
71 {
72 public:
73 
78  SMOOTHING_OFF
79  };
80 
82  //
85  enum Type {
87  TILED
88  };
89 
91  //
93  BitmapFill(Type t, const CachedBitmap* bi, const SWFMatrix& m,
94  SmoothingPolicy pol);
95 
97  BitmapFill(SWF::FillType t, movie_definition* md, boost::uint16_t id,
98  const SWFMatrix& m);
99 
101  ~BitmapFill();
102 
104  //
107  BitmapFill(const BitmapFill& other);
108 
109  BitmapFill& operator=(const BitmapFill& other);
110 
112  void setLerp(const BitmapFill& a, const BitmapFill& b, double ratio);
113 
115  //
117  Type type() const {
118  return _type;
119  }
120 
123  return _smoothingPolicy;
124  }
125 
127  const CachedBitmap* bitmap() const;
128 
130  const SWFMatrix& matrix() const {
131  return _matrix;
132  }
133 
134 private:
135 
136  Type _type;
137 
138  SmoothingPolicy _smoothingPolicy;
139 
140  SWFMatrix _matrix;
141 
143  mutable boost::intrusive_ptr<const CachedBitmap> _bitmapInfo;
144 
146  movie_definition* _md;
147 
148  // The id of the tag containing the bitmap
149  boost::uint16_t _id;
150 };
151 
154 {
155 public:
156 
158  //
160  enum Type {
162  RADIAL
163  };
164 
165  enum SpreadMode {
168  REFLECT
169  };
170 
173  LINEAR_RGB
174  };
175 
176  typedef std::vector<GradientRecord> GradientRecords;
177 
179  //
181  //
184  GradientFill(Type t, const SWFMatrix& m,
185  const GradientRecords& = GradientRecords());
186 
187  Type type() const {
188  return _type;
189  }
190 
191  const SWFMatrix& matrix() const {
192  return _matrix;
193  }
194 
196  void setLerp(const GradientFill& a, const GradientFill& b, double ratio);
197 
198  void setRecords(const GradientRecords& recs) {
199  assert(recs.size() > 1);
200  _gradients = recs;
201  }
202 
203  const GradientRecords &getRecords() const {
204  return _gradients;
205  }
206 
208  size_t recordCount() const {
209  return _gradients.size();
210  }
211 
213  //
215  const GradientRecord& record(size_t i) const {
216  assert(i < _gradients.size());
217  return _gradients[i];
218  }
219 
221  //
223  void setFocalPoint(double d);
224 
226  //
228  double focalPoint() const {
229  return _focalPoint;
230  }
231 
234 
235 private:
236 
237  double _focalPoint;
238  GradientRecords _gradients;
239  Type _type;
240  SWFMatrix _matrix;
241 };
242 
244 //
247 {
248 public:
249 
251  explicit SolidFill(const rgba& c)
252  :
253  _color(c)
254  { }
255 
257  SolidFill(const SolidFill& other)
258  :
259  _color(other._color)
260  { }
261 
263  void setLerp(const SolidFill& a, const SolidFill& b, double ratio) {
264  _color = lerp(a.color(), b.color(), ratio);
265  }
266 
268  rgba color() const {
269  return _color;
270  }
271 
272 private:
273  rgba _color;
274 };
275 
277 //
282 {
283 public:
284 
285  typedef boost::variant<BitmapFill, SolidFill, GradientFill> Fill;
286 
288  //
292  template<typename T> FillStyle(const T& f) : fill(f) {}
293 
294  FillStyle(const FillStyle& other)
295  :
296  fill(other.fill)
297  { }
298 
300 
301 };
302 
304 //
307 void setLerp(FillStyle& f, const FillStyle& a, const FillStyle& b, double t);
308 
310 DSOEXPORT std::ostream& operator<<(std::ostream& os,
312 
314 std::ostream& operator<<(std::ostream& os, const FillStyle& fs);
315 
317 std::ostream& operator<<(std::ostream& o, GradientFill::Type t);
318 
320 std::ostream& operator<<(std::ostream& o, GradientFill::SpreadMode t);
321 
323 std::ostream& operator<<(std::ostream& o, GradientFill::InterpolationMode t);
324 
325 } // namespace gnash
326 
327 #endif
328 
329 // Local Variables:
330 // mode: C++
331 // indent-tabs-mode: nil
332 // End: