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(std::uint8_t ratio, rgba color)
44  :
45  ratio(ratio),
46  color(std::move(color))
47  { }
48 
49  //data:
50  std::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  //
94  SmoothingPolicy pol);
95 
97  BitmapFill(SWF::FillType t, movie_definition* md, std::uint16_t id,
98  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  std::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(rgba c)
252  :
253  _color(std::move(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 
299  Fill fill;
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:
Definition: GnashKey.h:147
InterpolationMode
Definition: FillStyle.h:171
Definition: GnashKey.h:150
Client program&#39;s interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
const GradientRecord & record(size_t i) const
Query the GradientRecord at the specified index.
Definition: FillStyle.h:215
GradientRecord(std::uint8_t ratio, rgba color)
Definition: FillStyle.h:43
VGPaint fill
Definition: testr_gtk.cpp:86
SmoothingPolicy smoothingPolicy() const
Get the smoothing policy of this BitmapFill.
Definition: FillStyle.h:122
Type
The type of GradientFill.
Definition: FillStyle.h:160
Definition: SWFMatrix.h:53
A SolidFill containing one color.
Definition: FillStyle.h:246
FillType
SWF fill style types. Symbolic names copied from Ming.
Definition: SWF.h:1520
SmoothingPolicy
How to smooth the bitmap.
Definition: FillStyle.h:75
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
const SWFMatrix & matrix() const
Get the matrix of this BitmapFill.
Definition: FillStyle.h:130
std::uint8_t ratio
Definition: FillStyle.h:50
Definition: GnashKey.h:149
Definition: GnashKey.h:152
Definition: FillStyle.h:161
Definition: GnashKey.h:161
rgba color
Definition: FillStyle.h:51
double focalPoint() const
Get the focal point of this GradientFill.
Definition: FillStyle.h:228
void setLerp(const SolidFill &a, const SolidFill &b, double ratio)
Set this fill to a lerp of two other SolidFills.
Definition: FillStyle.h:263
SolidFill(rgba c)
Construct a SolidFill.
Definition: FillStyle.h:251
Definition: FillStyle.h:167
A GradientFill.
Definition: FillStyle.h:153
SpreadMode spreadMode
Definition: FillStyle.h:232
Type type() const
Get the Type of this BitmapFill.
Definition: FillStyle.h:117
std::ostream & operator<<(std::ostream &o, const URL &u)
Definition: URL.cpp:447
Definition: GnashKey.h:166
Definition: FillStyle.h:166
T lerp(T a, T b, T f)
Definition: GnashNumeric.h:85
Definition: FillStyle.h:40
FillStyle describes the various fill styles for shapes.
Definition: FillStyle.h:281
void setRecords(const GradientRecords &recs)
Definition: FillStyle.h:198
size_t recordCount() const
Get the number of records in this GradientFill.
Definition: FillStyle.h:208
FillStyle(const FillStyle &other)
Definition: FillStyle.h:294
Definition: GnashKey.h:148
#define DSOEXPORT
Definition: dsodefs.h:55
InterpolationMode interpolation
Definition: FillStyle.h:233
Definition: FillStyle.h:172
const SWFMatrix & matrix() const
Definition: FillStyle.h:191
Definition: GnashKey.h:132
Definition: FillStyle.h:77
Type
Whether the fill is tiled or clipped.
Definition: FillStyle.h:85
Definition: GnashKey.h:162
Definition: GnashKey.h:155
std::vector< GradientRecord > GradientRecords
Definition: FillStyle.h:176
SpreadMode
Definition: FillStyle.h:165
FillStyle(const T &f)
Construct a FillStyle from any Fill.
Definition: FillStyle.h:292
Definition: GnashKey.h:159
Type type() const
Definition: FillStyle.h:187
boost::variant< BitmapFill, SolidFill, GradientFill > Fill
Definition: FillStyle.h:285
SolidFill(const SolidFill &other)
Copy a SolidFill.
Definition: FillStyle.h:257
A CachedBitmap is created by the renderer in a format of its choosing.
Definition: CachedBitmap.h:37
const GradientRecords & getRecords() const
Definition: FillStyle.h:203
rgba color() const
Get the color of the fill.
Definition: FillStyle.h:268
void setLerp(FillStyle &f, const FillStyle &a, const FillStyle &b, double t)
Set the FillStyle to a lerp of a and b.
Definition: FillStyle.cpp:221
A BitmapFill.
Definition: FillStyle.h:70
Definition: FillStyle.h:86
Fill fill
Definition: FillStyle.h:299
A basic RGBA type.
Definition: RGBA.h:35