1 | /* GDK - The GIMP Drawing Kit |
---|
2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
---|
3 | * |
---|
4 | * This library is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU Library General Public |
---|
6 | * License as published by the Free Software Foundation; either |
---|
7 | * version 2 of the License, or (at your option) any later version. |
---|
8 | * |
---|
9 | * This library is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
12 | * Library General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU Library General Public |
---|
15 | * License along with this library; if not, write to the |
---|
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
17 | * Boston, MA 02111-1307, USA. |
---|
18 | */ |
---|
19 | |
---|
20 | /* |
---|
21 | * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS |
---|
22 | * file for a list of people on the GTK+ Team. See the ChangeLog |
---|
23 | * files for a list of changes. These files are distributed with |
---|
24 | * GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
---|
25 | */ |
---|
26 | |
---|
27 | #include <X11/Xlib.h> |
---|
28 | #include <X11/Xutil.h> |
---|
29 | #include "gdk.h" |
---|
30 | #include "gdkprivate.h" |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | GdkRegion* |
---|
36 | gdk_region_new (void) |
---|
37 | { |
---|
38 | GdkRegionPrivate *private; |
---|
39 | GdkRegion *region; |
---|
40 | Region xregion; |
---|
41 | |
---|
42 | xregion = XCreateRegion(); |
---|
43 | private = g_new (GdkRegionPrivate, 1); |
---|
44 | private->xregion = xregion; |
---|
45 | region = (GdkRegion*) private; |
---|
46 | region->user_data = NULL; |
---|
47 | |
---|
48 | return region; |
---|
49 | } |
---|
50 | |
---|
51 | void |
---|
52 | gdk_region_destroy (GdkRegion *region) |
---|
53 | { |
---|
54 | GdkRegionPrivate *private; |
---|
55 | |
---|
56 | g_return_if_fail (region != NULL); |
---|
57 | |
---|
58 | private = (GdkRegionPrivate *) region; |
---|
59 | XDestroyRegion (private->xregion); |
---|
60 | |
---|
61 | g_free (private); |
---|
62 | } |
---|
63 | |
---|
64 | gboolean |
---|
65 | gdk_region_empty (GdkRegion *region) |
---|
66 | { |
---|
67 | GdkRegionPrivate *private; |
---|
68 | |
---|
69 | g_return_val_if_fail (region != NULL, 0); |
---|
70 | |
---|
71 | private = (GdkRegionPrivate *) region; |
---|
72 | |
---|
73 | return XEmptyRegion (private->xregion); |
---|
74 | } |
---|
75 | |
---|
76 | gboolean |
---|
77 | gdk_region_equal (GdkRegion *region1, |
---|
78 | GdkRegion *region2) |
---|
79 | { |
---|
80 | GdkRegionPrivate *private1; |
---|
81 | GdkRegionPrivate *private2; |
---|
82 | |
---|
83 | g_return_val_if_fail (region1 != NULL, 0); |
---|
84 | g_return_val_if_fail (region2 != NULL, 0); |
---|
85 | |
---|
86 | private1 = (GdkRegionPrivate *) region1; |
---|
87 | private2 = (GdkRegionPrivate *) region2; |
---|
88 | |
---|
89 | return XEqualRegion (private1->xregion, private2->xregion); |
---|
90 | } |
---|
91 | |
---|
92 | void |
---|
93 | gdk_region_get_clipbox(GdkRegion *region, |
---|
94 | GdkRectangle *rectangle) |
---|
95 | { |
---|
96 | GdkRegionPrivate *rp; |
---|
97 | XRectangle r; |
---|
98 | |
---|
99 | g_return_if_fail(region != NULL); |
---|
100 | g_return_if_fail(rectangle != NULL); |
---|
101 | |
---|
102 | rp = (GdkRegionPrivate *)region; |
---|
103 | XClipBox(rp->xregion, &r); |
---|
104 | |
---|
105 | rectangle->x = r.x; |
---|
106 | rectangle->y = r.y; |
---|
107 | rectangle->width = r.width; |
---|
108 | rectangle->height = r.height; |
---|
109 | } |
---|
110 | |
---|
111 | gboolean |
---|
112 | gdk_region_point_in (GdkRegion *region, |
---|
113 | gint x, |
---|
114 | gint y) |
---|
115 | { |
---|
116 | GdkRegionPrivate *private; |
---|
117 | |
---|
118 | g_return_val_if_fail (region != NULL, 0); |
---|
119 | |
---|
120 | private = (GdkRegionPrivate *) region; |
---|
121 | |
---|
122 | return XPointInRegion (private->xregion, x, y); |
---|
123 | } |
---|
124 | |
---|
125 | GdkOverlapType |
---|
126 | gdk_region_rect_in (GdkRegion *region, |
---|
127 | GdkRectangle *rect) |
---|
128 | { |
---|
129 | GdkRegionPrivate *private; |
---|
130 | int res; |
---|
131 | |
---|
132 | g_return_val_if_fail (region != NULL, 0); |
---|
133 | |
---|
134 | private = (GdkRegionPrivate *) region; |
---|
135 | |
---|
136 | res = XRectInRegion (private->xregion, rect->x, rect->y, rect->width, rect->height); |
---|
137 | |
---|
138 | switch (res) |
---|
139 | { |
---|
140 | case RectangleIn: return GDK_OVERLAP_RECTANGLE_IN; |
---|
141 | case RectangleOut: return GDK_OVERLAP_RECTANGLE_OUT; |
---|
142 | case RectanglePart: return GDK_OVERLAP_RECTANGLE_PART; |
---|
143 | } |
---|
144 | |
---|
145 | return GDK_OVERLAP_RECTANGLE_OUT; /*what else ? */ |
---|
146 | } |
---|
147 | |
---|
148 | GdkRegion * |
---|
149 | gdk_region_polygon (GdkPoint *points, |
---|
150 | gint npoints, |
---|
151 | GdkFillRule fill_rule) |
---|
152 | { |
---|
153 | GdkRegionPrivate *private; |
---|
154 | GdkRegion *region; |
---|
155 | Region xregion; |
---|
156 | gint xfill_rule = EvenOddRule; |
---|
157 | |
---|
158 | g_return_val_if_fail (points != NULL, NULL); |
---|
159 | g_return_val_if_fail (npoints != 0, NULL); /* maybe we should check for at least three points */ |
---|
160 | |
---|
161 | switch (fill_rule) |
---|
162 | { |
---|
163 | case GDK_EVEN_ODD_RULE: |
---|
164 | xfill_rule = EvenOddRule; |
---|
165 | break; |
---|
166 | |
---|
167 | case GDK_WINDING_RULE: |
---|
168 | xfill_rule = WindingRule; |
---|
169 | break; |
---|
170 | } |
---|
171 | |
---|
172 | xregion = XPolygonRegion ((XPoint *) points, npoints, xfill_rule); |
---|
173 | private = g_new (GdkRegionPrivate, 1); |
---|
174 | private->xregion = xregion; |
---|
175 | region = (GdkRegion *) private; |
---|
176 | region->user_data = NULL; |
---|
177 | |
---|
178 | return region; |
---|
179 | } |
---|
180 | |
---|
181 | void |
---|
182 | gdk_region_offset (GdkRegion *region, |
---|
183 | gint dx, |
---|
184 | gint dy) |
---|
185 | { |
---|
186 | GdkRegionPrivate *private; |
---|
187 | |
---|
188 | g_return_if_fail (region != NULL); |
---|
189 | |
---|
190 | private = (GdkRegionPrivate *) region; |
---|
191 | |
---|
192 | XOffsetRegion (private->xregion, dx, dy); |
---|
193 | } |
---|
194 | |
---|
195 | void |
---|
196 | gdk_region_shrink (GdkRegion *region, |
---|
197 | gint dx, |
---|
198 | gint dy) |
---|
199 | { |
---|
200 | GdkRegionPrivate *private; |
---|
201 | |
---|
202 | g_return_if_fail (region != NULL); |
---|
203 | |
---|
204 | private = (GdkRegionPrivate *) region; |
---|
205 | |
---|
206 | XShrinkRegion (private->xregion, dx, dy); |
---|
207 | } |
---|
208 | |
---|
209 | GdkRegion* |
---|
210 | gdk_region_union_with_rect (GdkRegion *region, |
---|
211 | GdkRectangle *rect) |
---|
212 | { |
---|
213 | GdkRegionPrivate *private; |
---|
214 | GdkRegion *res; |
---|
215 | GdkRegionPrivate *res_private; |
---|
216 | XRectangle xrect; |
---|
217 | |
---|
218 | g_return_val_if_fail (region != NULL, NULL); |
---|
219 | |
---|
220 | private = (GdkRegionPrivate *) region; |
---|
221 | |
---|
222 | xrect.x = rect->x; |
---|
223 | xrect.y = rect->y; |
---|
224 | xrect.width = rect->width; |
---|
225 | xrect.height = rect->height; |
---|
226 | |
---|
227 | res = gdk_region_new (); |
---|
228 | res_private = (GdkRegionPrivate *) res; |
---|
229 | |
---|
230 | XUnionRectWithRegion (&xrect, private->xregion, res_private->xregion); |
---|
231 | |
---|
232 | return res; |
---|
233 | } |
---|
234 | |
---|
235 | GdkRegion* |
---|
236 | gdk_regions_intersect (GdkRegion *source1, |
---|
237 | GdkRegion *source2) |
---|
238 | { |
---|
239 | GdkRegionPrivate *private1; |
---|
240 | GdkRegionPrivate *private2; |
---|
241 | GdkRegion *res; |
---|
242 | GdkRegionPrivate *res_private; |
---|
243 | |
---|
244 | g_return_val_if_fail (source1 != NULL, NULL); |
---|
245 | g_return_val_if_fail (source2 != NULL, NULL); |
---|
246 | |
---|
247 | private1 = (GdkRegionPrivate *) source1; |
---|
248 | private2 = (GdkRegionPrivate *) source2; |
---|
249 | |
---|
250 | res = gdk_region_new (); |
---|
251 | res_private = (GdkRegionPrivate *) res; |
---|
252 | |
---|
253 | XIntersectRegion (private1->xregion, private2->xregion, res_private->xregion); |
---|
254 | |
---|
255 | return res; |
---|
256 | } |
---|
257 | |
---|
258 | GdkRegion* |
---|
259 | gdk_regions_union (GdkRegion *source1, |
---|
260 | GdkRegion *source2) |
---|
261 | { |
---|
262 | GdkRegionPrivate *private1; |
---|
263 | GdkRegionPrivate *private2; |
---|
264 | GdkRegion *res; |
---|
265 | GdkRegionPrivate *res_private; |
---|
266 | |
---|
267 | g_return_val_if_fail (source1 != NULL, NULL); |
---|
268 | g_return_val_if_fail (source2 != NULL, NULL); |
---|
269 | |
---|
270 | private1 = (GdkRegionPrivate *) source1; |
---|
271 | private2 = (GdkRegionPrivate *) source2; |
---|
272 | |
---|
273 | res = gdk_region_new (); |
---|
274 | res_private = (GdkRegionPrivate *) res; |
---|
275 | |
---|
276 | XUnionRegion (private1->xregion, private2->xregion, res_private->xregion); |
---|
277 | |
---|
278 | return res; |
---|
279 | } |
---|
280 | |
---|
281 | GdkRegion* |
---|
282 | gdk_regions_subtract (GdkRegion *source1, |
---|
283 | GdkRegion *source2) |
---|
284 | { |
---|
285 | GdkRegionPrivate *private1; |
---|
286 | GdkRegionPrivate *private2; |
---|
287 | GdkRegion *res; |
---|
288 | GdkRegionPrivate *res_private; |
---|
289 | |
---|
290 | g_return_val_if_fail (source1 != NULL, NULL); |
---|
291 | g_return_val_if_fail (source2 != NULL, NULL); |
---|
292 | |
---|
293 | private1 = (GdkRegionPrivate *) source1; |
---|
294 | private2 = (GdkRegionPrivate *) source2; |
---|
295 | |
---|
296 | res = gdk_region_new (); |
---|
297 | res_private = (GdkRegionPrivate *) res; |
---|
298 | |
---|
299 | XSubtractRegion (private1->xregion, private2->xregion, res_private->xregion); |
---|
300 | |
---|
301 | return res; |
---|
302 | } |
---|
303 | |
---|
304 | GdkRegion* |
---|
305 | gdk_regions_xor (GdkRegion *source1, |
---|
306 | GdkRegion *source2) |
---|
307 | { |
---|
308 | GdkRegionPrivate *private1; |
---|
309 | GdkRegionPrivate *private2; |
---|
310 | GdkRegion *res; |
---|
311 | GdkRegionPrivate *res_private; |
---|
312 | |
---|
313 | g_return_val_if_fail (source1 != NULL, NULL); |
---|
314 | g_return_val_if_fail (source2 != NULL, NULL); |
---|
315 | |
---|
316 | private1 = (GdkRegionPrivate *) source1; |
---|
317 | private2 = (GdkRegionPrivate *) source2; |
---|
318 | |
---|
319 | res = gdk_region_new (); |
---|
320 | res_private = (GdkRegionPrivate *) res; |
---|
321 | |
---|
322 | XXorRegion (private1->xregion, private2->xregion, res_private->xregion); |
---|
323 | |
---|
324 | return res; |
---|
325 | } |
---|
326 | |
---|
327 | |
---|
328 | |
---|