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 	/** */
164 	public static GType getType()
165 	{
166 		return gdk_color_get_type();
167 	}
168 
169 	/**
170 	 * Makes a copy of a #GdkColor.
171 	 *
172 	 * The result must be freed using gdk_color_free().
173 	 *
174 	 * Deprecated: Use #GdkRGBA
175 	 *
176 	 * Return: a copy of @color
177 	 */
178 	public Color copy()
179 	{
180 		auto p = gdk_color_copy(gdkColor);
181 		
182 		if(p is null)
183 		{
184 			return null;
185 		}
186 		
187 		return ObjectG.getDObject!(Color)(cast(GdkColor*) p);
188 	}
189 
190 	/**
191 	 * Compares two colors.
192 	 *
193 	 * Deprecated: Use #GdkRGBA
194 	 *
195 	 * Params:
196 	 *     colorb = another #GdkColor
197 	 *
198 	 * Return: %TRUE if the two colors compare equal
199 	 */
200 	public bool equal(Color colorb)
201 	{
202 		return gdk_color_equal(gdkColor, (colorb is null) ? null : colorb.getColorStruct()) != 0;
203 	}
204 
205 	/**
206 	 * Frees a #GdkColor created with gdk_color_copy().
207 	 *
208 	 * Deprecated: Use #GdkRGBA
209 	 */
210 	public void free()
211 	{
212 		gdk_color_free(gdkColor);
213 	}
214 
215 	/**
216 	 * A hash function suitable for using for a hash
217 	 * table that stores #GdkColors.
218 	 *
219 	 * Deprecated: Use #GdkRGBA
220 	 *
221 	 * Return: The hash function applied to @color
222 	 */
223 	public uint hash()
224 	{
225 		return gdk_color_hash(gdkColor);
226 	}
227 
228 	/**
229 	 * Returns a textual specification of @color in the hexadecimal
230 	 * form “\#rrrrggggbbbb” where “r”, “g” and “b” are hex digits
231 	 * representing the red, green and blue components respectively.
232 	 *
233 	 * The returned string can be parsed by gdk_color_parse().
234 	 *
235 	 * Deprecated: Use #GdkRGBA
236 	 *
237 	 * Return: a newly-allocated text string
238 	 *
239 	 * Since: 2.12
240 	 */
241 	public override string toString()
242 	{
243 		return Str.toString(gdk_color_to_string(gdkColor));
244 	}
245 
246 	/**
247 	 * Parses a textual specification of a color and fill in the
248 	 * @red, @green, and @blue fields of a #GdkColor.
249 	 *
250 	 * The string can either one of a large set of standard names
251 	 * (taken from the X11 `rgb.txt` file), or it can be a hexadecimal
252 	 * value in the form “\#rgb” “\#rrggbb”, “\#rrrgggbbb” or
253 	 * “\#rrrrggggbbbb” where “r”, “g” and “b” are hex digits of
254 	 * the red, green, and blue components of the color, respectively.
255 	 * (White in the four forms is “\#fff”, “\#ffffff”, “\#fffffffff”
256 	 * and “\#ffffffffffff”).
257 	 *
258 	 * Deprecated: Use #GdkRGBA
259 	 *
260 	 * Params:
261 	 *     spec = the string specifying the color
262 	 *     color = the #GdkColor to fill in
263 	 *
264 	 * Return: %TRUE if the parsing succeeded
265 	 */
266 	public static bool parse(string spec, out Color color)
267 	{
268 		GdkColor* outcolor = gMalloc!GdkColor();
269 		
270 		auto p = gdk_color_parse(Str.toStringz(spec), outcolor) != 0;
271 		
272 		color = ObjectG.getDObject!(Color)(outcolor);
273 		
274 		return p;
275 	}
276 }