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