Merged revisions 6293,6296-6306,6308 via svnmerge from
[ardour.git] / libs / gtkmm2 / gdk / src / region.ccg
1 // -*- c++ -*-
2 /* $Id: region.ccg,v 1.1 2003/01/21 13:38:38 murrayc Exp $ */
3
4 /*
5  *
6  * Copyright 1998-2002 The gtkmm Development Team
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <gdk/gdkregion.h>
24
25 namespace Gdk
26 {
27
28 Region::Region(const Glib::ArrayHandle<Gdk::Point>& points, FillRule fill_rule)
29 :
30   // The dangerous-looking cast to GdkPoint* works, because Gdk::Point
31   // has only one member variable of type GdkPoint, and no vtable.  Please
32   // don't copy this code, casts like that won't work with most other types.
33
34   gobject_ (gdk_region_polygon(
35       reinterpret_cast<GdkPoint*>(const_cast<Gdk::Point*>(points.data())),
36       points.size(), (GdkFillRule)(fill_rule)))
37 {}
38
39 Region::Region(const Rectangle& rectangle)
40 :
41   gobject_ (gdk_region_rectangle(const_cast<GdkRectangle*>(rectangle.gobj())))
42 {}
43
44 Glib::ArrayHandle<Rectangle> Region::get_rectangles() const
45 {
46   GdkRectangle* rectangles = 0;
47   int n_rectangles = 0;
48
49   gdk_region_get_rectangles(gobject_, &rectangles, &n_rectangles);
50
51   // The dangerous-looking cast to Rectangle* works, because Gdk::Rectangle
52   // has only one member variable of type GdkRectangle, and no vtable.  Please
53   // don't copy this code, casts like that won't work with most other types.
54
55   return Glib::ArrayHandle<Rectangle>(
56       reinterpret_cast<Rectangle*>(rectangles), n_rectangles, Glib::OWNERSHIP_SHALLOW);
57 }
58
59 } // namespace Gdk
60