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