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