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 = gdk-Colormaps-and-Colors.html 27 * outPack = gdk 28 * outFile = Colormap 29 * strct = GdkColormap 30 * realStrct= 31 * ctorStrct= 32 * clss = Colormap 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gdk_colormap_ 41 * - gdk_ 42 * omit structs: 43 * omit prefixes: 44 * - gdk_color_ 45 * omit code: 46 * omit signals: 47 * imports: 48 * - gdk.Visual 49 * - gdk.Color 50 * - gdk.Screen 51 * structWrap: 52 * - GdkColor* -> Color 53 * - GdkColormap* -> Colormap 54 * - GdkScreen* -> Screen 55 * - GdkVisual* -> Visual 56 * module aliases: 57 * local aliases: 58 * overrides: 59 */ 60 61 module gdk.Colormap; 62 63 public import gtkc.gdktypes; 64 65 private import gtkc.gdk; 66 private import glib.ConstructionException; 67 private import gobject.ObjectG; 68 69 70 private import gdk.Visual; 71 private import gdk.Color; 72 private import gdk.Screen; 73 74 75 76 77 /** 78 * Description 79 * These functions are used to modify colormaps. 80 * A colormap is an object that contains the mapping 81 * between the color values stored in memory and 82 * the RGB values that are used to display color 83 * values. In general, colormaps only contain 84 * significant information for pseudo-color visuals, 85 * but even for other visual types, a colormap object 86 * is required in some circumstances. 87 * There are a couple of special colormaps that can 88 * be retrieved. The system colormap (retrieved 89 * with gdk_colormap_get_system()) is the default 90 * colormap of the system. If you are using GdkRGB, 91 * there is another colormap that is important - the 92 * colormap in which GdkRGB works, retrieved with 93 * gdk_rgb_get_colormap(). However, when using GdkRGB, 94 * it is not generally necessary to allocate colors 95 * directly. 96 * In previous revisions of this interface, a number 97 * of functions that take a GdkColormap parameter 98 * were replaced with functions whose names began 99 * with "gdk_colormap_". This process will probably 100 * be extended somewhat in the future - 101 * gdk_color_white(), gdk_color_black(), and 102 * gdk_color_change() will probably become aliases. 103 */ 104 public class Colormap 105 { 106 107 /** the main Gtk struct */ 108 protected GdkColormap* gdkColormap; 109 110 111 public GdkColormap* getColormapStruct() 112 { 113 return gdkColormap; 114 } 115 116 117 /** the main Gtk struct as a void* */ 118 protected void* getStruct() 119 { 120 return cast(void*)gdkColormap; 121 } 122 123 /** 124 * Sets our main struct and passes it to the parent class 125 */ 126 public this (GdkColormap* gdkColormap) 127 { 128 this.gdkColormap = gdkColormap; 129 } 130 131 /** 132 */ 133 134 /** 135 * Creates a new colormap for the given visual. 136 * Params: 137 * visual = a GdkVisual. 138 * allocate = if TRUE, the newly created colormap will be 139 * a private colormap, and all colors in it will be 140 * allocated for the applications use. 141 * Throws: ConstructionException GTK+ fails to create the object. 142 */ 143 public this (Visual visual, int allocate) 144 { 145 // GdkColormap * gdk_colormap_new (GdkVisual *visual, gboolean allocate); 146 auto p = gdk_colormap_new((visual is null) ? null : visual.getVisualStruct(), allocate); 147 if(p is null) 148 { 149 throw new ConstructionException("null returned by gdk_colormap_new((visual is null) ? null : visual.getVisualStruct(), allocate)"); 150 } 151 this(cast(GdkColormap*) p); 152 } 153 154 /** 155 * Warning 156 * gdk_colormap_ref has been deprecated since version 2.0 and should not be used in newly-written code. Use g_object_ref() instead. 157 * Deprecated function; use g_object_ref() instead. 158 * Returns: the colormap 159 */ 160 public Colormap doref() 161 { 162 // GdkColormap * gdk_colormap_ref (GdkColormap *cmap); 163 auto p = gdk_colormap_ref(gdkColormap); 164 165 if(p is null) 166 { 167 return null; 168 } 169 170 return ObjectG.getDObject!(Colormap)(cast(GdkColormap*) p); 171 } 172 173 /** 174 * Warning 175 * gdk_colormap_unref has been deprecated since version 2.0 and should not be used in newly-written code. Use g_object_unref() instead. 176 * Deprecated function; use g_object_unref() instead. 177 */ 178 public void unref() 179 { 180 // void gdk_colormap_unref (GdkColormap *cmap); 181 gdk_colormap_unref(gdkColormap); 182 } 183 184 /** 185 * Gets the system's default colormap for the default screen. (See 186 * gdk_colormap_get_system_for_screen()) 187 * Returns: the default colormap. 188 */ 189 public static Colormap getSystem() 190 { 191 // GdkColormap * gdk_colormap_get_system (void); 192 auto p = gdk_colormap_get_system(); 193 194 if(p is null) 195 { 196 return null; 197 } 198 199 return ObjectG.getDObject!(Colormap)(cast(GdkColormap*) p); 200 } 201 202 /** 203 * Warning 204 * gdk_colormap_get_system_size is deprecated and should not be used in newly-written code. 205 * Returns the size of the system's default colormap. 206 * (See the description of struct GdkColormap for an 207 * explanation of the size of a colormap.) 208 * Returns: the size of the system's default colormap. 209 */ 210 public static int getSystemSize() 211 { 212 // gint gdk_colormap_get_system_size (void); 213 return gdk_colormap_get_system_size(); 214 } 215 216 /** 217 * Warning 218 * gdk_colormap_change is deprecated and should not be used in newly-written code. 219 * Changes the value of the first ncolors in a private colormap 220 * to match the values in the colors 221 * array in the colormap. This function is obsolete and 222 * should not be used. See gdk_color_change(). 223 * Params: 224 * ncolors = the number of colors to change. 225 */ 226 public void change(int ncolors) 227 { 228 // void gdk_colormap_change (GdkColormap *colormap, gint ncolors); 229 gdk_colormap_change(gdkColormap, ncolors); 230 } 231 232 /** 233 * Allocates colors from a colormap. 234 * Params: 235 * colors = The color values to allocate. On return, the pixel 236 * values for allocated colors will be filled in. 237 * writeable = If TRUE, the colors are allocated writeable 238 * (their values can later be changed using gdk_color_change()). 239 * Writeable colors cannot be shared between applications. 240 * bestMatch = If TRUE, GDK will attempt to do matching against 241 * existing colors if the colors cannot be allocated as requested. 242 * success = An array of length ncolors. On return, this 243 * indicates whether the corresponding color in colors was 244 * successfully allocated or not. 245 * Returns: The number of colors that were not successfully allocated. 246 */ 247 public int allocColors(GdkColor[] colors, int writeable, int bestMatch, int[] success) 248 { 249 // gint gdk_colormap_alloc_colors (GdkColormap *colormap, GdkColor *colors, gint n_colors, gboolean writeable, gboolean best_match, gboolean *success); 250 return gdk_colormap_alloc_colors(gdkColormap, colors.ptr, cast(int) colors.length, writeable, bestMatch, success.ptr); 251 } 252 253 /** 254 * Allocates a single color from a colormap. 255 * Params: 256 * color = the color to allocate. On return the 257 * pixel field will be 258 * filled in if allocation succeeds. 259 * writeable = If TRUE, the color is allocated writeable 260 * (their values can later be changed using gdk_color_change()). 261 * Writeable colors cannot be shared between applications. 262 * bestMatch = If TRUE, GDK will attempt to do matching against 263 * existing colors if the color cannot be allocated as requested. 264 * Returns: TRUE if the allocation succeeded. 265 */ 266 public int allocColor(out GdkColor color, int writeable, int bestMatch) 267 { 268 // gboolean gdk_colormap_alloc_color (GdkColormap *colormap, GdkColor *color, gboolean writeable, gboolean best_match); 269 return gdk_colormap_alloc_color(gdkColormap, &color, writeable, bestMatch); 270 } 271 272 /** 273 * Frees previously allocated colors. 274 * Params: 275 * colors = the colors to free. 276 */ 277 public void freeColors(GdkColor[] colors) 278 { 279 // void gdk_colormap_free_colors (GdkColormap *colormap, const GdkColor *colors, gint n_colors); 280 gdk_colormap_free_colors(gdkColormap, colors.ptr, cast(int) colors.length); 281 } 282 283 /** 284 * Locates the RGB color in colormap corresponding to the given 285 * hardware pixel pixel. pixel must be a valid pixel in the 286 * colormap; it's a programmer error to call this function with a 287 * pixel which is not in the colormap. Hardware pixels are normally 288 * obtained from gdk_colormap_alloc_colors(), or from a GdkImage. (A 289 * GdkImage contains image data in hardware format, a GdkPixbuf 290 * contains image data in a canonical 24-bit RGB format.) 291 * This function is rarely useful; it's used for example to 292 * implement the eyedropper feature in GtkColorSelection. 293 * Params: 294 * pixel = pixel value in hardware display format 295 * result = GdkColor with red, green, blue fields initialized 296 */ 297 public void queryColor(gulong pixel, out GdkColor result) 298 { 299 // void gdk_colormap_query_color (GdkColormap *colormap, gulong pixel, GdkColor *result); 300 gdk_colormap_query_color(gdkColormap, pixel, &result); 301 } 302 303 /** 304 * Returns the visual for which a given colormap was created. 305 * Returns: the visual of the colormap. 306 */ 307 public Visual getVisual() 308 { 309 // GdkVisual * gdk_colormap_get_visual (GdkColormap *colormap); 310 auto p = gdk_colormap_get_visual(gdkColormap); 311 312 if(p is null) 313 { 314 return null; 315 } 316 317 return ObjectG.getDObject!(Visual)(cast(GdkVisual*) p); 318 } 319 320 /** 321 * Gets the screen for which this colormap was created. 322 * Since 2.2 323 * Returns: the screen for which this colormap was created. 324 */ 325 public Screen getScreen() 326 { 327 // GdkScreen * gdk_colormap_get_screen (GdkColormap *cmap); 328 auto p = gdk_colormap_get_screen(gdkColormap); 329 330 if(p is null) 331 { 332 return null; 333 } 334 335 return ObjectG.getDObject!(Screen)(cast(GdkScreen*) p); 336 } 337 338 /** 339 * Warning 340 * gdk_colors_store is deprecated and should not be used in newly-written code. 341 * Changes the value of the first ncolors colors in 342 * a private colormap. This function is obsolete and 343 * should not be used. See gdk_color_change(). 344 * Params: 345 * colors = the new color values. 346 */ 347 public void colorsStore(GdkColor[] colors) 348 { 349 // void gdk_colors_store (GdkColormap *colormap, GdkColor *colors, gint ncolors); 350 gdk_colors_store(gdkColormap, colors.ptr, cast(int) colors.length); 351 } 352 353 /** 354 * Warning 355 * gdk_colors_alloc is deprecated and should not be used in newly-written code. 356 * Allocates colors from a colormap. This function 357 * is obsolete. See gdk_colormap_alloc_colors(). 358 * For full documentation of the fields, see 359 * the Xlib documentation for XAllocColorCells(). 360 * Params: 361 * contiguous = if TRUE, the colors should be allocated 362 * in contiguous color cells. 363 * planes = an array in which to store the plane masks. 364 * pixels = an array into which to store allocated pixel values. 365 * Returns: TRUE if the allocation was successful 366 */ 367 public int colorsAlloc(int contiguous, gulong[] planes, gulong[] pixels) 368 { 369 // gint gdk_colors_alloc (GdkColormap *colormap, gboolean contiguous, gulong *planes, gint nplanes, gulong *pixels, gint npixels); 370 return gdk_colors_alloc(gdkColormap, contiguous, planes.ptr, cast(int) planes.length, pixels.ptr, cast(int) pixels.length); 371 } 372 373 /** 374 * Warning 375 * gdk_colors_free is deprecated and should not be used in newly-written code. 376 * Frees colors allocated with gdk_colors_alloc(). This 377 * function is obsolete. See gdk_colormap_free_colors(). 378 * Params: 379 * pixels = the pixel values of the colors to free. 380 * planes = the plane masks for all planes to free, OR'd together. 381 */ 382 public void colorsFree(gulong[] pixels, gulong planes) 383 { 384 // void gdk_colors_free (GdkColormap *colormap, gulong *pixels, gint npixels, gulong planes); 385 gdk_colors_free(gdkColormap, pixels.ptr, cast(int) pixels.length, planes); 386 } 387 }