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