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 	public static GType getType()
150 	{
151 		return gdk_rgba_get_type();
152 	}
153 
154 	/**
155 	 * Makes a copy of a #GdkRGBA.
156 	 *
157 	 * The result must be freed through gdk_rgba_free().
158 	 *
159 	 * Return: A newly allocated #GdkRGBA, with the same contents as @rgba
160 	 *
161 	 * Since: 3.0
162 	 */
163 	public RGBA copy()
164 	{
165 		auto p = gdk_rgba_copy(gdkRGBA);
166 		
167 		if(p is null)
168 		{
169 			return null;
170 		}
171 		
172 		return ObjectG.getDObject!(RGBA)(cast(GdkRGBA*) p);
173 	}
174 
175 	/**
176 	 * Compares two RGBA colors.
177 	 *
178 	 * Params:
179 	 *     p2 = another #GdkRGBA pointer
180 	 *
181 	 * Return: %TRUE if the two colors compare equal
182 	 *
183 	 * Since: 3.0
184 	 */
185 	public bool equal(RGBA p2)
186 	{
187 		return gdk_rgba_equal(gdkRGBA, (p2 is null) ? null : p2.getRGBAStruct()) != 0;
188 	}
189 
190 	/**
191 	 * Frees a #GdkRGBA created with gdk_rgba_copy()
192 	 *
193 	 * Since: 3.0
194 	 */
195 	public void free()
196 	{
197 		gdk_rgba_free(gdkRGBA);
198 	}
199 
200 	/**
201 	 * A hash function suitable for using for a hash
202 	 * table that stores #GdkRGBAs.
203 	 *
204 	 * Return: The hash value for @p
205 	 *
206 	 * Since: 3.0
207 	 */
208 	public uint hash()
209 	{
210 		return gdk_rgba_hash(gdkRGBA);
211 	}
212 
213 	/**
214 	 * Parses a textual representation of a color, filling in
215 	 * the @red, @green, @blue and @alpha fields of the @rgba #GdkRGBA.
216 	 *
217 	 * The string can be either one of:
218 	 * - A standard name (Taken from the X11 rgb.txt file).
219 	 * - A hexadecimal value in the form “\#rgb”, “\#rrggbb”,
220 	 * “\#rrrgggbbb” or ”\#rrrrggggbbbb”
221 	 * - A RGB color in the form “rgb(r,g,b)” (In this case the color will
222 	 * have full opacity)
223 	 * - A RGBA color in the form “rgba(r,g,b,a)”
224 	 *
225 	 * Where “r”, “g”, “b” and “a” are respectively the red, green, blue and
226 	 * alpha color values. In the last two cases, r g and b are either integers
227 	 * in the range 0 to 255 or precentage values in the range 0% to 100%, and
228 	 * a is a floating point value in the range 0 to 1.
229 	 *
230 	 * Params:
231 	 *     spec = the string specifying the color
232 	 *
233 	 * Return: %TRUE if the parsing succeeded
234 	 *
235 	 * Since: 3.0
236 	 */
237 	public bool parse(string spec)
238 	{
239 		return gdk_rgba_parse(gdkRGBA, Str.toStringz(spec)) != 0;
240 	}
241 
242 	/**
243 	 * Returns a textual specification of @rgba in the form
244 	 * `rgb (r, g, b)` or
245 	 * `rgba (r, g, b, a)`,
246 	 * where “r”, “g”, “b” and “a” represent the red, green,
247 	 * blue and alpha values respectively. r, g, and b are
248 	 * represented as integers in the range 0 to 255, and a
249 	 * is represented as floating point value in the range 0 to 1.
250 	 *
251 	 * These string forms are string forms those supported by
252 	 * the CSS3 colors module, and can be parsed by gdk_rgba_parse().
253 	 *
254 	 * Note that this string representation may lose some
255 	 * precision, since r, g and b are represented as 8-bit
256 	 * integers. If this is a concern, you should use a
257 	 * different representation.
258 	 *
259 	 * Return: A newly allocated text string
260 	 *
261 	 * Since: 3.0
262 	 */
263 	public override string toString()
264 	{
265 		return Str.toString(gdk_rgba_to_string(gdkRGBA));
266 	}
267 }