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 gtk.HSV;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.Widget;
31 public  import gtkc.gdktypes;
32 private import gtkc.gtk;
33 public  import gtkc.gtktypes;
34 private import std.algorithm;
35 
36 
37 /**
38  * #GtkHSV is the “color wheel” part of a complete color selector widget.
39  * It allows to select a color by determining its HSV components in an
40  * intuitive way. Moving the selection around the outer ring changes the hue,
41  * and moving the selection point inside the inner triangle changes value and
42  * saturation.
43  * 
44  * #GtkHSV has been deprecated together with #GtkColorSelection, where
45  * it was used.
46  */
47 public class HSV : Widget
48 {
49 	/** the main Gtk struct */
50 	protected GtkHSV* gtkHSV;
51 
52 	/** Get the main Gtk struct */
53 	public GtkHSV* getHSVStruct()
54 	{
55 		return gtkHSV;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected override void* getStruct()
60 	{
61 		return cast(void*)gtkHSV;
62 	}
63 
64 	protected override void setStruct(GObject* obj)
65 	{
66 		gtkHSV = cast(GtkHSV*)obj;
67 		super.setStruct(obj);
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GtkHSV* gtkHSV, bool ownedRef = false)
74 	{
75 		this.gtkHSV = gtkHSV;
76 		super(cast(GtkWidget*)gtkHSV, ownedRef);
77 	}
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return gtk_hsv_get_type();
84 	}
85 
86 	/**
87 	 * Creates a new HSV color selector.
88 	 *
89 	 * Return: A newly-created HSV color selector.
90 	 *
91 	 * Since: 2.14
92 	 *
93 	 * Throws: ConstructionException GTK+ fails to create the object.
94 	 */
95 	public this()
96 	{
97 		auto p = gtk_hsv_new();
98 		
99 		if(p is null)
100 		{
101 			throw new ConstructionException("null returned by new");
102 		}
103 		
104 		this(cast(GtkHSV*) p);
105 	}
106 
107 	/**
108 	 * Converts a color from HSV space to RGB.
109 	 *
110 	 * Input values must be in the [0.0, 1.0] range;
111 	 * output values will be in the same range.
112 	 *
113 	 * Params:
114 	 *     h = Hue
115 	 *     s = Saturation
116 	 *     v = Value
117 	 *     r = Return value for the red component
118 	 *     g = Return value for the green component
119 	 *     b = Return value for the blue component
120 	 *
121 	 * Since: 2.14
122 	 */
123 	public static void toRgb(double h, double s, double v, out double r, out double g, out double b)
124 	{
125 		gtk_hsv_to_rgb(h, s, v, &r, &g, &b);
126 	}
127 
128 	/**
129 	 * Queries the current color in an HSV color selector.
130 	 * Returned values will be in the [0.0, 1.0] range.
131 	 *
132 	 * Params:
133 	 *     h = Return value for the hue
134 	 *     s = Return value for the saturation
135 	 *     v = Return value for the value
136 	 *
137 	 * Since: 2.14
138 	 */
139 	public void getColor(out double h, out double s, out double v)
140 	{
141 		gtk_hsv_get_color(gtkHSV, &h, &s, &v);
142 	}
143 
144 	/**
145 	 * Queries the size and ring width of an HSV color selector.
146 	 *
147 	 * Params:
148 	 *     size = Return value for the diameter of the hue ring
149 	 *     ringWidth = Return value for the width of the hue ring
150 	 *
151 	 * Since: 2.14
152 	 */
153 	public void getMetrics(out int size, out int ringWidth)
154 	{
155 		gtk_hsv_get_metrics(gtkHSV, &size, &ringWidth);
156 	}
157 
158 	/**
159 	 * An HSV color selector can be said to be adjusting if multiple rapid
160 	 * changes are being made to its value, for example, when the user is
161 	 * adjusting the value with the mouse. This function queries whether
162 	 * the HSV color selector is being adjusted or not.
163 	 *
164 	 * Return: %TRUE if clients can ignore changes to the color value,
165 	 *     since they may be transitory, or %FALSE if they should consider
166 	 *     the color value status to be final.
167 	 *
168 	 * Since: 2.14
169 	 */
170 	public bool isAdjusting()
171 	{
172 		return gtk_hsv_is_adjusting(gtkHSV) != 0;
173 	}
174 
175 	/**
176 	 * Sets the current color in an HSV color selector.
177 	 * Color component values must be in the [0.0, 1.0] range.
178 	 *
179 	 * Params:
180 	 *     h = Hue
181 	 *     s = Saturation
182 	 *     v = Value
183 	 *
184 	 * Since: 2.14
185 	 */
186 	public void setColor(double h, double s, double v)
187 	{
188 		gtk_hsv_set_color(gtkHSV, h, s, v);
189 	}
190 
191 	/**
192 	 * Sets the size and ring width of an HSV color selector.
193 	 *
194 	 * Params:
195 	 *     size = Diameter for the hue ring
196 	 *     ringWidth = Width of the hue ring
197 	 *
198 	 * Since: 2.14
199 	 */
200 	public void setMetrics(int size, int ringWidth)
201 	{
202 		gtk_hsv_set_metrics(gtkHSV, size, ringWidth);
203 	}
204 
205 	protected class OnChangedDelegateWrapper
206 	{
207 		void delegate(HSV) dlg;
208 		gulong handlerId;
209 		ConnectFlags flags;
210 		this(void delegate(HSV) dlg, gulong handlerId, ConnectFlags flags)
211 		{
212 			this.dlg = dlg;
213 			this.handlerId = handlerId;
214 			this.flags = flags;
215 		}
216 	}
217 	protected OnChangedDelegateWrapper[] onChangedListeners;
218 
219 	/** */
220 	gulong addOnChanged(void delegate(HSV) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
221 	{
222 		onChangedListeners ~= new OnChangedDelegateWrapper(dlg, 0, connectFlags);
223 		onChangedListeners[onChangedListeners.length - 1].handlerId = Signals.connectData(
224 			this,
225 			"changed",
226 			cast(GCallback)&callBackChanged,
227 			cast(void*)onChangedListeners[onChangedListeners.length - 1],
228 			cast(GClosureNotify)&callBackChangedDestroy,
229 			connectFlags);
230 		return onChangedListeners[onChangedListeners.length - 1].handlerId;
231 	}
232 	
233 	extern(C) static void callBackChanged(GtkHSV* hsvStruct,OnChangedDelegateWrapper wrapper)
234 	{
235 		wrapper.dlg(wrapper.outer);
236 	}
237 	
238 	extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure)
239 	{
240 		wrapper.outer.internalRemoveOnChanged(wrapper);
241 	}
242 
243 	protected void internalRemoveOnChanged(OnChangedDelegateWrapper source)
244 	{
245 		foreach(index, wrapper; onChangedListeners)
246 		{
247 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
248 			{
249 				onChangedListeners[index] = null;
250 				onChangedListeners = std.algorithm.remove(onChangedListeners, index);
251 				break;
252 			}
253 		}
254 	}
255 	
256 
257 	protected class OnMoveDelegateWrapper
258 	{
259 		void delegate(GtkDirectionType, HSV) dlg;
260 		gulong handlerId;
261 		ConnectFlags flags;
262 		this(void delegate(GtkDirectionType, HSV) dlg, gulong handlerId, ConnectFlags flags)
263 		{
264 			this.dlg = dlg;
265 			this.handlerId = handlerId;
266 			this.flags = flags;
267 		}
268 	}
269 	protected OnMoveDelegateWrapper[] onMoveListeners;
270 
271 	/** */
272 	gulong addOnMove(void delegate(GtkDirectionType, HSV) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
273 	{
274 		onMoveListeners ~= new OnMoveDelegateWrapper(dlg, 0, connectFlags);
275 		onMoveListeners[onMoveListeners.length - 1].handlerId = Signals.connectData(
276 			this,
277 			"move",
278 			cast(GCallback)&callBackMove,
279 			cast(void*)onMoveListeners[onMoveListeners.length - 1],
280 			cast(GClosureNotify)&callBackMoveDestroy,
281 			connectFlags);
282 		return onMoveListeners[onMoveListeners.length - 1].handlerId;
283 	}
284 	
285 	extern(C) static void callBackMove(GtkHSV* hsvStruct, GtkDirectionType object,OnMoveDelegateWrapper wrapper)
286 	{
287 		wrapper.dlg(object, wrapper.outer);
288 	}
289 	
290 	extern(C) static void callBackMoveDestroy(OnMoveDelegateWrapper wrapper, GClosure* closure)
291 	{
292 		wrapper.outer.internalRemoveOnMove(wrapper);
293 	}
294 
295 	protected void internalRemoveOnMove(OnMoveDelegateWrapper source)
296 	{
297 		foreach(index, wrapper; onMoveListeners)
298 		{
299 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
300 			{
301 				onMoveListeners[index] = null;
302 				onMoveListeners = std.algorithm.remove(onMoveListeners, index);
303 				break;
304 			}
305 		}
306 	}
307 	
308 
309 	/**
310 	 * Converts a color from RGB space to HSV.
311 	 *
312 	 * Input values must be in the [0.0, 1.0] range;
313 	 * output values will be in the same range.
314 	 *
315 	 * Params:
316 	 *     r = Red
317 	 *     g = Green
318 	 *     b = Blue
319 	 *     h = Return value for the hue component
320 	 *     s = Return value for the saturation component
321 	 *     v = Return value for the value component
322 	 *
323 	 * Since: 2.14
324 	 */
325 	public static void rgbToHsv(double r, double g, double b, out double h, out double s, out double v)
326 	{
327 		gtk_rgb_to_hsv(r, g, b, &h, &s, &v);
328 	}
329 }