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 module graphene.Quad;
26 
27 private import glib.ConstructionException;
28 private import glib.MemorySlice;
29 private import gobject.ObjectG;
30 private import graphene.Point;
31 private import graphene.Rect;
32 private import graphene.c.functions;
33 public  import graphene.c.types;
34 private import gtkd.Loader;
35 
36 
37 /**
38  * A 4 vertex quadrilateral, as represented by four #graphene_point_t.
39  * 
40  * The contents of a #graphene_quad_t are private and should never be
41  * accessed directly.
42  *
43  * Since: 1.0
44  */
45 public class Quad
46 {
47 	/** the main Gtk struct */
48 	protected graphene_quad_t* graphene_quad;
49 	protected bool ownedRef;
50 
51 	/** Get the main Gtk struct */
52 	public graphene_quad_t* getQuadStruct(bool transferOwnership = false)
53 	{
54 		if (transferOwnership)
55 			ownedRef = false;
56 		return graphene_quad;
57 	}
58 
59 	/** the main Gtk struct as a void* */
60 	protected void* getStruct()
61 	{
62 		return cast(void*)graphene_quad;
63 	}
64 
65 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (graphene_quad_t* graphene_quad, bool ownedRef = false)
69 	{
70 		this.graphene_quad = graphene_quad;
71 		this.ownedRef = ownedRef;
72 	}
73 
74 	~this ()
75 	{
76 		if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef )
77 			graphene_quad_free(graphene_quad);
78 	}
79 
80 
81 	/** */
82 	public static GType getType()
83 	{
84 		return graphene_quad_get_type();
85 	}
86 
87 	/**
88 	 * Allocates a new #graphene_quad_t instance.
89 	 *
90 	 * The contents of the returned instance are undefined.
91 	 *
92 	 * Returns: the newly created #graphene_quad_t instance
93 	 *
94 	 * Since: 1.0
95 	 *
96 	 * Throws: ConstructionException GTK+ fails to create the object.
97 	 */
98 	public this()
99 	{
100 		auto __p = graphene_quad_alloc();
101 
102 		if(__p is null)
103 		{
104 			throw new ConstructionException("null returned by alloc");
105 		}
106 
107 		this(cast(graphene_quad_t*) __p);
108 	}
109 
110 	/**
111 	 * Computes the bounding rectangle of @q and places it into @r.
112 	 *
113 	 * Params:
114 	 *     r = return location for a #graphene_rect_t
115 	 *
116 	 * Since: 1.0
117 	 */
118 	public void bounds(out Rect r)
119 	{
120 		graphene_rect_t* outr = sliceNew!graphene_rect_t();
121 
122 		graphene_quad_bounds(graphene_quad, outr);
123 
124 		r = ObjectG.getDObject!(Rect)(outr, true);
125 	}
126 
127 	/**
128 	 * Checks if the given #graphene_quad_t contains the given #graphene_point_t.
129 	 *
130 	 * Params:
131 	 *     p = a #graphene_point_t
132 	 *
133 	 * Returns: `true` if the point is inside the #graphene_quad_t
134 	 *
135 	 * Since: 1.0
136 	 */
137 	public bool contains(Point p)
138 	{
139 		return graphene_quad_contains(graphene_quad, (p is null) ? null : p.getPointStruct()) != 0;
140 	}
141 
142 	/**
143 	 * Frees the resources allocated by graphene_quad_alloc()
144 	 *
145 	 * Since: 1.0
146 	 */
147 	public void free()
148 	{
149 		graphene_quad_free(graphene_quad);
150 		ownedRef = false;
151 	}
152 
153 	/**
154 	 * Retrieves the point of a #graphene_quad_t at the given index.
155 	 *
156 	 * Params:
157 	 *     index = the index of the point to retrieve
158 	 *
159 	 * Returns: a #graphene_point_t
160 	 *
161 	 * Since: 1.0
162 	 */
163 	public Point getPoint(uint index)
164 	{
165 		auto __p = graphene_quad_get_point(graphene_quad, index);
166 
167 		if(__p is null)
168 		{
169 			return null;
170 		}
171 
172 		return ObjectG.getDObject!(Point)(cast(graphene_point_t*) __p);
173 	}
174 
175 	/**
176 	 * Initializes a #graphene_quad_t with the given points.
177 	 *
178 	 * Params:
179 	 *     p1 = the first point of the quadrilateral
180 	 *     p2 = the second point of the quadrilateral
181 	 *     p3 = the third point of the quadrilateral
182 	 *     p4 = the fourth point of the quadrilateral
183 	 *
184 	 * Returns: the initialized #graphene_quad_t
185 	 *
186 	 * Since: 1.0
187 	 */
188 	public Quad init(Point p1, Point p2, Point p3, Point p4)
189 	{
190 		auto __p = graphene_quad_init(graphene_quad, (p1 is null) ? null : p1.getPointStruct(), (p2 is null) ? null : p2.getPointStruct(), (p3 is null) ? null : p3.getPointStruct(), (p4 is null) ? null : p4.getPointStruct());
191 
192 		if(__p is null)
193 		{
194 			return null;
195 		}
196 
197 		return ObjectG.getDObject!(Quad)(cast(graphene_quad_t*) __p);
198 	}
199 
200 	/**
201 	 * Initializes a #graphene_quad_t using an array of points.
202 	 *
203 	 * Params:
204 	 *     points = an array of 4 #graphene_point_t
205 	 *
206 	 * Returns: the initialized #graphene_quad_t
207 	 *
208 	 * Since: 1.2
209 	 */
210 	public Quad initFromPoints(Point[4] points)
211 	{
212 		graphene_point_t[] pointsArray = new graphene_point_t[points.length];
213 		for ( int i = 0; i < points.length; i++ )
214 		{
215 			pointsArray[i] = *(points[i].getPointStruct());
216 		}
217 
218 		auto __p = graphene_quad_init_from_points(graphene_quad, pointsArray.ptr);
219 
220 		if(__p is null)
221 		{
222 			return null;
223 		}
224 
225 		return ObjectG.getDObject!(Quad)(cast(graphene_quad_t*) __p);
226 	}
227 
228 	/**
229 	 * Initializes a #graphene_quad_t using the four corners of the
230 	 * given #graphene_rect_t.
231 	 *
232 	 * Params:
233 	 *     r = a #graphene_rect_t
234 	 *
235 	 * Returns: the initialized #graphene_quad_t
236 	 *
237 	 * Since: 1.0
238 	 */
239 	public Quad initFromRect(Rect r)
240 	{
241 		auto __p = graphene_quad_init_from_rect(graphene_quad, (r is null) ? null : r.getRectStruct());
242 
243 		if(__p is null)
244 		{
245 			return null;
246 		}
247 
248 		return ObjectG.getDObject!(Quad)(cast(graphene_quad_t*) __p);
249 	}
250 }