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