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 * Conversion parameters: 26 * inFile = 27 * outPack = gdk 28 * outFile = Color 29 * strct = GdkColor 30 * realStrct= 31 * ctorStrct= 32 * clss = Color 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gdk_color_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * - gdk.Colormap 48 * structWrap: 49 * - GdkColor* -> Color 50 * - GdkColormap* -> Colormap 51 * module aliases: 52 * local aliases: 53 * overrides: 54 * - toString 55 */ 56 57 module gdk.Color; 58 59 public import gtkc.gdktypes; 60 61 private import gtkc.gdk; 62 private import glib.ConstructionException; 63 private import gobject.ObjectG; 64 65 66 private import glib.Str; 67 private import gdk.Colormap; 68 69 70 71 72 /** 73 * Description 74 * These functions are used to modify colormaps. 75 * A colormap is an object that contains the mapping 76 * between the color values stored in memory and 77 * the RGB values that are used to display color 78 * values. In general, colormaps only contain 79 * significant information for pseudo-color visuals, 80 * but even for other visual types, a colormap object 81 * is required in some circumstances. 82 * There are a couple of special colormaps that can 83 * be retrieved. The system colormap (retrieved 84 * with gdk_colormap_get_system()) is the default 85 * colormap of the system. If you are using GdkRGB, 86 * there is another colormap that is important - the 87 * colormap in which GdkRGB works, retrieved with 88 * gdk_rgb_get_colormap(). However, when using GdkRGB, 89 * it is not generally necessary to allocate colors 90 * directly. 91 * In previous revisions of this interface, a number 92 * of functions that take a GdkColormap parameter 93 * were replaced with functions whose names began 94 * with "gdk_colormap_". This process will probably 95 * be extended somewhat in the future - 96 * gdk_color_white(), gdk_color_black(), and 97 * gdk_color_change() will probably become aliases. 98 */ 99 public class Color 100 { 101 102 /** the main Gtk struct */ 103 protected GdkColor* gdkColor; 104 105 106 public GdkColor* getColorStruct() 107 { 108 return gdkColor; 109 } 110 111 112 /** the main Gtk struct as a void* */ 113 protected void* getStruct() 114 { 115 return cast(void*)gdkColor; 116 } 117 118 /** 119 * Sets our main struct and passes it to the parent class 120 */ 121 public this (GdkColor* gdkColor) 122 { 123 this.gdkColor = gdkColor; 124 } 125 126 static Color _black; 127 static Color _white; 128 129 /** 130 * Creates a new Color 131 */ 132 this() 133 { 134 this(new GdkColor); 135 } 136 137 /** */ 138 this(ubyte red, ubyte green, ubyte blue) 139 { 140 this(); 141 set8(red, green, blue); 142 } 143 144 /** 145 * Creates a new Color with RGB values 146 * Params: 147 * red = 148 * green = 149 * blue = 150 */ 151 this(guint16 red, guint16 green, guint16 blue) 152 { 153 this(); 154 //printf("Color.this red , green , blue = %d %d %d\n", red, green, blue); 155 set(red,green,blue); 156 } 157 158 /** */ 159 this(uint rgb) 160 { 161 this(); 162 //printf("Color.this uint %X\n",rgb); 163 set( cast(ushort)((rgb&0xFFFF)),cast(ushort)((rgb&0xFFFF00000000)>>32),cast(ushort)((rgb&0xFFFF0000)>>16)); 164 } 165 166 /** */ 167 this(int rgb) 168 { 169 this(); 170 //printf("Color.this int %X\n",rgb); 171 set8( cast(ubyte)((rgb&0xFF0000)>>16),cast(ubyte)((rgb&0x00FF00)>>8),cast(ubyte)(rgb&0xFF)); 172 } 173 174 /** */ 175 static Color black() 176 { 177 if ( !_black ) 178 { 179 _black = new Color(cast(ubyte)0,cast(ubyte)0,cast(ubyte)0); 180 } 181 return _black; 182 } 183 184 /** */ 185 static Color white() 186 { 187 if ( !_white ) 188 { 189 _white = new Color(cast(ubyte)255,cast(ubyte)255,cast(ubyte)255); 190 } 191 return _white; 192 } 193 194 /** 195 * Sets the Color with RGB values 196 * Params: 197 * red = 198 * green = 199 * blue = 200 */ 201 void set(guint16 red, guint16 green, guint16 blue) 202 { 203 //printf("Color.set %X %X %X\n",red,green,blue); 204 gdkColor.red = red; 205 gdkColor.green = green; 206 gdkColor.blue = blue; 207 gdkColor.pixel = (red&0xFF00 << 8) | (green&0xFF00) | (blue >> 8) ; 208 //printf("Color.pixel %X \n",gdkColor.pixel); 209 //allocColor(); 210 //printf("set pixel = %X\n", gdkColor.pixel); 211 } 212 213 /** */ 214 void set8(ubyte red, ubyte green, ubyte blue) 215 { 216 //printf("Color.set %X %X %X\n",red,green,blue); 217 218 gdkColor.red = cast(ushort)(red * 257); 219 gdkColor.green = cast(ushort)(green * 257); 220 gdkColor.blue = cast(ushort)(blue * 257); 221 gdkColor.pixel = (red << 16) | (green << 8 ) | blue; 222 //printf("set8 pixel = %X\n", gdkColor.pixel); 223 } 224 225 /** */ 226 ulong getValue() 227 { 228 return (cast(ulong)gdkColor.red <<32) | (cast(ulong)gdkColor.green << 16) | (cast(ulong)gdkColor.blue); 229 } 230 231 /** */ 232 int getValue24() 233 { 234 return ((gdkColor.red&0xFF00)<<8 ) | ((gdkColor.green&0xFF00)) | ((gdkColor.blue&0xFF00) >>8); 235 } 236 237 /** */ 238 uint getPixelValue() 239 { 240 return gdkColor.pixel; 241 } 242 243 244 /** 245 */ 246 247 /** 248 * Makes a copy of a color structure. The result 249 * must be freed using gdk_color_free(). 250 * Returns: a copy of color. 251 */ 252 public Color copy() 253 { 254 // GdkColor * gdk_color_copy (const GdkColor *color); 255 auto p = gdk_color_copy(gdkColor); 256 257 if(p is null) 258 { 259 return null; 260 } 261 262 return ObjectG.getDObject!(Color)(cast(GdkColor*) p); 263 } 264 265 /** 266 * Frees a color structure created with 267 * gdk_color_copy(). 268 */ 269 public void free() 270 { 271 // void gdk_color_free (GdkColor *color); 272 gdk_color_free(gdkColor); 273 } 274 275 /** 276 * Warning 277 * gdk_color_white is deprecated and should not be used in newly-written code. 278 * Returns the white color for a given colormap. The resulting 279 * value has already allocated been allocated. 280 * Params: 281 * colormap = a GdkColormap. 282 * color = the location to store the color. 283 * Returns: TRUE if the allocation succeeded. 284 */ 285 public static int white(Colormap colormap, out GdkColor color) 286 { 287 // gint gdk_color_white (GdkColormap *colormap, GdkColor *color); 288 return gdk_color_white((colormap is null) ? null : colormap.getColormapStruct(), &color); 289 } 290 291 /** 292 * Warning 293 * gdk_color_black is deprecated and should not be used in newly-written code. 294 * Returns the black color for a given colormap. The resulting 295 * value has already been allocated. 296 * Params: 297 * colormap = a GdkColormap. 298 * color = the location to store the color. 299 * Returns: TRUE if the allocation succeeded. 300 */ 301 public static int black(Colormap colormap, out GdkColor color) 302 { 303 // gint gdk_color_black (GdkColormap *colormap, GdkColor *color); 304 return gdk_color_black((colormap is null) ? null : colormap.getColormapStruct(), &color); 305 } 306 307 /** 308 * Parses a textual specification of a color and fill in the 309 * red, green, 310 * and blue fields of a GdkColor 311 * structure. The color is not allocated, you 312 * must call gdk_colormap_alloc_color() yourself. The string can 313 * either one of a large set of standard names. (Taken from the X11 314 * rgb.txt file), or it can be a hex value in the 315 * form '#rgb' '#rrggbb' '#rrrgggbbb' or 316 * '#rrrrggggbbbb' where 'r', 'g' and 'b' are hex digits of the 317 * red, green, and blue components of the color, respectively. (White 318 * in the four forms is '#fff' '#ffffff' '#fffffffff' and 319 * '#ffffffffffff') 320 * Params: 321 * spec = the string specifying the color. 322 * color = the GdkColor to fill in. [out] 323 * Returns: TRUE if the parsing succeeded. 324 */ 325 public static int parse(string spec, out GdkColor color) 326 { 327 // gboolean gdk_color_parse (const gchar *spec, GdkColor *color); 328 return gdk_color_parse(Str.toStringz(spec), &color); 329 } 330 331 /** 332 * Warning 333 * gdk_color_alloc has been deprecated since version 2.2 and should not be used in newly-written code. Use gdk_colormap_alloc_color() instead. 334 * Allocates a single color from a colormap. 335 * Params: 336 * colormap = a GdkColormap. 337 * color = The color to allocate. On return, the 338 * pixel field will be filled in. 339 * Returns: TRUE if the allocation succeeded. 340 */ 341 public static int alloc(Colormap colormap, out GdkColor color) 342 { 343 // gint gdk_color_alloc (GdkColormap *colormap, GdkColor *color); 344 return gdk_color_alloc((colormap is null) ? null : colormap.getColormapStruct(), &color); 345 } 346 347 /** 348 * Warning 349 * gdk_color_change is deprecated and should not be used in newly-written code. 350 * Changes the value of a color that has already 351 * been allocated. If colormap is not a private 352 * colormap, then the color must have been allocated 353 * using gdk_colormap_alloc_colors() with the 354 * writeable set to TRUE. 355 * Params: 356 * colormap = a GdkColormap. 357 * color = a GdkColor, with the color to change 358 * in the pixel field, 359 * and the new value in the remaining fields. 360 * Returns: TRUE if the color was successfully changed. 361 */ 362 public static int change(Colormap colormap, Color color) 363 { 364 // gint gdk_color_change (GdkColormap *colormap, GdkColor *color); 365 return gdk_color_change((colormap is null) ? null : colormap.getColormapStruct(), (color is null) ? null : color.getColorStruct()); 366 } 367 368 /** 369 * Compares two colors. 370 * Params: 371 * colorb = another GdkColor. 372 * Returns: TRUE if the two colors compare equal 373 */ 374 public int equal(Color colorb) 375 { 376 // gboolean gdk_color_equal (const GdkColor *colora, const GdkColor *colorb); 377 return gdk_color_equal(gdkColor, (colorb is null) ? null : colorb.getColorStruct()); 378 } 379 380 /** 381 * A hash function suitable for using for a hash 382 * table that stores GdkColor's. 383 * Returns: The hash function applied to colora 384 */ 385 public uint hash() 386 { 387 // guint gdk_color_hash (const GdkColor *colora); 388 return gdk_color_hash(gdkColor); 389 } 390 391 /** 392 * Returns a textual specification of color in the hexadecimal form 393 * #rrrrggggbbbb, where r, 394 * g and b are hex digits 395 * representing the red, green and blue components respectively. 396 * Since 2.12 397 * Returns: a newly-allocated text string 398 */ 399 public override string toString() 400 { 401 // gchar * gdk_color_to_string (const GdkColor *color); 402 return Str.toString(gdk_color_to_string(gdkColor)); 403 } 404 }