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 
00035 class Matrix;
00036 
00040 class Pattern
00041 {
00042 protected:
00043   //Use derived constructors.
00044 
00045   //TODO?: Pattern(cairo_pattern_t *target);
00046 
00047 public:
00048 
00053   explicit Pattern(cairo_pattern_t* cobject, bool has_reference = false);
00054 
00055   virtual ~Pattern();
00056 
00057   void set_matrix(const Matrix& matrix);
00058   void get_matrix(Matrix& matrix) const;
00061   Matrix get_matrix() const;
00062   /* To keep 1.6.x ABI  */
00063   void set_matrix(const cairo_matrix_t& matrix);
00064   void get_matrix(cairo_matrix_t& matrix) const;
00065   PatternType get_type() const;
00066 
00067   typedef cairo_pattern_t cobject;
00068   inline cobject* cobj() { return m_cobject; }
00069   inline const cobject* cobj() const { return m_cobject; }
00070 
00071   #ifndef DOXYGEN_IGNORE_THIS
00073   inline ErrorStatus get_status() const
00074   { return cairo_pattern_status(const_cast<cairo_pattern_t*>(cobj())); }
00075   #endif //DOXYGEN_IGNORE_THIS
00076 
00077   void reference() const;
00078   void unreference() const;
00079 
00080 protected:
00081   //Used by derived types only.
00082   Pattern();
00083 
00084   cobject* m_cobject;
00085 };
00086 
00087 class SolidPattern : public Pattern
00088 {
00089 protected:
00090 
00091 public:
00092 
00097   explicit SolidPattern(cairo_pattern_t* cobject, bool has_reference = false);
00098 
00109   void get_rgba (double& red, double& green,
00110                  double& blue, double& alpha) const;
00111 
00112   //TODO: Documentation
00113   static RefPtr<SolidPattern> create_rgb(double red, double green, double blue);
00114 
00115   //TODO: Documentation
00116   static RefPtr<SolidPattern> create_rgba(double red, double green,
00117                                           double blue, double alpha);
00118 
00119   //TODO?: SolidPattern(cairo_pattern_t *target);
00120   virtual ~SolidPattern();
00121 };
00122 
00123 class SurfacePattern : public Pattern
00124 {
00125 protected:
00126 
00127   explicit SurfacePattern(const RefPtr<Surface>& surface);
00128 
00129   //TODO?: SurfacePattern(cairo_pattern_t *target);
00130 
00131 public:
00132 
00137   explicit SurfacePattern(cairo_pattern_t* cobject, bool has_reference = false);
00138 
00144   RefPtr<const Surface> get_surface () const;
00145 
00151   RefPtr<Surface> get_surface ();
00152 
00153   virtual ~SurfacePattern();
00154 
00155   static RefPtr<SurfacePattern> create(const RefPtr<Surface>& surface);
00156 
00157   void set_extend(Extend extend);
00158   Extend get_extend() const;
00159   void set_filter(Filter filter);
00160   Filter get_filter() const;
00161 };
00162 
00163 class Gradient : public Pattern
00164 {
00165 protected:
00166   //Use derived constructors.
00167 
00168   //TODO?: Gradient(cairo_pattern_t *target);
00169 
00170 public:
00171 
00176   explicit Gradient(cairo_pattern_t* cobject, bool has_reference = false);
00177 
00178   virtual ~Gradient();
00179 
00194   void add_color_stop_rgb(double offset, double red, double green, double blue);
00195 
00211   void add_color_stop_rgba(double offset, double red, double green, double blue, double alpha);
00212 
00213   /*
00214    * Gets the color stops and offsets for this Gradient
00215    *
00216    * @since 1.4
00217    */
00218   std::vector<ColorStop> get_color_stops() const;
00219 
00220 
00221 protected:
00222   Gradient();
00223 };
00224 
00225 class LinearGradient : public Gradient
00226 {
00227 protected:
00228 
00229   LinearGradient(double x0, double y0, double x1, double y1);
00230 
00231 public:
00232 
00237   explicit LinearGradient(cairo_pattern_t* cobject, bool has_reference = false);
00238 
00249   void get_linear_points(double &x0, double &y0,
00250                           double &x1, double &y1) const;
00251 
00252   //TODO?: LinearGradient(cairo_pattern_t *target);
00253   virtual ~LinearGradient();
00254 
00255   static RefPtr<LinearGradient> create(double x0, double y0, double x1, double y1);
00256 };
00257 
00258 class RadialGradient : public Gradient
00259 {
00260 protected:
00261 
00262   RadialGradient(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
00263 
00264 public:
00265 
00270   explicit RadialGradient(cairo_pattern_t* cobject, bool has_reference = false);
00271 
00285   void get_radial_circles(double& x0, double& y0, double& r0,
00286                            double& x1, double& y1, double& r1) const;
00287 
00288   //TODO?: RadialGradient(cairo_pattern_t *target);
00289   virtual ~RadialGradient();
00290 
00291   static RefPtr<RadialGradient> create(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
00292 };
00293 
00294 } // namespace Cairo
00295 
00296 #endif //__CAIROMM_PATTERN_H
00297 
00298 // vim: ts=2 sw=2 et

Generated on Sat Aug 22 16:10:46 2009 for cairomm by  doxygen 1.5.8