1 /* Copyright (C) 2005 The cairomm Development Team
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.
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.
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
19 #ifndef __CAIROMM_PATTERN_H
20 #define __CAIROMM_PATTERN_H
22 #include <cairomm/surface.h>
23 #include <cairomm/enums.h>
32 double red, green, blue, alpha;
36 * This is a reference-counted object that should be used via Cairo::RefPtr.
41 //Use derived constructors.
43 //TODO?: Pattern(cairo_pattern_t *target);
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.
51 explicit Pattern(cairo_pattern_t* cobject, bool has_reference = false);
55 void set_matrix(const cairo_matrix_t &matrix);
56 void get_matrix(cairo_matrix_t &matrix) const;
57 PatternType get_type() const;
59 typedef cairo_pattern_t cobject;
60 inline cobject* cobj() { return m_cobject; }
61 inline const cobject* cobj() const { return m_cobject; }
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
69 void reference() const;
70 void unreference() const;
73 //Used by derived types only.
79 class SolidPattern : public Pattern
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.
89 explicit SolidPattern(cairo_pattern_t* cobject, bool has_reference = false);
92 * Gets the solid color for a solid color pattern.
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
101 void get_rgba (double& red, double& green,
102 double& blue, double& alpha) const;
104 //TODO: Documentation
105 static RefPtr<SolidPattern> create_rgb(double red, double green, double blue);
107 //TODO: Documentation
108 static RefPtr<SolidPattern> create_rgba(double red, double green,
109 double blue, double alpha);
111 //TODO?: SolidPattern(cairo_pattern_t *target);
112 virtual ~SolidPattern();
115 class SurfacePattern : public Pattern
119 explicit SurfacePattern(const RefPtr<Surface>& surface);
121 //TODO?: SurfacePattern(cairo_pattern_t *target);
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.
129 explicit SurfacePattern(cairo_pattern_t* cobject, bool has_reference = false);
132 * Gets the surface associated with this pattern
136 RefPtr<const Surface> get_surface () const;
139 * Gets the surface associated with this pattern
143 RefPtr<Surface> get_surface ();
145 virtual ~SurfacePattern();
147 static RefPtr<SurfacePattern> create(const RefPtr<Surface>& surface);
149 void set_extend(Extend extend);
150 Extend get_extend() const;
151 void set_filter(Filter filter);
152 Filter get_filter() const;
155 class Gradient : public Pattern
158 //Use derived constructors.
160 //TODO?: Gradient(cairo_pattern_t *target);
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.
168 explicit Gradient(cairo_pattern_t* cobject, bool has_reference = false);
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.
179 * The color is specified in the same way as in Context::set_source_rgb().
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
186 void add_color_stop_rgb(double offset, double red, double green, double blue);
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.
195 * The color is specified in the same way as in Context::set_source_rgba().
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
203 void add_color_stop_rgba(double offset, double red, double green, double blue, double alpha);
206 * Gets the color stops and offsets for this Gradient
210 std::vector<ColorStop> get_color_stops() const;
217 class LinearGradient : public Gradient
221 LinearGradient(double x0, double y0, double x1, double y1);
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.
229 explicit LinearGradient(cairo_pattern_t* cobject, bool has_reference = false);
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
237 * Gets the gradient endpoints for a linear gradient.
241 void get_linear_points(double &x0, double &y0,
242 double &x1, double &y1) const;
244 //TODO?: LinearGradient(cairo_pattern_t *target);
245 virtual ~LinearGradient();
247 static RefPtr<LinearGradient> create(double x0, double y0, double x1, double y1);
250 class RadialGradient : public Gradient
254 RadialGradient(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
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.
262 explicit RadialGradient(cairo_pattern_t* cobject, bool has_reference = false);
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
272 * Gets the gradient endpoint circles for a radial gradient, each
273 * specified as a center coordinate and a radius.
277 void get_radial_circles(double& x0, double& y0, double& r0,
278 double& x1, double& y1, double& r1) const;
280 //TODO?: RadialGradient(cairo_pattern_t *target);
281 virtual ~RadialGradient();
283 static RefPtr<RadialGradient> create(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
288 #endif //__CAIROMM_PATTERN_H