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