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  = gdk3-RGBA-Colors.html
27  * outPack = gdk
28  * outFile = RGBA
29  * strct   = GdkRGBA
30  * realStrct=
31  * ctorStrct=
32  * clss    = RGBA
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gdk_rgba_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gtkc.paths;
48  * 	- gtkc.Loader;
49  * structWrap:
50  * 	- GdkRGBA* -> RGBA
51  * module aliases:
52  * local aliases:
53  * overrides:
54  * 	- toString
55  */
56 
57 module gdk.RGBA;
58 
59 public  import gtkc.gdktypes;
60 
61 private import gtkc.gdk;
62 private import glib.ConstructionException;
63 private import gobject.ObjectG;
64 
65 
66 private import glib.Str;
67 private import gtkc.paths;;
68 private import gtkc.Loader;;
69 
70 
71 
72 
73 /**
74  * The GdkRGBA struct is a convenient way to pass rgba colors around.
75  * It's based on cairo's way to deal with colors and mirrors its behavior.
76  * All values are in the range from 0.0 to 1.0 inclusive. So the color
77  * (0.0, 0.0, 0.0, 0.0) represents transparent black and
78  * (1.0, 1.0, 1.0, 1.0) is opaque white. Other values will be clamped
79  * to this range when drawing.
80  */
81 public class RGBA
82 {
83 	
84 	/** the main Gtk struct */
85 	protected GdkRGBA* gdkRGBA;
86 	
87 	
88 	public GdkRGBA* getRGBAStruct()
89 	{
90 		return gdkRGBA;
91 	}
92 	
93 	
94 	/** the main Gtk struct as a void* */
95 	protected void* getStruct()
96 	{
97 		return cast(void*)gdkRGBA;
98 	}
99 	
100 	/**
101 	 * Sets our main struct and passes it to the parent class
102 	 */
103 	public this (GdkRGBA* gdkRGBA)
104 	{
105 		this.gdkRGBA = gdkRGBA;
106 	}
107 	
108 	/**
109 	 * Creates a new RGBA Color
110 	 */
111 	this()
112 	{
113 		GdkRGBA rgba;
114 		
115 		this(gdk_rgba_copy(&rgba));
116 	}
117 	
118 	/** ditto */
119 	this(double red, double green, double blue, double alpha = 1.0)
120 	{
121 		GdkRGBA rgba;
122 		
123 		rgba.red = red;
124 		rgba.green = green;
125 		rgba.blue = blue;
126 		rgba.alpha = alpha;
127 		
128 		this(gdk_rgba_copy(&rgba));
129 	}
130 	
131 	~this ()
132 	{
133 		if ( Linker.isLoaded(LIBRARY.GDK) && gdkRGBA !is null )
134 		{
135 			gdk_rgba_free(gdkRGBA);
136 		}
137 	}
138 	
139 	/**
140 	 * The color values.
141 	 * All values are in the range from 0.0 to 1.0 inclusive.
142 	 */
143 	double red()
144 	{
145 		return gdkRGBA.red;
146 	}
147 	
148 	/** ditto */
149 	void red(double value)
150 	{
151 		gdkRGBA.red = value;
152 	}
153 	
154 	/** ditto */
155 	double green()
156 	{
157 		return gdkRGBA.green;
158 	}
159 	
160 	/** ditto */
161 	void green(double value)
162 	{
163 		gdkRGBA.green = value;
164 	}
165 	
166 	/** ditto */
167 	double blue()
168 	{
169 		return gdkRGBA.blue;
170 	}
171 	
172 	/** ditto */
173 	void blue(double value)
174 	{
175 		gdkRGBA.blue = value;
176 	}
177 	
178 	/** ditto */
179 	double alpha()
180 	{
181 		return gdkRGBA.alpha;
182 	}
183 	
184 	/** ditto */
185 	void alpha(double value)
186 	{
187 		gdkRGBA.alpha = value;
188 	}
189 	
190 	/**
191 	 */
192 	
193 	/**
194 	 * Makes a copy of a GdkRGBA structure.
195 	 * The result must be freed through gdk_rgba_free().
196 	 * Returns: A newly allocated GdkRGBA, with the same contents as rgba Since 3.0
197 	 */
198 	public RGBA copy()
199 	{
200 		// GdkRGBA * gdk_rgba_copy (const GdkRGBA *rgba);
201 		auto p = gdk_rgba_copy(gdkRGBA);
202 		
203 		if(p is null)
204 		{
205 			return null;
206 		}
207 		
208 		return ObjectG.getDObject!(RGBA)(cast(GdkRGBA*) p);
209 	}
210 	
211 	/**
212 	 * Frees a GdkRGBA struct created with gdk_rgba_copy()
213 	 */
214 	public void free()
215 	{
216 		// void gdk_rgba_free (GdkRGBA *rgba);
217 		gdk_rgba_free(gdkRGBA);
218 	}
219 	
220 	/**
221 	 * Parses a textual representation of a color, filling in
222 	 * the red, green,
223 	 * blue and alpha
224 	 * fields of the rgba struct.
225 	 * Params:
226 	 * spec = the string specifying the color
227 	 * Returns: TRUE if the parsing succeeded Since 3.0
228 	 */
229 	public int parse(string spec)
230 	{
231 		// gboolean gdk_rgba_parse (GdkRGBA *rgba,  const gchar *spec);
232 		return gdk_rgba_parse(gdkRGBA, Str.toStringz(spec));
233 	}
234 	
235 	/**
236 	 * Compares two RGBA colors.
237 	 * Params:
238 	 * p1 = a GdkRGBA pointer. [type GdkRGBA]
239 	 * p2 = another GdkRGBA pointer. [type GdkRGBA]
240 	 * Returns: TRUE if the two colors compare equal Since 3.0
241 	 */
242 	public static int equal(void* p1, void* p2)
243 	{
244 		// gboolean gdk_rgba_equal (gconstpointer p1,  gconstpointer p2);
245 		return gdk_rgba_equal(p1, p2);
246 	}
247 	
248 	/**
249 	 * A hash function suitable for using for a hash
250 	 * table that stores GdkRGBAs.
251 	 * Params:
252 	 * p = a GdkRGBA pointer. [type GdkRGBA]
253 	 * Returns: The hash value for p Since 3.0
254 	 */
255 	public static uint hash(void* p)
256 	{
257 		// guint gdk_rgba_hash (gconstpointer p);
258 		return gdk_rgba_hash(p);
259 	}
260 	
261 	/**
262 	 * Returns a textual specification of rgba in the form
263 	 * rgb (r, g, b) or
264 	 * rgba (r, g, b, a),
265 	 * where 'r', 'g', 'b' and 'a' represent the red, green,
266 	 * blue and alpha values respectively. r, g, and b are
267 	 * represented as integers in the range 0 to 255, and a
268 	 * is represented as floating point value in the range 0 to 1.
269 	 * These string forms are string forms those supported by
270 	 * the CSS3 colors module, and can be parsed by gdk_rgba_parse().
271 	 * Note that this string representation may lose some
272 	 * precision, since r, g and b are represented as 8-bit
273 	 * integers. If this is a concern, you should use a
274 	 * different representation.
275 	 * Returns: A newly allocated text string Since 3.0
276 	 */
277 	public override string toString()
278 	{
279 		// gchar * gdk_rgba_to_string (const GdkRGBA *rgba);
280 		return Str.toString(gdk_rgba_to_string(gdkRGBA));
281 	}
282 }