2009-11-08 Chris Toshok <toshok@ximian.com>
[moon.git] / src / region.cpp
blobfb4e40632357a2f560793796753c9ebf4e0398f6
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * region.cpp
5 * Copyright 2007 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 *
9 */
11 #include <config.h>
12 #include <stdlib.h>
14 #include "region.h"
17 Region::Region ()
19 gdkregion = gdk_region_new ();
22 Region::Region (double x, double y, double width, double height)
24 gdkregion = gdk_region_new ();
25 Union (Rect (x, y, width, height));
28 Region::Region (Rect rect)
30 gdkregion = gdk_region_new ();
31 Union (rect);
34 Region::Region (GdkRegion *region)
36 gdkregion = gdk_region_copy (region);
39 Region::Region (Region *region)
41 gdkregion = gdk_region_copy (region->gdkregion);
44 Region::~Region ()
46 gdk_region_destroy (gdkregion);
47 gdkregion = NULL;
50 bool
51 Region::IsEmpty ()
53 return gdk_region_empty (gdkregion);
56 void
57 Region::Union (Rect rect)
59 GdkRectangle gdkrect = rect.ToGdkRectangle ();
60 gdk_region_union_with_rect (gdkregion, &gdkrect);
63 void
64 Region::Union (GdkRectangle *rect)
66 gdk_region_union_with_rect (gdkregion, rect);
69 void
70 Region::Union (Region *region)
72 gdk_region_union (gdkregion, region->gdkregion);
75 GdkOverlapType
76 Region::RectIn (Rect rect)
78 GdkRectangle gdkrect = rect.ToGdkRectangle ();
79 return gdk_region_rect_in (gdkregion, &gdkrect);
82 void
83 Region::Intersect (Region *region)
85 gdk_region_intersect (gdkregion, region->gdkregion);
88 void
89 Region::Intersect (Rect rect)
91 Region tmp = Region (rect);
92 Intersect (&tmp);
96 void
97 Region::Subtract (Region *region)
99 gdk_region_subtract (gdkregion, region->gdkregion);
102 void
103 Region::Subtract (Rect rect)
105 Region tmp = Region (rect);
106 Subtract (&tmp);
109 void
110 Region::Offset (int dx, int dy)
112 gdk_region_offset (gdkregion, dx, dy);
115 void
116 Region::GetRectangles (GdkRectangle **rects, int *count)
118 gdk_region_get_rectangles (gdkregion, rects, count);
119 //if (*count > 10) {
120 // *count = 1;
121 // gdk_region_get_clipbox (gdkregion, *rects);
125 Rect
126 Region::ClipBox ()
128 GdkRectangle clip;
129 gdk_region_get_clipbox (gdkregion, &clip);
130 return Rect (clip.x, clip.y, clip.width, clip.height);
133 void
134 Region::Draw (cairo_t *cr)
136 int i, count;
137 GdkRectangle *rects;
139 gdk_region_get_rectangles (gdkregion, &rects, &i);
141 for (count = 0; count < i; count++)
142 cairo_rectangle (cr, rects [count].x, rects [count].y, rects [count].width, rects [count].height);
144 g_free (rects);