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