summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@gnome.org>2010-12-30 17:00:53 -0600
committerJonathon Jongsma <jjongsma@gnome.org>2010-12-30 17:18:58 -0600
commit61ffb52e696d8885abb17e505f1ec98bffbd2c11 (patch)
tree8a00a79c9d034a45fa352f2dbf569caa5bff397e
parentcf1631b88225aff9fae2a0552ddb1f226c361ec3 (diff)
Wrap cairo_region_create_rectangles()
-rw-r--r--cairomm/region.cc31
-rw-r--r--cairomm/region.h8
2 files changed, 36 insertions, 3 deletions
diff --git a/cairomm/region.cc b/cairomm/region.cc
index c361e40..1233f2c 100644
--- a/cairomm/region.cc
+++ b/cairomm/region.cc
@@ -18,6 +18,7 @@
#include <cairomm/region.h>
#include <cairomm/private.h>
+#include <algorithm>
namespace Cairo
{
@@ -34,6 +35,26 @@ Region::Region(const RectangleInt& rectangle)
check_object_status_and_throw_exception (*this);
}
+// less efficient but convenient
+Region::Region(const std::vector<RectangleInt>& rects) :
+ m_cobject(0)
+{
+ RectangleInt *carray = new RectangleInt[rects.size()];
+ std::copy(rects.begin(), rects.end(), carray);
+ m_cobject = cairo_region_create_rectangles (carray, rects.size());
+
+ delete[] carray;
+
+ check_object_status_and_throw_exception (*this);
+}
+
+// less convenient but more efficient
+Region::Region(const RectangleInt *rects, int count) :
+ m_cobject(cairo_region_create_rectangles (rects, count))
+{
+ check_object_status_and_throw_exception (*this);
+}
+
Region::Region(cairo_region_t* cobject, bool has_reference)
: m_cobject(0)
{
@@ -55,6 +76,16 @@ RefPtr<Region> Region::create(const RectangleInt& rectangle)
return RefPtr<Region>(new Region(rectangle));
}
+RefPtr<Region> Region::create(const std::vector<RectangleInt>& rects)
+{
+ return RefPtr<Region>(new Region(rects));
+}
+
+RefPtr<Region> Region::create(const RectangleInt *rects, int count)
+{
+ return RefPtr<Region>(new Region(rects, count));
+}
+
RefPtr<Region> Region::copy() const
{
return RefPtr<Region> (new Region (cairo_region_copy (m_cobject), true));
diff --git a/cairomm/region.h b/cairomm/region.h
index 4e4f400..67b891b 100644
--- a/cairomm/region.h
+++ b/cairomm/region.h
@@ -23,7 +23,7 @@
#include <cairomm/enums.h>
#include <cairomm/refptr.h>
#include <cairo.h>
-
+#include <vector>
namespace Cairo
{
@@ -44,8 +44,8 @@ private:
explicit Region(const RectangleInt& rectangle);
- //TODO: wrapping cairo_region_create_rectangles()
- //Region(const RectangleInt *rects, int count);
+ explicit Region(const std::vector<RectangleInt>& rects);
+ Region(const RectangleInt *rects, int count);
public:
/** Create a C++ wrapper for the C instance. This C++ instance should then be given to a RefPtr.
@@ -56,6 +56,8 @@ public:
static RefPtr<Region> create();
static RefPtr<Region> create(const RectangleInt& rectangle);
+ static RefPtr<Region> create(const std::vector<RectangleInt>& rects);
+ static RefPtr<Region> create(const RectangleInt *rects, int count);
/** allocates a new region object copied from the original */
RefPtr<Region> copy() const;