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 gdk.RGBA;
26 
27 private import glib.Str;
28 private import gobject.ObjectG;
29 private import gtkc.Loader;
30 private import gtkc.gdk;
31 public  import gtkc.gdktypes;
32 private import gtkc.paths;
33 
34 
35 /**
36  * A #GdkRGBA is used to represent a (possibly translucent)
37  * color, in a way that is compatible with cairos notion of color.
38  */
39 public class RGBA
40 {
41 	/** the main Gtk struct */
42 	protected GdkRGBA* gdkRGBA;
43 
44 	/** Get the main Gtk struct */
45 	public GdkRGBA* getRGBAStruct()
46 	{
47 		return gdkRGBA;
48 	}
49 
50 	/** the main Gtk struct as a void* */
51 	protected void* getStruct()
52 	{
53 		return cast(void*)gdkRGBA;
54 	}
55 
56 	/**
57 	 * Sets our main struct and passes it to the parent class.
58 	 */
59 	public this (GdkRGBA* gdkRGBA)
60 	{
61 		this.gdkRGBA = gdkRGBA;
62 	}
63 
64 	/**
65 	 * Creates a new RGBA Color
66 	 */
67 	this()
68 	{
69 		GdkRGBA rgba = GdkRGBA(0, 0, 0, 0);
70 		
71 		this(gdk_rgba_copy(&rgba));
72 	}
73 	
74 	/** ditto */
75 	this(double red, double green, double blue, double alpha = 1.0)
76 	{
77 		GdkRGBA rgba;
78 		
79 		rgba.red = red;
80 		rgba.green = green;
81 		rgba.blue = blue;
82 		rgba.alpha = alpha;
83 		
84 		this(gdk_rgba_copy(&rgba));
85 	}
86 	
87 	~this ()
88 	{
89 		if ( Linker.isLoaded(LIBRARY.GDK) && gdkRGBA !is null )
90 		{
91 			gdk_rgba_free(gdkRGBA);
92 		}
93 	}
94 	
95 	/**
96 	 * The color values.
97 	 * All values are in the range from 0.0 to 1.0 inclusive.
98 	 */
99 	double red()
100 	{
101 		return gdkRGBA.red;
102 	}
103 	
104 	/** ditto */
105 	void red(double value)
106 	{
107 		gdkRGBA.red = value;
108 	}
109 	
110 	/** ditto */
111 	double green()
112 	{
113 		return gdkRGBA.green;
114 	}
115 	
116 	/** ditto */
117 	void green(double value)
118 	{
119 		gdkRGBA.green = value;
120 	}
121 	
122 	/** ditto */
123 	double blue()
124 	{
125 		return gdkRGBA.blue;
126 	}
127 	
128 	/** ditto */
129 	void blue(double value)
130 	{
131 		gdkRGBA.blue = value;
132 	}
133 	
134 	/** ditto */
135 	double alpha()
136 	{
137 		return gdkRGBA.alpha;
138 	}
139 	
140 	/** ditto */
141 	void alpha(double value)
142 	{
143 		gdkRGBA.alpha = value;
144 	}
145 
146 	/**
147 	 */
148 
149 	/** */
150 	public static GType getType()
151 	{
152 		return gdk_rgba_get_type();
153 	}
154 
155 	/**
156 	 * Makes a copy of a #GdkRGBA.
157 	 *
158 	 * The result must be freed through gdk_rgba_free().
159 	 *
160 	 * Return: A newly allocated #GdkRGBA, with the same contents as @rgba
161 	 *
162 	 * Since: 3.0
163 	 */
164 	public RGBA copy()
165 	{
166 		auto p = gdk_rgba_copy(gdkRGBA);
167 		
168 		if(p is null)
169 		{
170 			return null;
171 		}
172 		
173 		return ObjectG.getDObject!(RGBA)(cast(GdkRGBA*) p);
174 	}
175 
176 	/**
177 	 * Compares two RGBA colors.
178 	 *
179 	 * Params:
180 	 *     p2 = another #GdkRGBA pointer
181 	 *
182 	 * Return: %TRUE if the two colors compare equal
183 	 *
184 	 * Since: 3.0
185 	 */
186 	public bool equal(RGBA p2)
187 	{
188 		return gdk_rgba_equal(gdkRGBA, (p2 is null) ? null : p2.getRGBAStruct()) != 0;
189 	}
190 
191 	/**
192 	 * Frees a #GdkRGBA created with gdk_rgba_copy()
193 	 *
194 	 * Since: 3.0
195 	 */
196 	public void free()
197 	{
198 		gdk_rgba_free(gdkRGBA);
199 	}
200 
201 	/**
202 	 * A hash function suitable for using for a hash
203 	 * table that stores #GdkRGBAs.
204 	 *
205 	 * Return: The hash value for @p
206 	 *
207 	 * Since: 3.0
208 	 */
209 	public uint hash()
210 	{
211 		return gdk_rgba_hash(gdkRGBA);
212 	}
213 
214 	/**
215 	 * Parses a textual representation of a color, filling in
216 	 * the @red, @green, @blue and @alpha fields of the @rgba #GdkRGBA.
217 	 *
218 	 * The string can be either one of:
219 	 * - A standard name (Taken from the X11 rgb.txt file).
220 	 * - A hexadecimal value in the form “\#rgb”, “\#rrggbb”,
221 	 * “\#rrrgggbbb” or ”\#rrrrggggbbbb”
222 	 * - A RGB color in the form “rgb(r,g,b)” (In this case the color will
223 	 * have full opacity)
224 	 * - A RGBA color in the form “rgba(r,g,b,a)”
225 	 *
226 	 * Where “r”, “g”, “b” and “a” are respectively the red, green, blue and
227 	 * alpha color values. In the last two cases, r g and b are either integers
228 	 * in the range 0 to 255 or precentage values in the range 0% to 100%, and
229 	 * a is a floating point value in the range 0 to 1.
230 	 *
231 	 * Params:
232 	 *     spec = the string specifying the color
233 	 *
234 	 * Return: %TRUE if the parsing succeeded
235 	 *
236 	 * Since: 3.0
237 	 */
238 	public bool parse(string spec)
239 	{
240 		return gdk_rgba_parse(gdkRGBA, Str.toStringz(spec)) != 0;
241 	}
242 
243 	/**
244 	 * Returns a textual specification of @rgba in the form
245 	 * `rgb (r, g, b)` or
246 	 * `rgba (r, g, b, a)`,
247 	 * where “r”, “g”, “b” and “a” represent the red, green,
248 	 * blue and alpha values respectively. r, g, and b are
249 	 * represented as integers in the range 0 to 255, and a
250 	 * is represented as floating point value in the range 0 to 1.
251 	 *
252 	 * These string forms are string forms those supported by
253 	 * the CSS3 colors module, and can be parsed by gdk_rgba_parse().
254 	 *
255 	 * Note that this string representation may lose some
256 	 * precision, since r, g and b are represented as 8-bit
257 	 * integers. If this is a concern, you should use a
258 	 * different representation.
259 	 *
260 	 * Return: A newly allocated text string
261 	 *
262 	 * Since: 3.0
263 	 */
264 	public override string toString()
265 	{
266 		return Str.toString(gdk_rgba_to_string(gdkRGBA));
267 	}
268 }