Merged revisions 6293,6296-6306,6308 via svnmerge from
[ardour.git] / libs / cairomm / cairomm / pattern.h
1 /* Copyright (C) 2005 The cairomm Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Library General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301, USA.
17  */
18
19 #ifndef __CAIROMM_PATTERN_H
20 #define __CAIROMM_PATTERN_H
21
22 #include <cairomm/surface.h>
23 #include <cairomm/enums.h>
24 #include <cairo.h>
25
26
27 namespace Cairo
28 {
29 struct ColorStop
30 {
31   double offset;
32   double red, green, blue, alpha;
33 };
34
35 /**
36  * This is a reference-counted object that should be used via Cairo::RefPtr.
37  */
38 class Pattern
39 {
40 protected:
41   //Use derived constructors.
42
43   //TODO?: Pattern(cairo_pattern_t *target);
44
45 public:
46
47   /** Create a C++ wrapper for the C instance. This C++ instance should then be given to a RefPtr.
48    * @param cobject The C instance.
49    * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
50    */
51   explicit Pattern(cairo_pattern_t* cobject, bool has_reference = false);
52
53   virtual ~Pattern();
54
55   void set_matrix(const cairo_matrix_t &matrix);
56   void get_matrix(cairo_matrix_t &matrix) const;
57   PatternType get_type() const;
58
59   typedef cairo_pattern_t cobject;
60   inline cobject* cobj() { return m_cobject; }
61   inline const cobject* cobj() const { return m_cobject; }
62
63   #ifndef DOXYGEN_IGNORE_THIS
64   ///For use only by the cairomm implementation.
65   inline ErrorStatus get_status() const
66   { return cairo_pattern_status(const_cast<cairo_pattern_t*>(cobj())); }
67   #endif //DOXYGEN_IGNORE_THIS
68
69   void reference() const;
70   void unreference() const;
71
72 protected:
73   //Used by derived types only.
74   Pattern();
75
76   cobject* m_cobject;
77 };
78
79 class SolidPattern : public Pattern
80 {
81 protected:
82
83 public:
84
85   /** Create a C++ wrapper for the C instance.
86    * @param cobject The C instance.
87    * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
88    */
89   explicit SolidPattern(cairo_pattern_t* cobject, bool has_reference = false);
90
91   /**
92    * Gets the solid color for a solid color pattern.
93    *
94    * @param red return value for red component of color
95    * @param green return value for green component of color
96    * @param blue return value for blue component of color
97    * @param alpha return value for alpha component of color
98    *
99    * @since 1.4
100    **/
101   void get_rgba (double& red, double& green,
102                  double& blue, double& alpha) const;
103
104   //TODO: Documentation
105   static RefPtr<SolidPattern> create_rgb(double red, double green, double blue);
106
107   //TODO: Documentation
108   static RefPtr<SolidPattern> create_rgba(double red, double green,
109                                           double blue, double alpha);
110
111   //TODO?: SolidPattern(cairo_pattern_t *target);
112   virtual ~SolidPattern();
113 };
114
115 class SurfacePattern : public Pattern
116 {
117 protected:
118
119   explicit SurfacePattern(const RefPtr<Surface>& surface);
120
121   //TODO?: SurfacePattern(cairo_pattern_t *target);
122
123 public:
124
125   /** Create a C++ wrapper for the C instance. This C++ instance should then be given to a RefPtr.
126    * @param cobject The C instance.
127    * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
128    */
129   explicit SurfacePattern(cairo_pattern_t* cobject, bool has_reference = false);
130
131   /**
132    * Gets the surface associated with this pattern
133    *
134    * @since 1.4
135    **/
136   RefPtr<const Surface> get_surface () const;
137
138   /**
139    * Gets the surface associated with this pattern
140    *
141    * @since 1.4
142    **/
143   RefPtr<Surface> get_surface ();
144
145   virtual ~SurfacePattern();
146
147   static RefPtr<SurfacePattern> create(const RefPtr<Surface>& surface);
148
149   void set_extend(Extend extend);
150   Extend get_extend() const;
151   void set_filter(Filter filter);
152   Filter get_filter() const;
153 };
154
155 class Gradient : public Pattern
156 {
157 protected:
158   //Use derived constructors.
159
160   //TODO?: Gradient(cairo_pattern_t *target);
161
162 public:
163
164   /** Create a C++ wrapper for the C instance. This C++ instance should then be given to a RefPtr.
165    * @param cobject The C instance.
166    * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
167    */
168   explicit Gradient(cairo_pattern_t* cobject, bool has_reference = false);
169
170   virtual ~Gradient();
171
172   /**
173    * Adds an opaque color stop to a gradient pattern. The offset
174    * specifies the location along the gradient's control vector. For
175    * example, a linear gradient's control vector is from (x0,y0) to
176    * (x1,y1) while a radial gradient's control vector is from any point
177    * on the start circle to the corresponding point on the end circle.
178    *
179    * The color is specified in the same way as in Context::set_source_rgb().
180    *
181    * @param offset an offset in the range [0.0 .. 1.0]
182    * @param red red component of color
183    * @param green green component of color
184    * @param blue blue component of color
185    **/
186   void add_color_stop_rgb(double offset, double red, double green, double blue);
187
188   /**
189    * Adds a translucent color stop to a gradient pattern. The offset
190    * specifies the location along the gradient's control vector. For
191    * example, a linear gradient's control vector is from (x0,y0) to
192    * (x1,y1) while a radial gradient's control vector is from any point
193    * on the start circle to the corresponding point on the end circle.
194    *
195    * The color is specified in the same way as in Context::set_source_rgba().
196    *
197    * @param offset an offset in the range [0.0 .. 1.0]
198    * @param red red component of color
199    * @param green green component of color
200    * @param blue blue component of color
201    * @param alpha alpha component of color
202    */
203   void add_color_stop_rgba(double offset, double red, double green, double blue, double alpha);
204
205   /*
206    * Gets the color stops and offsets for this Gradient
207    *
208    * @since 1.4
209    */
210   std::vector<ColorStop> get_color_stops() const;
211
212
213 protected:
214   Gradient();
215 };
216
217 class LinearGradient : public Gradient
218 {
219 protected:
220
221   LinearGradient(double x0, double y0, double x1, double y1);
222
223 public:
224
225   /** Create a C++ wrapper for the C instance. This C++ instance should then be given to a RefPtr.
226    * @param cobject The C instance.
227    * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
228    */
229   explicit LinearGradient(cairo_pattern_t* cobject, bool has_reference = false);
230
231   /**
232    * @param x0 return value for the x coordinate of the first point
233    * @param y0 return value for the y coordinate of the first point
234    * @param x1 return value for the x coordinate of the second point
235    * @param y1 return value for the y coordinate of the second point
236    *
237    * Gets the gradient endpoints for a linear gradient.
238    *
239    * @since 1.4
240    **/
241   void get_linear_points(double &x0, double &y0,
242                           double &x1, double &y1) const;
243
244   //TODO?: LinearGradient(cairo_pattern_t *target);
245   virtual ~LinearGradient();
246
247   static RefPtr<LinearGradient> create(double x0, double y0, double x1, double y1);
248 };
249
250 class RadialGradient : public Gradient
251 {
252 protected:
253
254   RadialGradient(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
255
256 public:
257
258   /** Create a C++ wrapper for the C instance. This C++ instance should then be given to a RefPtr.
259    * @param cobject The C instance.
260    * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
261    */
262   explicit RadialGradient(cairo_pattern_t* cobject, bool has_reference = false);
263
264   /**
265    * @param x0 return value for the x coordinate of the center of the first (inner) circle
266    * @param y0 return value for the y coordinate of the center of the first (inner) circle
267    * @param r0 return value for the radius of the first (inner) circle
268    * @param x1 return value for the x coordinate of the center of the second (outer) circle
269    * @param y1 return value for the y coordinate of the center of the second (outer) circle
270    * @param r1 return value for the radius of the second (outer) circle
271    *
272    * Gets the gradient endpoint circles for a radial gradient, each
273    * specified as a center coordinate and a radius.
274    *
275    * @since 1.4
276    **/
277   void get_radial_circles(double& x0, double& y0, double& r0,
278                            double& x1, double& y1, double& r1) const;
279
280   //TODO?: RadialGradient(cairo_pattern_t *target);
281   virtual ~RadialGradient();
282
283   static RefPtr<RadialGradient> create(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
284 };
285
286 } // namespace Cairo
287
288 #endif //__CAIROMM_PATTERN_H
289
290 // vim: ts=2 sw=2 et