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