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.Size;
26 
27 private import glib.ConstructionException;
28 private import glib.MemorySlice;
29 private import gobject.ObjectG;
30 private import graphene.c.functions;
31 public  import graphene.c.types;
32 private import gtkd.Loader;
33 
34 
35 /**
36  * A size.
37  *
38  * Since: 1.0
39  */
40 public final class Size
41 {
42 	/** the main Gtk struct */
43 	protected graphene_size_t* graphene_size;
44 	protected bool ownedRef;
45 
46 	/** Get the main Gtk struct */
47 	public graphene_size_t* getSizeStruct(bool transferOwnership = false)
48 	{
49 		if (transferOwnership)
50 			ownedRef = false;
51 		return graphene_size;
52 	}
53 
54 	/** the main Gtk struct as a void* */
55 	protected void* getStruct()
56 	{
57 		return cast(void*)graphene_size;
58 	}
59 
60 	/**
61 	 * Sets our main struct and passes it to the parent class.
62 	 */
63 	public this (graphene_size_t* graphene_size, bool ownedRef = false)
64 	{
65 		this.graphene_size = graphene_size;
66 		this.ownedRef = ownedRef;
67 	}
68 
69 	~this ()
70 	{
71 		if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef )
72 			graphene_size_free(graphene_size);
73 	}
74 
75 
76 	/**
77 	 * the width
78 	 */
79 	public @property float width()
80 	{
81 		return graphene_size.width;
82 	}
83 
84 	/** Ditto */
85 	public @property void width(float value)
86 	{
87 		graphene_size.width = value;
88 	}
89 
90 	/**
91 	 * the height
92 	 */
93 	public @property float height()
94 	{
95 		return graphene_size.height;
96 	}
97 
98 	/** Ditto */
99 	public @property void height(float value)
100 	{
101 		graphene_size.height = value;
102 	}
103 
104 	/** */
105 	public static GType getType()
106 	{
107 		return graphene_size_get_type();
108 	}
109 
110 	/**
111 	 * Allocates a new #graphene_size_t.
112 	 *
113 	 * The contents of the returned value are undefined.
114 	 *
115 	 * Returns: the newly allocated #graphene_size_t
116 	 *
117 	 * Since: 1.0
118 	 *
119 	 * Throws: ConstructionException GTK+ fails to create the object.
120 	 */
121 	public this()
122 	{
123 		auto __p = graphene_size_alloc();
124 
125 		if(__p is null)
126 		{
127 			throw new ConstructionException("null returned by alloc");
128 		}
129 
130 		this(cast(graphene_size_t*) __p);
131 	}
132 
133 	/**
134 	 * Checks whether the two give #graphene_size_t are equal.
135 	 *
136 	 * Params:
137 	 *     b = a #graphene_size_t
138 	 *
139 	 * Returns: `true` if the sizes are equal
140 	 *
141 	 * Since: 1.0
142 	 */
143 	public bool equal(Size b)
144 	{
145 		return graphene_size_equal(graphene_size, (b is null) ? null : b.getSizeStruct()) != 0;
146 	}
147 
148 	/**
149 	 * Frees the resources allocated by graphene_size_alloc().
150 	 *
151 	 * Since: 1.0
152 	 */
153 	public void free()
154 	{
155 		graphene_size_free(graphene_size);
156 		ownedRef = false;
157 	}
158 
159 	/**
160 	 * Initializes a #graphene_size_t using the given @width and @height.
161 	 *
162 	 * Params:
163 	 *     width = the width
164 	 *     height = the height
165 	 *
166 	 * Returns: the initialized #graphene_size_t
167 	 *
168 	 * Since: 1.0
169 	 */
170 	public Size init(float width, float height)
171 	{
172 		auto __p = graphene_size_init(graphene_size, width, height);
173 
174 		if(__p is null)
175 		{
176 			return null;
177 		}
178 
179 		return ObjectG.getDObject!(Size)(cast(graphene_size_t*) __p);
180 	}
181 
182 	/**
183 	 * Initializes a #graphene_size_t using the width and height of
184 	 * the given @src.
185 	 *
186 	 * Params:
187 	 *     src = a #graphene_size_t
188 	 *
189 	 * Returns: the initialized #graphene_size_t
190 	 *
191 	 * Since: 1.0
192 	 */
193 	public Size initFromSize(Size src)
194 	{
195 		auto __p = graphene_size_init_from_size(graphene_size, (src is null) ? null : src.getSizeStruct());
196 
197 		if(__p is null)
198 		{
199 			return null;
200 		}
201 
202 		return ObjectG.getDObject!(Size)(cast(graphene_size_t*) __p);
203 	}
204 
205 	/**
206 	 * Linearly interpolates the two given #graphene_size_t using the given
207 	 * interpolation @factor.
208 	 *
209 	 * Params:
210 	 *     b = a #graphene_size_t
211 	 *     factor = the linear interpolation factor
212 	 *     res = return location for the interpolated size
213 	 *
214 	 * Since: 1.0
215 	 */
216 	public void interpolate(Size b, double factor, out Size res)
217 	{
218 		graphene_size_t* outres = sliceNew!graphene_size_t();
219 
220 		graphene_size_interpolate(graphene_size, (b is null) ? null : b.getSizeStruct(), factor, outres);
221 
222 		res = ObjectG.getDObject!(Size)(outres, true);
223 	}
224 
225 	/**
226 	 * Scales the components of a #graphene_size_t using the given @factor.
227 	 *
228 	 * Params:
229 	 *     factor = the scaling factor
230 	 *     res = return location for the scaled size
231 	 *
232 	 * Since: 1.0
233 	 */
234 	public void scale(float factor, out Size res)
235 	{
236 		graphene_size_t* outres = sliceNew!graphene_size_t();
237 
238 		graphene_size_scale(graphene_size, factor, outres);
239 
240 		res = ObjectG.getDObject!(Size)(outres, true);
241 	}
242 
243 	/**
244 	 * A constant pointer to a zero #graphene_size_t, useful for
245 	 * equality checks and interpolations.
246 	 *
247 	 * Returns: a constant size
248 	 *
249 	 * Since: 1.0
250 	 */
251 	public static Size zero()
252 	{
253 		auto __p = graphene_size_zero();
254 
255 		if(__p is null)
256 		{
257 			return null;
258 		}
259 
260 		return ObjectG.getDObject!(Size)(cast(graphene_size_t*) __p);
261 	}
262 }