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 
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 	int[string] connectedSignals;
206 
207 	void delegate(HSV)[] onChangedListeners;
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 	void addOnMove(void delegate(GtkDirectionType, HSV) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
233 	{
234 		if ( "move" !in connectedSignals )
235 		{
236 			Signals.connectData(
237 				this,
238 				"move",
239 				cast(GCallback)&callBackMove,
240 				cast(void*)this,
241 				null,
242 				connectFlags);
243 			connectedSignals["move"] = 1;
244 		}
245 		onMoveListeners ~= dlg;
246 	}
247 	extern(C) static void callBackMove(GtkHSV* hsvStruct, GtkDirectionType object, HSV _hsv)
248 	{
249 		foreach ( void delegate(GtkDirectionType, HSV) dlg; _hsv.onMoveListeners )
250 		{
251 			dlg(object, _hsv);
252 		}
253 	}
254 
255 	/**
256 	 * Converts a color from RGB space to HSV.
257 	 *
258 	 * Input values must be in the [0.0, 1.0] range;
259 	 * output values will be in the same range.
260 	 *
261 	 * Params:
262 	 *     r = Red
263 	 *     g = Green
264 	 *     b = Blue
265 	 *     h = Return value for the hue component
266 	 *     s = Return value for the saturation component
267 	 *     v = Return value for the value component
268 	 *
269 	 * Since: 2.14
270 	 */
271 	public static void rgbToHsv(double r, double g, double b, out double h, out double s, out double v)
272 	{
273 		gtk_rgb_to_hsv(r, g, b, &h, &s, &v);
274 	}
275 }