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