diff options
author | Murray Cumming <murrayc@murrayc.com> | 2005-12-08 15:07:55 +0000 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2005-12-08 15:07:55 +0000 |
commit | d16d199da9b510d80d0b27a4b117213ab008d07d (patch) | |
tree | 5b23a91ebd99f01a75929753915036effea201a3 | |
parent | 91005e3850055780cb65483bbfb249abcd5da353 (diff) |
2005-12-08 Murray Cumming <murrayc@murrayc.com>RELEASE_0_3_0
* 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.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | cairomm/pattern.cc | 195 | ||||
-rw-r--r-- | cairomm/pattern.h | 160 |
3 files changed, 317 insertions, 45 deletions
@@ -1,3 +1,10 @@ +2005-12-08 Murray Cumming <murrayc@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. + 2005-12-07 Murray Cumming <murrayc@murrayc.com> * cairomm/context.cc: diff --git a/cairomm/pattern.cc b/cairomm/pattern.cc index 108f108..7be40a5 100644 --- a/cairomm/pattern.cc +++ b/cairomm/pattern.cc @@ -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 @@ Pattern& Pattern::operator=(const Pattern& src) 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) +{ + m_cobject = cairo_pattern_create_for_surface(surface.cobj()); + check_object_status_and_throw_exception(*this); +} + +SurfacePattern::SurfacePattern(cairo_pattern_t* cobject, bool has_reference) +: Pattern(cobject, has_reference) { - cairo_pattern_get_matrix(m_cobject, &matrix); - check_object_status_and_throw_exception(*this); } -void Pattern::set_extend(Extend extend) +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 diff --git a/cairomm/pattern.h b/cairomm/pattern.h index 1ebbc87..dd2bb15 100644 --- a/cairomm/pattern.h +++ b/cairomm/pattern.h @@ -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 @@ typedef cairo_filter_t Filter; class Pattern { public: - Pattern(); + //Use derived constructors. /** Create a C++ wrapper for the C instance. * @param cobject The C instance. @@ -56,21 +57,8 @@ public: */ 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 @@ public: #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 |