drop libxv, add lsb-release
[gnash.git] / libcore / FillStyle.h
blob927a3c7c3223da3bcde8806962f3111153c33950
1 // FillStyle.h: variant fill styles
2 //
3 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef GNASH_FILL_STYLE_H
20 #define GNASH_FILL_STYLE_H
22 #include <boost/variant.hpp>
23 #include <vector>
24 #include <iosfwd>
25 #include <boost/intrusive_ptr.hpp>
26 #include <cassert>
28 #include "SWFMatrix.h"
29 #include "SWF.h"
30 #include "RGBA.h"
32 namespace gnash {
33 class movie_definition;
34 class CachedBitmap;
37 namespace gnash {
39 class GradientRecord
41 public:
43 GradientRecord(boost::uint8_t ratio, const rgba& color)
45 ratio(ratio),
46 color(color)
49 //data:
50 boost::uint8_t ratio;
51 rgba color;
55 /// A BitmapFill
57 /// BitmapFills can refer to a parsed bitmap tag or be constructed from
58 /// bitmap data. They are used for Bitmap characters.
60 /// Presently all members are immutable after construction. It is of course
61 /// possible to change the appearance of the fill by changing the CachedBitmap
62 /// it refers to.
64 /// Special member functions (ctor, dtor etc) are not inlined to avoid
65 /// requiring the definition of movie_definition.
67 /// TODO: check the following:
69 /// It may be necessary to allow setting the smoothing policy; the use of
70 /// this should certainly be extended to non-static BitmapFills.
71 class DSOEXPORT BitmapFill
73 public:
75 /// How to smooth the bitmap.
76 enum SmoothingPolicy {
77 SMOOTHING_UNSPECIFIED,
78 SMOOTHING_ON,
79 SMOOTHING_OFF
82 /// Whether the fill is tiled or clipped.
84 /// Clipped fills use the edge pixels to fill any area outside the bounds
85 /// of the image.
86 enum Type {
87 CLIPPED,
88 TILED
91 /// Construct a BitmapFill from arbitrary bitmap data.
93 /// TODO: check the smoothing policy here!
94 BitmapFill(Type t, const CachedBitmap* bi, const SWFMatrix& m,
95 SmoothingPolicy pol);
97 /// Construct a static BitmapFill using a SWF tag.
98 BitmapFill(SWF::FillType t, movie_definition* md, boost::uint16_t id,
99 const SWFMatrix& m);
101 /// Destructor
102 ~BitmapFill();
104 /// Copy a BitmapFill
106 /// The copied BitmapFill refers to the same bitmap id in the same
107 /// movie_definition as the original.
108 BitmapFill(const BitmapFill& other);
110 BitmapFill& operator=(const BitmapFill& other);
112 /// Set this fill to a lerp of two other BitmapFills.
113 void setLerp(const BitmapFill& a, const BitmapFill& b, double ratio);
115 /// Get the Type of this BitmapFill
117 /// BitmapFills are either tiled or clipped.
118 Type type() const {
119 return _type;
122 /// Get the smoothing policy of this BitmapFill.
123 SmoothingPolicy smoothingPolicy() const {
124 return _smoothingPolicy;
127 /// Get the actual Bitmap data.
128 const CachedBitmap* bitmap() const;
130 /// Get the matrix of this BitmapFill.
131 const SWFMatrix& matrix() const {
132 return _matrix;
135 private:
137 Type _type;
139 SmoothingPolicy _smoothingPolicy;
141 SWFMatrix _matrix;
143 /// A Bitmap, used for dynamic fills and to cache parsed bitmaps.
144 mutable boost::intrusive_ptr<const CachedBitmap> _bitmapInfo;
146 /// The movie definition containing the bitmap
147 movie_definition* _md;
149 // The id of the tag containing the bitmap
150 boost::uint16_t _id;
153 /// A GradientFill
155 /// TODO: clean this up!
156 class DSOEXPORT GradientFill
158 public:
160 /// The type of GradientFill
162 /// A Focal fill is a gradient fill with a focal point.
163 enum Type {
164 LINEAR,
165 RADIAL
168 enum SpreadMode {
169 PAD,
170 REPEAT,
171 REFLECT
174 typedef std::vector<GradientRecord> GradientRecords;
176 /// Construct a GradientFill
178 /// Optionally the records can be passed here.
180 /// The actual matrix of the gradient depends on the type; the constructor
181 /// handles this, and users should just pass the user matrix.
182 GradientFill(Type t, const SWFMatrix& m,
183 const GradientRecords& = GradientRecords());
185 Type type() const {
186 return _type;
189 const SWFMatrix& matrix() const {
190 return _matrix;
193 /// Set this fill to a lerp of two other GradientFills.
194 void setLerp(const GradientFill& a, const GradientFill& b, double ratio);
196 void setRecords(const GradientRecords& recs) {
197 assert(recs.size() > 1);
198 _gradients = recs;
201 /// Get the number of records in this GradientFill
202 size_t recordCount() const {
203 return _gradients.size();
206 /// Query the GradientRecord at the specified index
208 /// There are recordCount() records.
209 const GradientRecord& record(size_t i) const {
210 assert(i < _gradients.size());
211 return _gradients[i];
214 /// Set the focal point.
216 /// Value will be clamped to the range -1..1; callers don't need to check.
217 void setFocalPoint(double d);
219 /// Get the focal point of this GradientFill
221 /// If the focal point is 0.0, it is a simple radial fill.
222 double focalPoint() const {
223 return _focalPoint;
226 SpreadMode spreadMode;
227 SWF::InterpolationMode interpolation;
229 private:
231 double _focalPoint;
232 GradientRecords _gradients;
233 Type _type;
234 SWFMatrix _matrix;
237 /// A SolidFill containing one color.
239 /// SolidFills are the simplest fill, containing only a single color.
240 struct DSOEXPORT SolidFill
242 public:
244 /// Construct a SolidFill.
245 explicit SolidFill(const rgba& c)
247 _color(c)
250 /// Copy a SolidFill.
251 SolidFill(const SolidFill& other)
253 _color(other._color)
256 /// Set this fill to a lerp of two other SolidFills.
257 void setLerp(const SolidFill& a, const SolidFill& b, double ratio) {
258 _color.set_lerp(a.color(), b.color(), ratio);
261 /// Get the color of the fill.
262 rgba color() const {
263 return _color;
266 private:
267 rgba _color;
270 /// FillStyle describes the various fill styles for shapes
272 /// The FillStyle class is effectively a boost::variant, but to allow passing
273 /// FillStyles using a forward declaration (and reducing compile times),
274 /// it's necessary to use a class.
275 class DSOEXPORT FillStyle
277 public:
279 typedef boost::variant<BitmapFill, SolidFill, GradientFill> Fill;
281 /// Construct a FillStyle from any Fill.
283 /// The non-explicit templated contructor allows the same syntax as a
284 /// simple boost::variant:
285 /// FillStyle f = GradientFill();
286 template<typename T> FillStyle(const T& f) : fill(f) {}
288 FillStyle(const FillStyle& other)
290 fill(other.fill)
293 Fill fill;
297 /// Set the FillStyle to a lerp of a and b.
299 /// Callers must ensure that all FillStyles have exactly the same type! Most
300 /// errors are caught by type-checking and will throw an unhandled exception.
301 void setLerp(FillStyle& f, const FillStyle& a, const FillStyle& b, double t);
303 DSOEXPORT std::ostream& operator<<(std::ostream& os,
304 const BitmapFill::SmoothingPolicy& p);
306 } // namespace gnash
308 #endif
311 // Local Variables:
312 // mode: C++
313 // indent-tabs-mode: t
314 // End: