1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = 
27  * outPack = gdk
28  * outFile = Region
29  * strct   = GdkRegion
30  * realStrct=
31  * ctorStrct=
32  * clss    = Region
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gdk_region_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- gdk.Rectangle
47  * structWrap:
48  * 	- GdkRectangle* -> Rectangle
49  * 	- GdkRegion* -> Region
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module gdk.Region;
56 
57 public  import gtkc.gdktypes;
58 
59 private import gtkc.gdk;
60 private import glib.ConstructionException;
61 private import gobject.ObjectG;
62 
63 
64 private import gdk.Rectangle;
65 
66 
67 
68 
69 /**
70  * Description
71  * GDK provides the GdkPoint, GdkRectangle, GdkRegion and GdkSpan data types
72  * for representing pixels and sets of pixels on the screen.
73  * GdkPoint is a simple structure containing an x and y coordinate of a point.
74  * GdkRectangle is a structure holding the position and size of a rectangle.
75  * The intersection of two rectangles can be computed with
76  * gdk_rectangle_intersect(). To find the union of two rectangles use
77  * gdk_rectangle_union().
78  * GdkRegion is an opaque data type holding a set of arbitrary pixels, and is
79  * usually used for clipping graphical operations (see gdk_gc_set_clip_region()).
80  * GdkSpan is a structure holding a spanline. A spanline is a horizontal line that
81  * is one pixel wide. It is mainly used when rasterizing other graphics primitives.
82  * It can be intersected to regions by using gdk_region_spans_intersect_foreach().
83  */
84 public class Region
85 {
86 	
87 	/** the main Gtk struct */
88 	protected GdkRegion* gdkRegion;
89 	
90 	
91 	public GdkRegion* getRegionStruct()
92 	{
93 		return gdkRegion;
94 	}
95 	
96 	
97 	/** the main Gtk struct as a void* */
98 	protected void* getStruct()
99 	{
100 		return cast(void*)gdkRegion;
101 	}
102 	
103 	/**
104 	 * Sets our main struct and passes it to the parent class
105 	 */
106 	public this (GdkRegion* gdkRegion)
107 	{
108 		this.gdkRegion = gdkRegion;
109 	}
110 	
111 	/**
112 	 */
113 	
114 	/**
115 	 * Creates a new empty GdkRegion.
116 	 * Throws: ConstructionException GTK+ fails to create the object.
117 	 */
118 	public this ()
119 	{
120 		// GdkRegion * gdk_region_new (void);
121 		auto p = gdk_region_new();
122 		if(p is null)
123 		{
124 			throw new ConstructionException("null returned by gdk_region_new()");
125 		}
126 		this(cast(GdkRegion*) p);
127 	}
128 	
129 	/**
130 	 * Warning
131 	 * gdk_region_polygon has been deprecated since version 2.22 and should not be used in newly-written code. There is no replacement. For working with paths, please
132 	 *  use Cairo.
133 	 * Creates a new GdkRegion using the polygon defined by a
134 	 * number of points.
135 	 * Params:
136 	 * points = an array of GdkPoint structs
137 	 * fillRule = specifies which pixels are included in the region when the
138 	 * polygon overlaps itself.
139 	 * Returns: a new GdkRegion based on the given polygon
140 	 */
141 	public static Region polygon(GdkPoint[] points, GdkFillRule fillRule)
142 	{
143 		// GdkRegion * gdk_region_polygon (const GdkPoint *points,  gint n_points,  GdkFillRule fill_rule);
144 		auto p = gdk_region_polygon(points.ptr, cast(int) points.length, fillRule);
145 		
146 		if(p is null)
147 		{
148 			return null;
149 		}
150 		
151 		return ObjectG.getDObject!(Region)(cast(GdkRegion*) p);
152 	}
153 	
154 	/**
155 	 * Copies region, creating an identical new region.
156 	 * Returns: a new region identical to region
157 	 */
158 	public Region copy()
159 	{
160 		// GdkRegion * gdk_region_copy (const GdkRegion *region);
161 		auto p = gdk_region_copy(gdkRegion);
162 		
163 		if(p is null)
164 		{
165 			return null;
166 		}
167 		
168 		return ObjectG.getDObject!(Region)(cast(GdkRegion*) p);
169 	}
170 	
171 	/**
172 	 * Creates a new region containing the area rectangle.
173 	 * Params:
174 	 * rectangle = a GdkRectangle
175 	 * Returns: a new region
176 	 */
177 	public static Region rectangle(Rectangle rectangle)
178 	{
179 		// GdkRegion * gdk_region_rectangle (const GdkRectangle *rectangle);
180 		auto p = gdk_region_rectangle((rectangle is null) ? null : rectangle.getRectangleStruct());
181 		
182 		if(p is null)
183 		{
184 			return null;
185 		}
186 		
187 		return ObjectG.getDObject!(Region)(cast(GdkRegion*) p);
188 	}
189 	
190 	/**
191 	 * Destroys a GdkRegion.
192 	 */
193 	public void destroy()
194 	{
195 		// void gdk_region_destroy (GdkRegion *region);
196 		gdk_region_destroy(gdkRegion);
197 	}
198 	
199 	/**
200 	 * Obtains the smallest rectangle which includes the entire GdkRegion.
201 	 * Params:
202 	 * rectangle = return location for the clipbox
203 	 */
204 	public void getClipbox(Rectangle rectangle)
205 	{
206 		// void gdk_region_get_clipbox (const GdkRegion *region,  GdkRectangle *rectangle);
207 		gdk_region_get_clipbox(gdkRegion, (rectangle is null) ? null : rectangle.getRectangleStruct());
208 	}
209 	
210 	/**
211 	 * Obtains the area covered by the region as a list of rectangles.
212 	 * The array returned in rectangles must be freed with g_free().
213 	 * Params:
214 	 * rectangles = return location for an array of rectangles. [array length=n_rectangles][transfer container]
215 	 */
216 	public void getRectangles(out GdkRectangle[] rectangles)
217 	{
218 		// void gdk_region_get_rectangles (const GdkRegion *region,  GdkRectangle **rectangles,  gint *n_rectangles);
219 		GdkRectangle* outrectangles = null;
220 		int nRectangles;
221 		
222 		gdk_region_get_rectangles(gdkRegion, &outrectangles, &nRectangles);
223 		
224 		rectangles = outrectangles[0 .. nRectangles];
225 	}
226 	
227 	/**
228 	 * Finds out if the GdkRegion is empty.
229 	 * Returns: TRUE if region is empty.
230 	 */
231 	public int empty()
232 	{
233 		// gboolean gdk_region_empty (const GdkRegion *region);
234 		return gdk_region_empty(gdkRegion);
235 	}
236 	
237 	/**
238 	 * Finds out if the two regions are the same.
239 	 * Params:
240 	 * region2 = a GdkRegion
241 	 * Returns: TRUE if region1 and region2 are equal.
242 	 */
243 	public int equal(Region region2)
244 	{
245 		// gboolean gdk_region_equal (const GdkRegion *region1,  const GdkRegion *region2);
246 		return gdk_region_equal(gdkRegion, (region2 is null) ? null : region2.getRegionStruct());
247 	}
248 	
249 	/**
250 	 * Warning
251 	 * gdk_region_rect_equal has been deprecated since version 2.22 and should not be used in newly-written code. Use gdk_region_new_rect() and gdk_region_equal() to
252 	 *  achieve the same effect.
253 	 * Finds out if a regions is the same as a rectangle.
254 	 * Since 2.18
255 	 * Params:
256 	 * rectangle = a GdkRectangle
257 	 * Returns: TRUE if region and rectangle are equal.
258 	 */
259 	public int rectEqual(Rectangle rectangle)
260 	{
261 		// gboolean gdk_region_rect_equal (const GdkRegion *region,  const GdkRectangle *rectangle);
262 		return gdk_region_rect_equal(gdkRegion, (rectangle is null) ? null : rectangle.getRectangleStruct());
263 	}
264 	
265 	/**
266 	 * Finds out if a point is in a region.
267 	 * Params:
268 	 * x = the x coordinate of a point
269 	 * y = the y coordinate of a point
270 	 * Returns: TRUE if the point is in region.
271 	 */
272 	public int pointIn(int x, int y)
273 	{
274 		// gboolean gdk_region_point_in (const GdkRegion *region,  int x,  int y);
275 		return gdk_region_point_in(gdkRegion, x, y);
276 	}
277 	
278 	/**
279 	 * Tests whether a rectangle is within a region.
280 	 * Params:
281 	 * rectangle = a GdkRectangle.
282 	 * Returns: GDK_OVERLAP_RECTANGLE_IN, GDK_OVERLAP_RECTANGLE_OUT, or GDK_OVERLAP_RECTANGLE_PART, depending on whether the rectangle is inside, outside, or partly inside the GdkRegion, respectively.
283 	 */
284 	public GdkOverlapType rectIn(Rectangle rectangle)
285 	{
286 		// GdkOverlapType gdk_region_rect_in (const GdkRegion *region,  const GdkRectangle *rectangle);
287 		return gdk_region_rect_in(gdkRegion, (rectangle is null) ? null : rectangle.getRectangleStruct());
288 	}
289 	
290 	/**
291 	 * Moves a region the specified distance.
292 	 * Params:
293 	 * dx = the distance to move the region horizontally
294 	 * dy = the distance to move the region vertically
295 	 */
296 	public void offset(int dx, int dy)
297 	{
298 		// void gdk_region_offset (GdkRegion *region,  gint dx,  gint dy);
299 		gdk_region_offset(gdkRegion, dx, dy);
300 	}
301 	
302 	/**
303 	 * Warning
304 	 * gdk_region_shrink has been deprecated since version 2.22 and should not be used in newly-written code. There is no replacement for this function.
305 	 * Resizes a region by the specified amount.
306 	 * Positive values shrink the region. Negative values expand it.
307 	 * Params:
308 	 * dx = the number of pixels to shrink the region horizontally
309 	 * dy = the number of pixels to shrink the region vertically
310 	 */
311 	public void shrink(int dx, int dy)
312 	{
313 		// void gdk_region_shrink (GdkRegion *region,  gint dx,  gint dy);
314 		gdk_region_shrink(gdkRegion, dx, dy);
315 	}
316 	
317 	/**
318 	 * Sets the area of region to the union of the areas of region and
319 	 * rect. The resulting area is the set of pixels contained in
320 	 * either region or rect.
321 	 * Params:
322 	 * rect = a GdkRectangle.
323 	 */
324 	public void unionWithRect(Rectangle rect)
325 	{
326 		// void gdk_region_union_with_rect (GdkRegion *region,  const GdkRectangle *rect);
327 		gdk_region_union_with_rect(gdkRegion, (rect is null) ? null : rect.getRectangleStruct());
328 	}
329 	
330 	/**
331 	 * Sets the area of source1 to the intersection of the areas of source1
332 	 * and source2. The resulting area is the set of pixels contained in
333 	 * both source1 and source2.
334 	 * Params:
335 	 * source2 = another GdkRegion
336 	 */
337 	public void intersect(Region source2)
338 	{
339 		// void gdk_region_intersect (GdkRegion *source1,  const GdkRegion *source2);
340 		gdk_region_intersect(gdkRegion, (source2 is null) ? null : source2.getRegionStruct());
341 	}
342 	
343 	/**
344 	 * Sets the area of source1 to the union of the areas of source1 and
345 	 * source2. The resulting area is the set of pixels contained in
346 	 * either source1 or source2.
347 	 * Params:
348 	 * source2 = a GdkRegion
349 	 */
350 	public void unio(Region source2)
351 	{
352 		// void gdk_region_union (GdkRegion *source1,  const GdkRegion *source2);
353 		gdk_region_union(gdkRegion, (source2 is null) ? null : source2.getRegionStruct());
354 	}
355 	
356 	/**
357 	 * Subtracts the area of source2 from the area source1. The resulting
358 	 * area is the set of pixels contained in source1 but not in source2.
359 	 * Params:
360 	 * source2 = another GdkRegion
361 	 */
362 	public void subtract(Region source2)
363 	{
364 		// void gdk_region_subtract (GdkRegion *source1,  const GdkRegion *source2);
365 		gdk_region_subtract(gdkRegion, (source2 is null) ? null : source2.getRegionStruct());
366 	}
367 	
368 	/**
369 	 * Sets the area of source1 to the exclusive-OR of the areas of source1
370 	 * and source2. The resulting area is the set of pixels contained in one
371 	 * or the other of the two sources but not in both.
372 	 * Params:
373 	 * source2 = another GdkRegion
374 	 */
375 	public void xor(Region source2)
376 	{
377 		// void gdk_region_xor (GdkRegion *source1,  const GdkRegion *source2);
378 		gdk_region_xor(gdkRegion, (source2 is null) ? null : source2.getRegionStruct());
379 	}
380 	
381 	/**
382 	 * Warning
383 	 * gdk_region_spans_intersect_foreach has been deprecated since version 2.22 and should not be used in newly-written code. There is no replacement.
384 	 * Calls a function on each span in the intersection of region and spans.
385 	 * Params:
386 	 * spans = an array of GdkSpans
387 	 * sorted = TRUE if spans is sorted wrt. the y coordinate
388 	 * data = data to pass to function
389 	 */
390 	public void spansIntersectForeach(GdkSpan[] spans, int sorted, GdkSpanFunc funct, void* data)
391 	{
392 		// void gdk_region_spans_intersect_foreach (GdkRegion *region,  const GdkSpan *spans,  int n_spans,  gboolean sorted,  GdkSpanFunc function,  gpointer data);
393 		gdk_region_spans_intersect_foreach(gdkRegion, spans.ptr, cast(int) spans.length, sorted, funct, data);
394 	}
395 }