~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to src/region.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 * region.cpp
 
4
 *
 
5
 * Copyright 2007 Novell, Inc. (http://www.novell.com)
 
6
 *
 
7
 * See the LICENSE file included with the distribution for details.
 
8
 * 
 
9
 */
 
10
 
 
11
#include <config.h>
 
12
#include <stdlib.h>
 
13
 
 
14
#include "region.h"
 
15
 
 
16
 
 
17
Region::Region ()
 
18
 
19
        gdkregion = gdk_region_new (); 
 
20
}
 
21
 
 
22
Region::Region (double x, double y, double width, double height)
 
23
{
 
24
        gdkregion = gdk_region_new ();
 
25
        Union (Rect (x, y, width, height));
 
26
}
 
27
 
 
28
Region::Region (Rect rect)
 
29
{
 
30
        gdkregion = gdk_region_new ();
 
31
        Union (rect);
 
32
}
 
33
 
 
34
Region::Region (GdkRegion *region)
 
35
{
 
36
        gdkregion = gdk_region_copy (region);
 
37
}
 
38
 
 
39
Region::Region (Region *region)
 
40
{
 
41
        gdkregion = gdk_region_copy (region->gdkregion);
 
42
}
 
43
 
 
44
Region::~Region ()
 
45
{
 
46
        gdk_region_destroy (gdkregion);
 
47
        gdkregion = NULL;
 
48
}
 
49
 
 
50
bool
 
51
Region::IsEmpty ()
 
52
{
 
53
        return gdk_region_empty (gdkregion);
 
54
}
 
55
 
 
56
void 
 
57
Region::Union (Rect rect)
 
58
{
 
59
        GdkRectangle gdkrect = rect.ToGdkRectangle ();
 
60
        gdk_region_union_with_rect (gdkregion, &gdkrect);
 
61
}
 
62
 
 
63
void
 
64
Region::Union (GdkRectangle *rect)
 
65
{
 
66
        gdk_region_union_with_rect (gdkregion, rect);
 
67
}
 
68
 
 
69
void 
 
70
Region::Union (Region *region)
 
71
{
 
72
        gdk_region_union (gdkregion, region->gdkregion);
 
73
}
 
74
 
 
75
GdkOverlapType
 
76
Region::RectIn (Rect rect)
 
77
{
 
78
        GdkRectangle gdkrect = rect.ToGdkRectangle ();
 
79
        return gdk_region_rect_in (gdkregion, &gdkrect);
 
80
}
 
81
 
 
82
void
 
83
Region::Intersect (Region *region)
 
84
{
 
85
        gdk_region_intersect (gdkregion, region->gdkregion);
 
86
}
 
87
 
 
88
void
 
89
Region::Intersect (Rect rect)
 
90
{
 
91
        Region tmp = Region (rect);
 
92
        Intersect (&tmp);
 
93
}
 
94
 
 
95
 
 
96
void
 
97
Region::Subtract (Region *region)
 
98
{
 
99
        gdk_region_subtract (gdkregion, region->gdkregion);
 
100
}
 
101
 
 
102
void
 
103
Region::Subtract (Rect rect)
 
104
{
 
105
        Region tmp = Region (rect);
 
106
        Subtract (&tmp);
 
107
}
 
108
 
 
109
void
 
110
Region::Offset (int dx, int dy)
 
111
{
 
112
        gdk_region_offset (gdkregion, dx, dy);
 
113
}
 
114
 
 
115
void
 
116
Region::GetRectangles (GdkRectangle **rects, int *count)
 
117
{
 
118
        gdk_region_get_rectangles (gdkregion, rects, count);
 
119
        //if (*count > 10) {
 
120
        //      *count = 1;
 
121
        //      gdk_region_get_clipbox (gdkregion, *rects);
 
122
        //}
 
123
}
 
124
 
 
125
Rect 
 
126
Region::ClipBox ()
 
127
{
 
128
        GdkRectangle clip;
 
129
        gdk_region_get_clipbox (gdkregion, &clip);
 
130
        return Rect (clip.x, clip.y, clip.width, clip.height);
 
131
}
 
132
 
 
133
void 
 
134
Region::Draw (cairo_t *cr)
 
135
{
 
136
        int i, count;
 
137
        GdkRectangle *rects;
 
138
 
 
139
        gdk_region_get_rectangles (gdkregion, &rects, &i);
 
140
 
 
141
        for (count = 0; count < i; count++)
 
142
                cairo_rectangle (cr, rects [count].x, rects [count].y, rects [count].width, rects [count].height);
 
143
 
 
144
        g_free (rects);
 
145
}
 
146