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