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 
33 
34 /**
35  * A #GdkColor is used to describe a color,
36  * similar to the XColor struct used in the X11 drawing API.
37  * 
38  * Deprecated: Use #GdkRGBA
39  */
40 public class Color
41 {
42 	/** the main Gtk struct */
43 	protected GdkColor* gdkColor;
44 	protected bool ownedRef;
45 
46 	/** Get the main Gtk struct */
47 	public GdkColor* getColorStruct(bool transferOwnership = false)
48 	{
49 		if (transferOwnership)
50 			ownedRef = false;
51 		return gdkColor;
52 	}
53 
54 	/** the main Gtk struct as a void* */
55 	protected void* getStruct()
56 	{
57 		return cast(void*)gdkColor;
58 	}
59 
60 	/**
61 	 * Sets our main struct and passes it to the parent class.
62 	 */
63 	public this (GdkColor* gdkColor, bool ownedRef = false)
64 	{
65 		this.gdkColor = gdkColor;
66 		this.ownedRef = ownedRef;
67 	}
68 
69 	~this ()
70 	{
71 		if (  Linker.isLoaded(LIBRARY_GDK) && ownedRef )
72 			gdk_color_free(gdkColor);
73 	}
74 
75 	/**
76 	 * Creates a new Color
77 	 */
78 	this()
79 	{
80 		GdkColor color;
81 		
82 		this(gdk_color_copy(&color));
83 	}
84 	
85 	/** ditto */
86 	this(ubyte red, ubyte green, ubyte blue)
87 	{
88 		GdkColor color;
89 		
90 		color.red = cast(ushort)(red * 257);
91 		color.green = cast(ushort)(green * 257);
92 		color.blue = cast(ushort)(blue * 257);
93 		
94 		this(gdk_color_copy(&color));
95 	}
96 	
97 	/** ditto */
98 	this(ushort red, ushort green, ushort blue)
99 	{
100 		GdkColor color;
101 		
102 		color.red = red;
103 		color.green = green;
104 		color.blue = blue;
105 		
106 		this(gdk_color_copy(&color));
107 	}
108 	
109 	/**
110 	 * The color values.
111 	 */
112 	ushort red()
113 	{
114 		return gdkColor.red;
115 	}
116 	
117 	/** ditto */
118 	void red(ushort value)
119 	{
120 		gdkColor.red = value;
121 		updatePixel();
122 	}
123 	
124 	/** ditto */
125 	ushort green()
126 	{
127 		return gdkColor.green;
128 	}
129 	
130 	/** ditto */
131 	void green(ushort value)
132 	{
133 		gdkColor.green = value;
134 		updatePixel();
135 	}
136 	
137 	/** ditto */
138 	ushort blue()
139 	{
140 		return gdkColor.blue;
141 	}
142 	
143 	/** ditto */
144 	void blue(ushort value)
145 	{
146 		gdkColor.blue = value;
147 		updatePixel();
148 	}
149 	
150 	/** ditto */
151 	uint pixel()
152 	{
153 		return gdkColor.pixel;
154 	}
155 	
156 	private void updatePixel()
157 	{
158 		gdkColor.pixel = (gdkColor.red&0xFF00 << 8) | (gdkColor.green&0xFF00) | (gdkColor.blue >> 8) ;
159 	}
160 
161 	/**
162 	 */
163 
164 	/** */
165 	public static GType getType()
166 	{
167 		return gdk_color_get_type();
168 	}
169 
170 	/**
171 	 * Makes a copy of a #GdkColor.
172 	 *
173 	 * The result must be freed using gdk_color_free().
174 	 *
175 	 * Deprecated: Use #GdkRGBA
176 	 *
177 	 * Returns: a copy of @color
178 	 */
179 	public Color copy()
180 	{
181 		auto p = gdk_color_copy(gdkColor);
182 		
183 		if(p is null)
184 		{
185 			return null;
186 		}
187 		
188 		return ObjectG.getDObject!(Color)(cast(GdkColor*) p, true);
189 	}
190 
191 	/**
192 	 * Compares two colors.
193 	 *
194 	 * Deprecated: Use #GdkRGBA
195 	 *
196 	 * Params:
197 	 *     colorb = another #GdkColor
198 	 *
199 	 * Returns: %TRUE if the two colors compare equal
200 	 */
201 	public bool equal(Color colorb)
202 	{
203 		return gdk_color_equal(gdkColor, (colorb is null) ? null : colorb.getColorStruct()) != 0;
204 	}
205 
206 	/**
207 	 * Frees a #GdkColor created with gdk_color_copy().
208 	 *
209 	 * Deprecated: Use #GdkRGBA
210 	 */
211 	public void free()
212 	{
213 		gdk_color_free(gdkColor);
214 		ownedRef = false;
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 }