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