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  * Conversion parameters:
26  * inFile  = gdk3-Colors.html
27  * outPack = gdk
28  * outFile = Color
29  * strct   = GdkColor
30  * realStrct=
31  * ctorStrct=
32  * clss    = Color
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gdk_color_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gtkc.paths;
48  * 	- gtkc.Loader;
49  * structWrap:
50  * 	- GdkColor* -> Color
51  * module aliases:
52  * local aliases:
53  * overrides:
54  * 	- toString
55  */
56 
57 module gdk.Color;
58 
59 public  import gtkc.gdktypes;
60 
61 private import gtkc.gdk;
62 private import glib.ConstructionException;
63 private import gobject.ObjectG;
64 
65 private import glib.Str;
66 private import gtkc.paths;;
67 private import gtkc.Loader;;
68 
69 
70 
71 /**
72  * A GdkColor represents a color.
73  *
74  * When working with cairo, it is often more convenient
75  * to use a GdkRGBA instead.
76  */
77 public class Color
78 {
79 	
80 	/** the main Gtk struct */
81 	protected GdkColor* gdkColor;
82 	
83 	
84 	/** Get the main Gtk struct */
85 	public GdkColor* getColorStruct()
86 	{
87 		return gdkColor;
88 	}
89 	
90 	
91 	/** the main Gtk struct as a void* */
92 	protected void* getStruct()
93 	{
94 		return cast(void*)gdkColor;
95 	}
96 	
97 	/**
98 	 * Sets our main struct and passes it to the parent class
99 	 */
100 	public this (GdkColor* gdkColor)
101 	{
102 		this.gdkColor = gdkColor;
103 	}
104 	
105 	/**
106 	 * Creates a new Color
107 	 */
108 	this()
109 	{
110 		GdkColor color;
111 		
112 		this(gdk_color_copy(&color));
113 	}
114 	
115 	/** ditto */
116 	this(ubyte red, ubyte green, ubyte blue)
117 	{
118 		GdkColor color;
119 		
120 		color.red = cast(ushort)(red * 257);
121 		color.green = cast(ushort)(green * 257);
122 		color.blue = cast(ushort)(blue * 257);
123 		
124 		this(gdk_color_copy(&color));
125 	}
126 	
127 	/** ditto */
128 	this(ushort red, ushort green, ushort blue)
129 	{
130 		GdkColor color;
131 		
132 		color.red = red;
133 		color.green = green;
134 		color.blue = blue;
135 		
136 		this(gdk_color_copy(&color));
137 	}
138 	
139 	~this ()
140 	{
141 		if ( Linker.isLoaded(LIBRARY.GDK) && gdkColor !is null )
142 		{
143 			gdk_color_free(gdkColor);
144 		}
145 	}
146 	
147 	/**
148 	 * The color values.
149 	 */
150 	ushort red()
151 	{
152 		return gdkColor.red;
153 	}
154 	
155 	/** ditto */
156 	void red(ushort value)
157 	{
158 		gdkColor.red = value;
159 		updatePixel();
160 	}
161 	
162 	/** ditto */
163 	ushort green()
164 	{
165 		return gdkColor.green;
166 	}
167 	
168 	/** ditto */
169 	void green(ushort value)
170 	{
171 		gdkColor.green = value;
172 		updatePixel();
173 	}
174 	
175 	/** ditto */
176 	ushort blue()
177 	{
178 		return gdkColor.blue;
179 	}
180 	
181 	/** ditto */
182 	void blue(ushort value)
183 	{
184 		gdkColor.blue = value;
185 		updatePixel();
186 	}
187 	
188 	/** ditto */
189 	uint pixel()
190 	{
191 		return gdkColor.pixel;
192 	}
193 	
194 	private void updatePixel()
195 	{
196 		gdkColor.pixel = (gdkColor.red&0xFF00 << 8) | (gdkColor.green&0xFF00) | (gdkColor.blue >> 8) ;
197 	}
198 	
199 	/**
200 	 */
201 	
202 	/**
203 	 * Makes a copy of a color structure.
204 	 * The result must be freed using gdk_color_free().
205 	 * Returns: a copy of color
206 	 */
207 	public Color copy()
208 	{
209 		// GdkColor * gdk_color_copy (const GdkColor *color);
210 		auto p = gdk_color_copy(gdkColor);
211 		
212 		if(p is null)
213 		{
214 			return null;
215 		}
216 		
217 		return ObjectG.getDObject!(Color)(cast(GdkColor*) p);
218 	}
219 	
220 	/**
221 	 * Frees a color structure created with gdk_color_copy().
222 	 */
223 	public void free()
224 	{
225 		// void gdk_color_free (GdkColor *color);
226 		gdk_color_free(gdkColor);
227 	}
228 	
229 	/**
230 	 * Parses a textual specification of a color and fill in the
231 	 * red, green,
232 	 * and blue fields of a GdkColor
233 	 * structure.
234 	 * The string can either one of a large set of standard names
235 	 * (taken from the X11 rgb.txt file), or
236 	 * it can be a hex value in the form '#rgb' '#rrggbb'
237 	 * '#rrrgggbbb' or '#rrrrggggbbbb' where 'r', 'g' and
238 	 * 'b' are hex digits of the red, green, and blue components
239 	 * of the color, respectively. (White in the four forms is
240 	 * '#fff', '#ffffff', '#fffffffff' and
241 	 * '#ffffffffffff').
242 	 * Params:
243 	 * spec = the string specifying the color
244 	 * color = the GdkColor to fill in. [out]
245 	 * Returns: TRUE if the parsing succeeded
246 	 */
247 	public static int parse(string spec, Color color)
248 	{
249 		// gboolean gdk_color_parse (const gchar *spec,  GdkColor *color);
250 		return gdk_color_parse(Str.toStringz(spec), (color is null) ? null : color.getColorStruct());
251 	}
252 	
253 	/**
254 	 * Compares two colors.
255 	 * Params:
256 	 * colorb = another GdkColor
257 	 * Returns: TRUE if the two colors compare equal
258 	 */
259 	public int equal(Color colorb)
260 	{
261 		// gboolean gdk_color_equal (const GdkColor *colora,  const GdkColor *colorb);
262 		return gdk_color_equal(gdkColor, (colorb is null) ? null : colorb.getColorStruct());
263 	}
264 	
265 	/**
266 	 * A hash function suitable for using for a hash
267 	 * table that stores GdkColors.
268 	 * Returns: The hash function applied to color
269 	 */
270 	public uint hash()
271 	{
272 		// guint gdk_color_hash (const GdkColor *color);
273 		return gdk_color_hash(gdkColor);
274 	}
275 	
276 	/**
277 	 * Returns a textual specification of color in the hexadecimal form
278 	 * #rrrrggggbbbb, where r,
279 	 * g and b are hex digits
280 	 * representing the red, green and blue components respectively.
281 	 * The returned string can be parsed by gdk_color_parse().
282 	 * Since 2.12
283 	 * Returns: a newly-allocated text string
284 	 */
285 	public override string toString()
286 	{
287 		// gchar * gdk_color_to_string (const GdkColor *color);
288 		return Str.toString(gdk_color_to_string(gdkColor));
289 	}
290 }