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 gdk.RGBA; 26 27 private import gdk.c.functions; 28 public import gdk.c.types; 29 private import glib.MemorySlice; 30 private import glib.Str; 31 private import glib.c.functions; 32 private import gobject.ObjectG; 33 private import gtkd.Loader; 34 35 36 /** 37 * A `GdkRGBA` is used to represent a color, in a way that is compatible 38 * with cairo’s notion of color. 39 * 40 * `GdkRGBA` is a convenient way to pass colors around. It’s based on 41 * cairo’s way to deal with colors and mirrors its behavior. All values 42 * are in the range from 0.0 to 1.0 inclusive. So the color 43 * (0.0, 0.0, 0.0, 0.0) represents transparent black and 44 * (1.0, 1.0, 1.0, 1.0) is opaque white. Other values will 45 * be clamped to this range when drawing. 46 */ 47 public final class RGBA 48 { 49 /** the main Gtk struct */ 50 protected GdkRGBA* gdkRGBA; 51 protected bool ownedRef; 52 53 /** Get the main Gtk struct */ 54 public GdkRGBA* getRGBAStruct(bool transferOwnership = false) 55 { 56 if (transferOwnership) 57 ownedRef = false; 58 return gdkRGBA; 59 } 60 61 /** the main Gtk struct as a void* */ 62 protected void* getStruct() 63 { 64 return cast(void*)gdkRGBA; 65 } 66 67 /** 68 * Sets our main struct and passes it to the parent class. 69 */ 70 public this (GdkRGBA* gdkRGBA, bool ownedRef = false) 71 { 72 this.gdkRGBA = gdkRGBA; 73 this.ownedRef = ownedRef; 74 } 75 76 ~this () 77 { 78 if ( Linker.isLoaded(LIBRARY_GDK) && ownedRef ) 79 gdk_rgba_free(gdkRGBA); 80 } 81 82 /** 83 * Creates a new RGBA Color 84 */ 85 this() 86 { 87 GdkRGBA rgba = GdkRGBA(0, 0, 0, 0); 88 89 this(gdk_rgba_copy(&rgba), true); 90 } 91 92 /** ditto */ 93 this(double red, double green, double blue, double alpha = 1.0) 94 { 95 GdkRGBA rgba; 96 97 rgba.red = red; 98 rgba.green = green; 99 rgba.blue = blue; 100 rgba.alpha = alpha; 101 102 this(gdk_rgba_copy(&rgba), true); 103 } 104 105 106 /** 107 */ 108 109 /** 110 * The intensity of the red channel from 0.0 to 1.0 inclusive 111 */ 112 public @property float red() 113 { 114 return gdkRGBA.red; 115 } 116 117 /** Ditto */ 118 public @property void red(float value) 119 { 120 gdkRGBA.red = value; 121 } 122 123 /** 124 * The intensity of the green channel from 0.0 to 1.0 inclusive 125 */ 126 public @property float green() 127 { 128 return gdkRGBA.green; 129 } 130 131 /** Ditto */ 132 public @property void green(float value) 133 { 134 gdkRGBA.green = value; 135 } 136 137 /** 138 * The intensity of the blue channel from 0.0 to 1.0 inclusive 139 */ 140 public @property float blue() 141 { 142 return gdkRGBA.blue; 143 } 144 145 /** Ditto */ 146 public @property void blue(float value) 147 { 148 gdkRGBA.blue = value; 149 } 150 151 /** 152 * The opacity of the color from 0.0 for completely translucent to 153 * 1.0 for opaque 154 */ 155 public @property float alpha() 156 { 157 return gdkRGBA.alpha; 158 } 159 160 /** Ditto */ 161 public @property void alpha(float value) 162 { 163 gdkRGBA.alpha = value; 164 } 165 166 /** */ 167 public static GType getType() 168 { 169 return gdk_rgba_get_type(); 170 } 171 172 /** 173 * Makes a copy of a `GdkRGBA`. 174 * 175 * The result must be freed through [method@Gdk.RGBA.free]. 176 * 177 * Returns: A newly allocated `GdkRGBA`, with the same contents as @rgba 178 */ 179 public RGBA copy() 180 { 181 auto __p = gdk_rgba_copy(gdkRGBA); 182 183 if(__p is null) 184 { 185 return null; 186 } 187 188 return ObjectG.getDObject!(RGBA)(cast(GdkRGBA*) __p, true); 189 } 190 191 /** 192 * Compares two `GdkRGBA` colors. 193 * 194 * Params: 195 * p2 = another `GdkRGBA` 196 * 197 * Returns: %TRUE if the two colors compare equal 198 */ 199 public bool equal(RGBA p2) 200 { 201 return gdk_rgba_equal(gdkRGBA, (p2 is null) ? null : p2.getRGBAStruct()) != 0; 202 } 203 204 /** 205 * Frees a `GdkRGBA`. 206 */ 207 public void free() 208 { 209 gdk_rgba_free(gdkRGBA); 210 ownedRef = false; 211 } 212 213 /** 214 * A hash function suitable for using for a hash 215 * table that stores `GdkRGBA`s. 216 * 217 * Returns: The hash value for @p 218 */ 219 public uint hash() 220 { 221 return gdk_rgba_hash(gdkRGBA); 222 } 223 224 /** 225 * Checks if an @rgba value is transparent. 226 * 227 * That is, drawing with the value would not produce any change. 228 * 229 * Returns: %TRUE if the @rgba is clear 230 */ 231 public bool isClear() 232 { 233 return gdk_rgba_is_clear(gdkRGBA) != 0; 234 } 235 236 /** 237 * Checks if an @rgba value is opaque. 238 * 239 * That is, drawing with the value will not retain any results 240 * from previous contents. 241 * 242 * Returns: %TRUE if the @rgba is opaque 243 */ 244 public bool isOpaque() 245 { 246 return gdk_rgba_is_opaque(gdkRGBA) != 0; 247 } 248 249 /** 250 * Parses a textual representation of a color. 251 * 252 * The string can be either one of: 253 * 254 * - A standard name (Taken from the X11 rgb.txt file). 255 * - A hexadecimal value in the form “\#rgb”, “\#rrggbb”, 256 * “\#rrrgggbbb” or ”\#rrrrggggbbbb” 257 * - A hexadecimal value in the form “\#rgba”, “\#rrggbbaa”, 258 * or ”\#rrrrggggbbbbaaaa” 259 * - A RGB color in the form “rgb(r,g,b)” (In this case the color 260 * will have full opacity) 261 * - A RGBA color in the form “rgba(r,g,b,a)” 262 * 263 * Where “r”, “g”, “b” and “a” are respectively the red, green, 264 * blue and alpha color values. In the last two cases, “r”, “g”, 265 * and “b” are either integers in the range 0 to 255 or percentage 266 * values in the range 0% to 100%, and a is a floating point value 267 * in the range 0 to 1. 268 * 269 * Params: 270 * spec = the string specifying the color 271 * 272 * Returns: %TRUE if the parsing succeeded 273 */ 274 public bool parse(string spec) 275 { 276 return gdk_rgba_parse(gdkRGBA, Str.toStringz(spec)) != 0; 277 } 278 279 /** 280 * Returns a textual specification of @rgba in the form 281 * `rgb(r,g,b)` or `rgba(r,g,b,a)`, where “r”, “g”, “b” and 282 * “a” represent the red, green, blue and alpha values 283 * respectively. “r”, “g”, and “b” are represented as integers 284 * in the range 0 to 255, and “a” is represented as a floating 285 * point value in the range 0 to 1. 286 * 287 * These string forms are string forms that are supported by 288 * the CSS3 colors module, and can be parsed by [method@Gdk.RGBA.parse]. 289 * 290 * Note that this string representation may lose some precision, 291 * since “r”, “g” and “b” are represented as 8-bit integers. If 292 * this is a concern, you should use a different representation. 293 * 294 * Returns: A newly allocated text string 295 */ 296 public override string toString() 297 { 298 auto retStr = gdk_rgba_to_string(gdkRGBA); 299 300 scope(exit) Str.freeString(retStr); 301 return Str.toString(retStr); 302 } 303 }