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() 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 * Returns: 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 * Returns: %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 protected class OnChangedDelegateWrapper 205 { 206 static OnChangedDelegateWrapper[] listeners; 207 void delegate(HSV) dlg; 208 gulong handlerId; 209 210 this(void delegate(HSV) dlg) 211 { 212 this.dlg = dlg; 213 this.listeners ~= this; 214 } 215 216 void remove(OnChangedDelegateWrapper source) 217 { 218 foreach(index, wrapper; listeners) 219 { 220 if (wrapper.handlerId == source.handlerId) 221 { 222 listeners[index] = null; 223 listeners = std.algorithm.remove(listeners, index); 224 break; 225 } 226 } 227 } 228 } 229 230 /** */ 231 gulong addOnChanged(void delegate(HSV) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 232 { 233 auto wrapper = new OnChangedDelegateWrapper(dlg); 234 wrapper.handlerId = Signals.connectData( 235 this, 236 "changed", 237 cast(GCallback)&callBackChanged, 238 cast(void*)wrapper, 239 cast(GClosureNotify)&callBackChangedDestroy, 240 connectFlags); 241 return wrapper.handlerId; 242 } 243 244 extern(C) static void callBackChanged(GtkHSV* hsvStruct, OnChangedDelegateWrapper wrapper) 245 { 246 wrapper.dlg(wrapper.outer); 247 } 248 249 extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure) 250 { 251 wrapper.remove(wrapper); 252 } 253 254 protected class OnMoveDelegateWrapper 255 { 256 static OnMoveDelegateWrapper[] listeners; 257 void delegate(GtkDirectionType, HSV) dlg; 258 gulong handlerId; 259 260 this(void delegate(GtkDirectionType, HSV) dlg) 261 { 262 this.dlg = dlg; 263 this.listeners ~= this; 264 } 265 266 void remove(OnMoveDelegateWrapper source) 267 { 268 foreach(index, wrapper; listeners) 269 { 270 if (wrapper.handlerId == source.handlerId) 271 { 272 listeners[index] = null; 273 listeners = std.algorithm.remove(listeners, index); 274 break; 275 } 276 } 277 } 278 } 279 280 /** */ 281 gulong addOnMove(void delegate(GtkDirectionType, HSV) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 282 { 283 auto wrapper = new OnMoveDelegateWrapper(dlg); 284 wrapper.handlerId = Signals.connectData( 285 this, 286 "move", 287 cast(GCallback)&callBackMove, 288 cast(void*)wrapper, 289 cast(GClosureNotify)&callBackMoveDestroy, 290 connectFlags); 291 return wrapper.handlerId; 292 } 293 294 extern(C) static void callBackMove(GtkHSV* hsvStruct, GtkDirectionType object, OnMoveDelegateWrapper wrapper) 295 { 296 wrapper.dlg(object, wrapper.outer); 297 } 298 299 extern(C) static void callBackMoveDestroy(OnMoveDelegateWrapper wrapper, GClosure* closure) 300 { 301 wrapper.remove(wrapper); 302 } 303 304 /** 305 * Converts a color from RGB space to HSV. 306 * 307 * Input values must be in the [0.0, 1.0] range; 308 * output values will be in the same range. 309 * 310 * Params: 311 * r = Red 312 * g = Green 313 * b = Blue 314 * h = Return value for the hue component 315 * s = Return value for the saturation component 316 * v = Return value for the value component 317 * 318 * Since: 2.14 319 */ 320 public static void rgbToHsv(double r, double g, double b, out double h, out double s, out double v) 321 { 322 gtk_rgb_to_hsv(r, g, b, &h, &s, &v); 323 } 324 }