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.gdk;
30 public  import gtkc.gdktypes;
31 private import gtkd.Loader;
32 
33 
34 /**
35  * A #GdkRGBA is used to represent a (possibly translucent)
36  * color, in a way that is compatible with cairos notion of color.
37  */
38 public class RGBA
39 {
40 	/** the main Gtk struct */
41 	protected GdkRGBA* gdkRGBA;
42 	protected bool ownedRef;
43 
44 	/** Get the main Gtk struct */
45 	public GdkRGBA* getRGBAStruct(bool transferOwnership = false)
46 	{
47 		if (transferOwnership)
48 			ownedRef = false;
49 		return gdkRGBA;
50 	}
51 
52 	/** the main Gtk struct as a void* */
53 	protected void* getStruct()
54 	{
55 		return cast(void*)gdkRGBA;
56 	}
57 
58 	/**
59 	 * Sets our main struct and passes it to the parent class.
60 	 */
61 	public this (GdkRGBA* gdkRGBA, bool ownedRef = false)
62 	{
63 		this.gdkRGBA = gdkRGBA;
64 		this.ownedRef = ownedRef;
65 	}
66 
67 	~this ()
68 	{
69 		if (  Linker.isLoaded(LIBRARY_GDK) && ownedRef )
70 			gdk_rgba_free(gdkRGBA);
71 	}
72 
73 	/**
74 	 * Creates a new RGBA Color
75 	 */
76 	this()
77 	{
78 		GdkRGBA rgba = GdkRGBA(0, 0, 0, 0);
79 		
80 		this(gdk_rgba_copy(&rgba), true);
81 	}
82 	
83 	/** ditto */
84 	this(double red, double green, double blue, double alpha = 1.0)
85 	{
86 		GdkRGBA rgba;
87 		
88 		rgba.red = red;
89 		rgba.green = green;
90 		rgba.blue = blue;
91 		rgba.alpha = alpha;
92 		
93 		this(gdk_rgba_copy(&rgba), true);
94 	}
95 	
96 	/**
97 	 * The color values.
98 	 * All values are in the range from 0.0 to 1.0 inclusive.
99 	 */
100 	double red()
101 	{
102 		return gdkRGBA.red;
103 	}
104 	
105 	/** ditto */
106 	void red(double value)
107 	{
108 		gdkRGBA.red = value;
109 	}
110 	
111 	/** ditto */
112 	double green()
113 	{
114 		return gdkRGBA.green;
115 	}
116 	
117 	/** ditto */
118 	void green(double value)
119 	{
120 		gdkRGBA.green = value;
121 	}
122 	
123 	/** ditto */
124 	double blue()
125 	{
126 		return gdkRGBA.blue;
127 	}
128 	
129 	/** ditto */
130 	void blue(double value)
131 	{
132 		gdkRGBA.blue = value;
133 	}
134 	
135 	/** ditto */
136 	double alpha()
137 	{
138 		return gdkRGBA.alpha;
139 	}
140 	
141 	/** ditto */
142 	void alpha(double value)
143 	{
144 		gdkRGBA.alpha = value;
145 	}
146 
147 	/**
148 	 */
149 
150 	/** */
151 	public static GType getType()
152 	{
153 		return gdk_rgba_get_type();
154 	}
155 
156 	/**
157 	 * Makes a copy of a #GdkRGBA.
158 	 *
159 	 * The result must be freed through gdk_rgba_free().
160 	 *
161 	 * Returns: A newly allocated #GdkRGBA, with the same contents as @rgba
162 	 *
163 	 * Since: 3.0
164 	 */
165 	public RGBA copy()
166 	{
167 		auto p = gdk_rgba_copy(gdkRGBA);
168 		
169 		if(p is null)
170 		{
171 			return null;
172 		}
173 		
174 		return ObjectG.getDObject!(RGBA)(cast(GdkRGBA*) p, true);
175 	}
176 
177 	/**
178 	 * Compares two RGBA colors.
179 	 *
180 	 * Params:
181 	 *     p2 = another #GdkRGBA pointer
182 	 *
183 	 * Returns: %TRUE if the two colors compare equal
184 	 *
185 	 * Since: 3.0
186 	 */
187 	public bool equal(RGBA p2)
188 	{
189 		return gdk_rgba_equal(gdkRGBA, (p2 is null) ? null : p2.getRGBAStruct()) != 0;
190 	}
191 
192 	/**
193 	 * Frees a #GdkRGBA created with gdk_rgba_copy()
194 	 *
195 	 * Since: 3.0
196 	 */
197 	public void free()
198 	{
199 		gdk_rgba_free(gdkRGBA);
200 		ownedRef = false;
201 	}
202 
203 	/**
204 	 * A hash function suitable for using for a hash
205 	 * table that stores #GdkRGBAs.
206 	 *
207 	 * Returns: 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 	 * Returns: %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 	 * Returns: 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 }