[cairo-commit] cairomm/cairomm pattern.cc, 1.2, 1.3 pattern.h, 1.2, 1.3

Murray Cumming commit at pdx.freedesktop.org
Thu Dec 8 07:07:57 PST 2005


Committed by: murrayc

Update of /cvs/cairo/cairomm/cairomm
In directory gabe:/tmp/cvs-serv23529/cairomm

Modified Files:
	pattern.cc pattern.h 
Log Message:
2005-12-08  Murray Cumming <murrayc at murrayc.com>

        * cairomm/pattern.cc:
        * cairomm/pattern.h: Create a hierarchy of pattern
        classes, as suggested by the C documentation, because
        not all functions are meaningful for all pattern types.


Index: pattern.cc
===================================================================
RCS file: /cvs/cairo/cairomm/cairomm/pattern.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pattern.cc	2 Dec 2005 14:05:17 -0000	1.2
+++ pattern.cc	8 Dec 2005 15:07:55 -0000	1.3
@@ -21,6 +21,11 @@
 namespace Cairo
 {
 
+Pattern::Pattern()
+: m_cobject(0)
+{
+}
+
 Pattern::Pattern(cairo_pattern_t* cobject, bool has_reference)
 : m_cobject(0)
 {
@@ -70,84 +75,212 @@
   return *this;
 }
 
-Pattern Pattern::create_rgb(double red, double green, double blue)
+
+
+
+void Pattern::set_matrix(const cairo_matrix_t &matrix)
 {
-  cairo_pattern_t* cobject = cairo_pattern_create_rgb(red, green, blue);
-  return Pattern(cobject, true /* has reference */);
+  cairo_pattern_set_matrix(m_cobject, &matrix);
+  check_object_status_and_throw_exception(*this);
 }
 
-Pattern Pattern::create_rgba(double red, double green, double blue, double alpha)
+void Pattern::get_matrix(cairo_matrix_t &matrix) const
 {
-  cairo_pattern_t* cobject  = cairo_pattern_create_rgba(red, green, blue, alpha);
-  return Pattern(cobject, true /* has reference */);
+  cairo_pattern_get_matrix(m_cobject, &matrix);
+  check_object_status_and_throw_exception(*this);
 }
 
-Pattern Pattern::create_for_surface(cairo_surface_t *surface)
+
+
+SolidPattern::SolidPattern(cairo_pattern_t* cobject, bool has_reference)
+: Pattern(cobject, has_reference)
 {
-  cairo_pattern_t* cobject =  cairo_pattern_create_for_surface(surface);
-  return Pattern(cobject, true /* has reference */);
 }
 
-Pattern Pattern::create_linear(double x0, double y0, double x1, double y1)
+SolidPattern::SolidPattern(const SolidPattern& src)
+: Pattern(src)
 {
-  cairo_pattern_t* cobject =  cairo_pattern_create_linear(x0, y0, x1, y1);
-  return Pattern(cobject, true /* has reference */);
 }
 
-Pattern Pattern::create_radial(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1)
+SolidPattern::~SolidPattern()
 {
-  cairo_pattern_t* cobject =  cairo_pattern_create_radial(cx0, cy0, radius0, cx1, cy1, radius1);
-  return Pattern(cobject, true /* has reference */);
 }
 
-void Pattern::add_color_stop_rgb(double offset, double red, double green, double blue)
+SolidPattern SolidPattern::create_rgb(double red, double green, double blue)
 {
-  cairo_pattern_add_color_stop_rgb(m_cobject, offset, red, green, blue);
-  check_object_status_and_throw_exception(*this);
+  cairo_pattern_t* cobject = cairo_pattern_create_rgb(red, green, blue);
+  check_status_and_throw_exception(cairo_pattern_status(cobject)); 
+  return SolidPattern(cobject, true /* has reference */);
 }
 
-void Pattern::add_color_stop_rgba(double offset, double red, double green, double blue, double alpha)
+SolidPattern SolidPattern::create_rgba(double red, double green, double blue, double alpha)
 {
-  cairo_pattern_add_color_stop_rgba(m_cobject, offset, red, green, blue, alpha);
-  check_object_status_and_throw_exception(*this);
+  cairo_pattern_t* cobject  = cairo_pattern_create_rgba(red, green, blue, alpha);
+  check_status_and_throw_exception(cairo_pattern_status(cobject));
+  return SolidPattern(cobject, true /* has reference */);
 }
 
-void Pattern::set_matrix(const cairo_matrix_t &matrix)
+
+SolidPattern& SolidPattern::operator=(const SolidPattern& src)
 {
-  cairo_pattern_set_matrix(m_cobject, &matrix);
-  check_object_status_and_throw_exception(*this);
+  Pattern::operator=(src);
+
+  return *this;
 }
 
-void Pattern::get_matrix(cairo_matrix_t &matrix) const
+
+SurfacePattern::SurfacePattern(Surface& surface)
 {
-  cairo_pattern_get_matrix(m_cobject, &matrix);
-  check_object_status_and_throw_exception(*this);
+  m_cobject = cairo_pattern_create_for_surface(surface.cobj());
+  check_object_status_and_throw_exception(*this); 
 }
 
-void Pattern::set_extend(Extend extend)
+SurfacePattern::SurfacePattern(cairo_pattern_t* cobject, bool has_reference)
+: Pattern(cobject, has_reference)
+{
+}
+
+SurfacePattern::SurfacePattern(const SurfacePattern& src)
+: Pattern(src)
+{
+}
+
+SurfacePattern::~SurfacePattern()
+{
+}
+
+
+SurfacePattern& SurfacePattern::operator=(const SurfacePattern& src)
+{
+  Pattern::operator=(src);
+
+  return *this;
+}
+
+void SurfacePattern::set_extend(Extend extend)
 {
   cairo_pattern_set_extend(m_cobject, (cairo_extend_t)extend);
   check_object_status_and_throw_exception(*this);
 }
 
-Extend Pattern::get_extend() const
+Extend SurfacePattern::get_extend() const
 {
   const Extend result = cairo_pattern_get_extend(m_cobject);
   check_object_status_and_throw_exception(*this);
   return result;
 }
 
-void Pattern::set_filter(Filter filter)
+void SurfacePattern::set_filter(Filter filter)
 {
   cairo_pattern_set_filter(m_cobject, (cairo_filter_t)filter);
   check_object_status_and_throw_exception(*this);
 }
 
-Filter Pattern::get_filter() const
+Filter SurfacePattern::get_filter() const
 {
   Filter result = cairo_pattern_get_filter(m_cobject);
   check_object_status_and_throw_exception(*this);
   return result;
 }
 
+
+
+Gradient::Gradient()
+{
+}
+
+Gradient::Gradient(cairo_pattern_t* cobject, bool has_reference)
+: Pattern(cobject, has_reference)
+{
+}
+
+Gradient::Gradient(const Gradient& src)
+: Pattern(src)
+{
+}
+
+Gradient::~Gradient()
+{
+}
+
+Gradient& Gradient::operator=(const Gradient& src)
+{
+  Pattern::operator=(src);
+
+  return *this;
+}
+
+void Gradient::add_color_stop_rgb(double offset, double red, double green, double blue)
+{
+  cairo_pattern_add_color_stop_rgb(m_cobject, offset, red, green, blue);
+  check_object_status_and_throw_exception(*this);
+}
+
+void Gradient::add_color_stop_rgba(double offset, double red, double green, double blue, double alpha)
+{
+  cairo_pattern_add_color_stop_rgba(m_cobject, offset, red, green, blue, alpha);
+  check_object_status_and_throw_exception(*this);
+}
+
+
+
+LinearGradient::LinearGradient(double x0, double y0, double x1, double y1)
+{
+  m_cobject = cairo_pattern_create_linear(x0, y0, x1, y1);
+  check_object_status_and_throw_exception(*this); 
+}
+
+LinearGradient::LinearGradient(cairo_pattern_t* cobject, bool has_reference)
+: Gradient(cobject, has_reference)
+{
+}
+
+LinearGradient::LinearGradient(const LinearGradient& src)
+: Gradient(src)
+{
+}
+
+LinearGradient::~LinearGradient()
+{
+}
+
+
+LinearGradient& LinearGradient::operator=(const LinearGradient& src)
+{
+  Gradient::operator=(src);
+
+  return *this;
+}
+
+
+RadialGradient::RadialGradient(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1)
+{
+  m_cobject = cairo_pattern_create_radial(cx0, cy0, radius0, cx1, cy1, radius1);
+  check_object_status_and_throw_exception(*this); 
+}
+
+RadialGradient::RadialGradient(cairo_pattern_t* cobject, bool has_reference)
+: Gradient(cobject, has_reference)
+{
+}
+
+RadialGradient::RadialGradient(const RadialGradient& src)
+: Gradient(src)
+{
+}
+
+RadialGradient::~RadialGradient()
+{
+}
+
+
+RadialGradient& RadialGradient::operator=(const RadialGradient& src)
+{
+  Gradient::operator=(src);
+
+  return *this;
+}
+
+
+
 } //namespace Cairo

