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