pattern.h

Go to the documentation of this file.
00001 /* Copyright (C) 2005 The cairomm Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Library General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2 of the License, or (at your option) any later version.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Library General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Library General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00016  * 02110-1301, USA.
00017  */
00018 
00019 #ifndef __CAIROMM_PATTERN_H
00020 #define __CAIROMM_PATTERN_H
00021 
00022 #include <cairomm/surface.h>
00023 #include <cairomm/enums.h>
00024 #include <cairo.h>
00025 
00026 
00027 namespace Cairo
00028 {
00029 struct ColorStop
00030 {
00031   double offset;
00032   double red, green, blue, alpha;
00033 };
00034 
00038 class Pattern
00039 {
00040 protected:
00041   //Use derived constructors.
00042 
00043   //TODO?: Pattern(cairo_pattern_t *target);
00044 
00045 public:
00046 
00051   explicit Pattern(cairo_pattern_t* cobject, bool has_reference = false);
00052 
00053   virtual ~Pattern();
00054 
00055   void set_matrix(const cairo_matrix_t &matrix);
00056   void get_matrix(cairo_matrix_t &matrix) const;
00057   PatternType get_type() const;
00058 
00059   typedef cairo_pattern_t cobject;
00060   inline cobject* cobj() { return m_cobject; }
00061   inline const cobject* cobj() const { return m_cobject; }
00062 
00063   #ifndef DOXYGEN_IGNORE_THIS
00065   inline ErrorStatus get_status() const
00066   { return cairo_pattern_status(const_cast<cairo_pattern_t*>(cobj())); }
00067   #endif //DOXYGEN_IGNORE_THIS
00068 
00069   void reference() const;
00070   void unreference() const;
00071 
00072 protected:
00073   //Used by derived types only.
00074   Pattern();
00075 
00076   cobject* m_cobject;
00077 };
00078 
00079 class SolidPattern : public Pattern
00080 {
00081 protected:
00082 
00083 public:
00084 
00089   explicit SolidPattern(cairo_pattern_t* cobject, bool has_reference = false);
00090 
00101   void get_rgba (double& red, double& green,
00102                  double& blue, double& alpha) const;
00103 
00104   //TODO: Documentation
00105   static RefPtr<SolidPattern> create_rgb(double red, double green, double blue);
00106 
00107   //TODO: Documentation
00108   static RefPtr<SolidPattern> create_rgba(double red, double green,
00109                                           double blue, double alpha);
00110 
00111   //TODO?: SolidPattern(cairo_pattern_t *target);
00112   virtual ~SolidPattern();
00113 };
00114 
00115 class SurfacePattern : public Pattern
00116 {
00117 protected:
00118 
00119   explicit SurfacePattern(const RefPtr<Surface>& surface);
00120 
00121   //TODO?: SurfacePattern(cairo_pattern_t *target);
00122 
00123 public:
00124 
00129   explicit SurfacePattern(cairo_pattern_t* cobject, bool has_reference = false);
00130 
00136   RefPtr<const Surface> get_surface () const;
00137 
00143   RefPtr<Surface> get_surface ();
00144 
00145   virtual ~SurfacePattern();
00146 
00147   static RefPtr<SurfacePattern> create(const RefPtr<Surface>& surface);
00148 
00149   void set_extend(Extend extend);
00150   Extend get_extend() const;
00151   void set_filter(Filter filter);
00152   Filter get_filter() const;
00153 };
00154 
00155 class Gradient : public Pattern
00156 {
00157 protected:
00158   //Use derived constructors.
00159 
00160   //TODO?: Gradient(cairo_pattern_t *target);
00161 
00162 public:
00163 
00168   explicit Gradient(cairo_pattern_t* cobject, bool has_reference = false);
00169 
00170   virtual ~Gradient();
00171 
00186   void add_color_stop_rgb(double offset, double red, double green, double blue);
00187 
00203   void add_color_stop_rgba(double offset, double red, double green, double blue, double alpha);
00204 
00205   /*
00206    * Gets the color stops and offsets for this Gradient
00207    *
00208    * @since 1.4
00209    */
00210   std::vector<ColorStop> get_color_stops() const;
00211 
00212 
00213 protected:
00214   Gradient();
00215 };
00216 
00217 class LinearGradient : public Gradient
00218 {
00219 protected:
00220 
00221   LinearGradient(double x0, double y0, double x1, double y1);
00222 
00223 public:
00224 
00229   explicit LinearGradient(cairo_pattern_t* cobject, bool has_reference = false);
00230 
00241   void get_linear_points(double &x0, double &y0,
00242                           double &x1, double &y1) const;
00243 
00244   //TODO?: LinearGradient(cairo_pattern_t *target);
00245   virtual ~LinearGradient();
00246 
00247   static RefPtr<LinearGradient> create(double x0, double y0, double x1, double y1);
00248 };
00249 
00250 class RadialGradient : public Gradient
00251 {
00252 protected:
00253 
00254   RadialGradient(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
00255 
00256 public:
00257 
00262   explicit RadialGradient(cairo_pattern_t* cobject, bool has_reference = false);
00263 
00277   void get_radial_circles(double& x0, double& y0, double& r0,
00278                            double& x1, double& y1, double& r1) const;
00279 
00280   //TODO?: RadialGradient(cairo_pattern_t *target);
00281   virtual ~RadialGradient();
00282 
00283   static RefPtr<RadialGradient> create(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
00284 };
00285 
00286 } // namespace Cairo
00287 
00288 #endif //__CAIROMM_PATTERN_H
00289 
00290 // vim: ts=2 sw=2 et

Generated on Thu Sep 4 21:57:13 2008 for cairomm by  doxygen 1.5.5