diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | cairomm/cairomm.h | 1 | ||||
-rw-r--r-- | cairomm/enums.h | 7 | ||||
-rw-r--r-- | cairomm/filelist.am | 2 | ||||
-rw-r--r-- | cairomm/region.cc | 132 | ||||
-rw-r--r-- | cairomm/region.h | 112 | ||||
-rw-r--r-- | cairomm/types.h | 6 |
7 files changed, 269 insertions, 0 deletions
@@ -1,3 +1,12 @@ +2010-07-06 Murray Cumming <murrayc@murrayc.com> + + Add Region, wrapping cairo_region_t, new in cairo 1.10. + + * cairomm/region.[h|cc]: Added this class, wrapping it like other + reference-counted types, such as Pattern. + * cairomm/cairomm.h: Add an include of it here. + * cairomm/filelist.am: Mention the new files here. + 2010-06-07 Daniel Elstner <danielk@openismus.com> Disallow copying of Cairo::Context objects diff --git a/cairomm/cairomm.h b/cairomm/cairomm.h index 3600531..b96c3b1 100644 --- a/cairomm/cairomm.h +++ b/cairomm/cairomm.h @@ -40,6 +40,7 @@ #include <cairomm/matrix.h> #include <cairomm/path.h> #include <cairomm/pattern.h> +#include <cairomm/region.h> #include <cairomm/scaledfont.h> #include <cairomm/surface.h> diff --git a/cairomm/enums.h b/cairomm/enums.h index b698fb7..7475dac 100644 --- a/cairomm/enums.h +++ b/cairomm/enums.h @@ -230,6 +230,13 @@ typedef enum TEXT_CLUSTER_FLAG_BACKWARD = CAIRO_TEXT_CLUSTER_FLAG_BACKWARD /**< The clusters in the cluster array map to glyphs in the glyph array from end to start. */ } TextClusterFlags; +typedef enum +{ + REGION_OVERLAP_IN = CAIRO_REGION_OVERLAP_IN, /**< completely inside region */ + REGION_OVERLAP_OUT = CAIRO_REGION_OVERLAP_OUT, /**< completely outside region */ + REGION_OVERLAP_PART = CAIRO_REGION_OVERLAP_PART /**< partly inside region */ +} RegionOverlap; + } // namespace Cairo #endif //__CAIROMM_ENUMS_H diff --git a/cairomm/filelist.am b/cairomm/filelist.am index e2f67e3..48517d5 100644 --- a/cairomm/filelist.am +++ b/cairomm/filelist.am @@ -14,6 +14,7 @@ cairomm_cc = \ private.cc \ quartz_font.cc \ quartz_surface.cc \ + region.cc \ scaledfont.cc \ surface.cc \ win32_font.cc \ @@ -32,6 +33,7 @@ cairomm_public_h = \ quartz_font.h \ quartz_surface.h \ refptr.h \ + region.h \ scaledfont.h \ surface.h \ types.h \ diff --git a/cairomm/region.cc b/cairomm/region.cc new file mode 100644 index 0000000..0d37b9b --- /dev/null +++ b/cairomm/region.cc @@ -0,0 +1,132 @@ +/* Copyright (C) 2005 The cairomm Development Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include <cairomm/region.h> +#include <cairomm/private.h> + +namespace Cairo +{ + +Region::Region() +: m_cobject(cairo_region_create()) +{ +} + +Region::Region(const RectangleInt& rectangle) +: m_cobject(cairo_region_create_rectangle(&rectangle)) +{ +} + +Region::Region(cairo_region_t* cobject, bool has_reference) +: m_cobject(0) +{ + if(has_reference) + m_cobject = cobject; + else + m_cobject = cairo_region_reference(cobject); +} + +Region::~Region() +{ + if(m_cobject) + cairo_region_destroy(m_cobject); +} + +void Region::reference() const +{ + cairo_region_reference(m_cobject); +} + +void Region::unreference() const +{ + cairo_region_destroy(m_cobject); +} + +RectangleInt Region::get_extents() const +{ + RectangleInt result; + cairo_region_get_extents(m_cobject, &result); + return result; +} + +int Region::get_num_rectangles() const +{ + return cairo_region_num_rectangles(m_cobject); +} + +RectangleInt Region::get_rectangle(int nth_rectangle) const +{ + RectangleInt result; + cairo_region_get_rectangle(m_cobject, nth_rectangle, &result); + return result; +} + +bool Region::empty() const +{ + return cairo_region_is_empty(m_cobject); +} + +RegionOverlap Region::contains_rectangle(const RectangleInt& rectangle) const +{ + return (RegionOverlap)cairo_region_contains_rectangle(m_cobject, &rectangle); +} + +bool Region::contains_point(int x, int y) const +{ + return cairo_region_contains_point(m_cobject, x, y); +} + +void Region::translate(int dx, int dy) +{ + cairo_region_translate(m_cobject, dx, dy); +} + +ErrorStatus Region::subtract(const RefPtr<Region>& other) +{ + return cairo_region_subtract(m_cobject, (other ? other->cobj() : 0)); +} + +ErrorStatus Region::subtract(const RectangleInt& rectangle) +{ + return cairo_region_subtract_rectangle(m_cobject, &rectangle); +} + +ErrorStatus Region::intersect(const RefPtr<Region>& other) +{ + return cairo_region_intersect(m_cobject, (other ? other->cobj() : 0)); +} + +ErrorStatus Region::intersect(const RectangleInt& rectangle) +{ + return cairo_region_intersect_rectangle(m_cobject, &rectangle); +} + +ErrorStatus Region::do_union(const RefPtr<Region>& other) +{ + return cairo_region_union(m_cobject, (other ? other->cobj() : 0)); +} + +ErrorStatus Region::do_union(const RectangleInt& rectangle) +{ + return cairo_region_union_rectangle(m_cobject, &rectangle); +} + + +} //namespace Cairo + +// vim: ts=2 sw=2 et diff --git a/cairomm/region.h b/cairomm/region.h new file mode 100644 index 0000000..d6acb0c --- /dev/null +++ b/cairomm/region.h @@ -0,0 +1,112 @@ +/* Copyright (C) 2005 The cairomm Development Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __CAIROMM_REGION_H +#define __CAIROMM_REGION_H + +#include <cairomm/types.h> +#include <cairomm/enums.h> +#include <cairomm/refptr.h> +#include <cairo.h> + + +namespace Cairo +{ + +//TODO: Documentation. + +/** + * This is a reference-counted object that should be used via Cairo::RefPtr. + */ +class Region +{ +public: + + Region(); + + explicit Region(const RectangleInt& rectangle); + + //TODO: wrapping cairo_region_create_rectangles() + //Region(const RectangleInt *rects, int count); + + /** Create a C++ wrapper for the C instance. This C++ instance should then be given to a RefPtr. + * @param cobject The C instance. + * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference. + */ + explicit Region(cairo_region_t* cobject, bool has_reference = false); + +//TODO: +//cairo_public cairo_region_t * +//cairo_region_copy (const cairo_region_t *original); + + virtual ~Region(); + + RectangleInt get_extents() const; + + int get_num_rectangles() const; + + RectangleInt get_rectangle(int nth_rectangle) const; + + bool empty() const; + + RegionOverlap contains_rectangle(const RectangleInt& rectangle) const; + + bool contains_point(int x, int y) const; + + void translate(int dx, int dy); + + ErrorStatus subtract(const RefPtr<Region>& other); + + ErrorStatus subtract(const RectangleInt& rectangle); + + ErrorStatus intersect(const RefPtr<Region>& other); + + ErrorStatus intersect(const RectangleInt& rectangle); + + //We don't call this method union() because that is a C++ keyword. + + ErrorStatus do_union(const RefPtr<Region>& other); + + ErrorStatus do_union(const RectangleInt& rectangle); + + + + typedef cairo_region_t cobject; + + inline cobject* cobj() { return m_cobject; } + inline const cobject* cobj() const { return m_cobject; } + + #ifndef DOXYGEN_IGNORE_THIS + ///For use only by the cairomm implementation. + inline ErrorStatus get_status() const + { return cairo_region_status(const_cast<cairo_region_t*>(cobj())); } + #endif //DOXYGEN_IGNORE_THIS + + void reference() const; + void unreference() const; + +protected: + + cobject* m_cobject; +}; + +} // namespace Cairo + +#endif //__CAIROMM_REGION_H + +// vim: ts=2 sw=2 et diff --git a/cairomm/types.h b/cairomm/types.h index 5d583cd..2565b04 100644 --- a/cairomm/types.h +++ b/cairomm/types.h @@ -30,6 +30,12 @@ namespace Cairo typedef cairo_rectangle_t Rectangle; /** See the <a + * href="http://cairographics.org/manual/cairo-context.html#cairo-rectangle-t">cairo_rectangle_int_t + * reference</a> in the cairo manual for more information + */ +typedef cairo_rectangle_int_t RectangleInt; + +/** See the <a * href="http://cairographics.org/manual/cairo-scaled-font.html#cairo-font-extents-t">cairo_font_extents_t * reference</a> in the cairo manual for more information */ |