Index: pattern.h
===================================================================
RCS file: /cvs/cairo/cairomm/cairomm/pattern.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pattern.h	2 Dec 2005 14:05:17 -0000	1.2
+++ pattern.h	8 Dec 2005 15:07:55 -0000	1.3
@@ -18,6 +18,7 @@
 #ifndef __CAIROMM_PATTERN_H
 #define __CAIROMM_PATTERN_H
 
+#include <cairomm/surface.h>
 #include <cairomm/enums.h>
 #include <cairo/cairo.h>
 
@@ -35,7 +36,7 @@
 class Pattern
 {
 public:
-  Pattern();
+  //Use derived constructors.
 
   /** Create a C++ wrapper for the C instance.
    * @param cobject The C instance.
@@ -56,21 +57,8 @@
   */
   Pattern& operator=(const Pattern& src);
 
-  static Pattern create_rgb(double red, double green, double blue);
-  static Pattern create_rgba(double red, double green, double blue, double alpha);
-
-  static Pattern create_for_surface(cairo_surface_t *surface);
-  static Pattern create_linear(double x0, double y0, double x1, double y1);
-  static Pattern create_radial(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
-
-  void add_color_stop_rgb(double offset, double red, double green, double blue);
-  void add_color_stop_rgba(double offset, double red, double green, double blue, double alpha);
   void set_matrix(const cairo_matrix_t &matrix);
   void get_matrix(cairo_matrix_t &matrix) const;
-  void set_extend(Extend extend);
-  Extend get_extend() const;
-  void set_filter(Filter filter);
-  Filter get_filter() const;
 
   typedef cairo_pattern_t cobject;
   inline cobject* cobj() { return m_cobject; }
@@ -83,9 +71,153 @@
   #endif //DOXYGEN_IGNORE_THIS
 
 protected:
+  //Used by derived types only.
+  Pattern();
+
   cobject* m_cobject;
 };
 
+class SolidPattern : public Pattern
+{
+public:
+
+  static SolidPattern create_rgb(double red, double green, double blue);
+  static SolidPattern create_rgba(double red, double green, double blue, double alpha);
+
+  /** Create a C++ wrapper for the C instance.
+   * @param cobject The C instance.
+   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
+   */
+  explicit SolidPattern(cairo_pattern_t* cobject, bool has_reference = false);
+
+  /** Create a second reference to the Pattern.
+  * Changing this instance will change the original instance.
+  */
+  SolidPattern(const SolidPattern& src);
+
+  //TODO?: SolidPattern(cairo_pattern_t *target);
+  virtual ~SolidPattern();
+
+  /** Create a second reference to the Pattern.
+  * Changing this instance will change the original instance.
+  */
+  SolidPattern& operator=(const SolidPattern& src);
+};
+
+class SurfacePattern : public Pattern
+{
+public:
+
+  explicit SurfacePattern(Surface& surface);
+
+  /** Create a C++ wrapper for the C instance.
+   * @param cobject The C instance.
+   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
+   */
+  explicit SurfacePattern(cairo_pattern_t* cobject, bool has_reference = false);
+
+  /** Create a second reference to the Pattern.
+  * Changing this instance will change the original instance.
+  */
+  SurfacePattern(const SurfacePattern& src);
+
+  //TODO?: SurfacePattern(cairo_pattern_t *target);
+  virtual ~SurfacePattern();
+
+  /** Create a second reference to the Pattern.
+  * Changing this instance will change the original instance.
+  */
+  SurfacePattern& operator=(const SurfacePattern& src);
+
+  void set_extend(Extend extend);
+  Extend get_extend() const;
+  void set_filter(Filter filter);
+  Filter get_filter() const;
+};
+
+class Gradient : public Pattern
+{
+public:
+  //Use derived constructors.
+
+  /** Create a C++ wrapper for the C instance.
+   * @param cobject The C instance.
+   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
+   */
+  explicit Gradient(cairo_pattern_t* cobject, bool has_reference = false);
+
+  /** Create a second reference to the Pattern.
+  * Changing this instance will change the original instance.
+  */
+  Gradient(const Gradient& src);
+
+  //TODO?: Gradient(cairo_pattern_t *target);
+  virtual ~Gradient();
+
+  /** Create a second reference to the Pattern.
+  * Changing this instance will change the original instance.
+  */
+  Gradient& operator=(const Gradient& src);
+
+  void add_color_stop_rgb(double offset, double red, double green, double blue);
+  void add_color_stop_rgba(double offset, double red, double green, double blue, double alpha);
+
+protected:
+  Gradient();
+};
+
+class LinearGradient : public Gradient
+{
+public:
+
+  LinearGradient(double x0, double y0, double x1, double y1);
+
+  /** Create a C++ wrapper for the C instance.
+   * @param cobject The C instance.
+   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
+   */
+  explicit LinearGradient(cairo_pattern_t* cobject, bool has_reference = false);
+
+  /** Create a second reference to the Pattern.
+  * Changing this instance will change the original instance.
+  */
+  LinearGradient(const LinearGradient& src);
+
+  //TODO?: LinearGradient(cairo_pattern_t *target);
+  virtual ~LinearGradient();
+
+  /** Create a second reference to the Pattern.
+  * Changing this instance will change the original instance.
+  */
+  LinearGradient& operator=(const LinearGradient& src);
+};
+
+class RadialGradient : public Gradient
+{
+public:
+
+  RadialGradient(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
+
+  /** Create a C++ wrapper for the C instance.
+   * @param cobject The C instance.
+   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
+   */
+  explicit RadialGradient(cairo_pattern_t* cobject, bool has_reference = false);
+
+  /** Create a second reference to the Pattern.
+  * Changing this instance will change the original instance.
+  */
+  RadialGradient(const RadialGradient& src);
+
+  //TODO?: RadialGradient(cairo_pattern_t *target);
+  virtual ~RadialGradient();
+
+  /** Create a second reference to the Pattern.
+  * Changing this instance will change the original instance.
+  */
+  RadialGradient& operator=(const RadialGradient& src);
+};
+
 } // namespace Cairo
 
 #endif //__CAIROMM_PATTERN_H



More information about the cairo-commit mailing list