Mercurial > projects > dwt-win
comparison dwt/graphics/Color.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | ab60f3309436 |
children | fd9c62a2998e |
comparison
equal
deleted
inserted
replaced
212:ab60f3309436 | 213:36f5cb12e1a2 |
---|---|
37 * @see RGB | 37 * @see RGB |
38 * @see Device#getSystemColor | 38 * @see Device#getSystemColor |
39 */ | 39 */ |
40 | 40 |
41 public final class Color : Resource { | 41 public final class Color : Resource { |
42 | |
43 alias Resource.init_ init_; | |
42 | 44 |
43 /** | 45 /** |
44 * the handle to the OS color resource | 46 * the handle to the OS color resource |
45 * (Warning: This field is platform dependent) | 47 * (Warning: This field is platform dependent) |
46 * <p> | 48 * <p> |
53 public COLORREF handle; | 55 public COLORREF handle; |
54 | 56 |
55 /** | 57 /** |
56 * Prevents uninitialized instances from being created outside the package. | 58 * Prevents uninitialized instances from being created outside the package. |
57 */ | 59 */ |
58 this() { | 60 this(Device device) { |
61 super(device); | |
59 } | 62 } |
60 | 63 |
61 /** | 64 /** |
62 * Constructs a new instance of this class given a device and the | 65 * Constructs a new instance of this class given a device and the |
63 * desired red, green and blue values expressed as ints in the range | 66 * desired red, green and blue values expressed as ints in the range |
81 * </ul> | 84 * </ul> |
82 * | 85 * |
83 * @see #dispose | 86 * @see #dispose |
84 */ | 87 */ |
85 public this (Device device, int red, int green, int blue) { | 88 public this (Device device, int red, int green, int blue) { |
86 if (device is null) device = Device.getDevice(); | 89 super(device); |
87 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 90 init_(red, green, blue); |
88 init_(device, red, green, blue); | 91 init_(); |
89 if (device.tracking) device.new_Object(this); | |
90 } | 92 } |
91 | 93 |
92 /** | 94 /** |
93 * Constructs a new instance of this class given a device and an | 95 * Constructs a new instance of this class given a device and an |
94 * <code>RGB</code> describing the desired red, green and blue values. | 96 * <code>RGB</code> describing the desired red, green and blue values. |
110 * </ul> | 112 * </ul> |
111 * | 113 * |
112 * @see #dispose | 114 * @see #dispose |
113 */ | 115 */ |
114 public this (Device device, RGB rgb) { | 116 public this (Device device, RGB rgb) { |
115 if (device is null) device = Device.getDevice(); | 117 super(device); |
116 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
117 if (rgb is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 118 if (rgb is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
118 init_(device, rgb.red, rgb.green, rgb.blue); | 119 init_(rgb.red, rgb.green, rgb.blue); |
119 if (device.tracking) device.new_Object(this); | 120 init_(); |
120 } | 121 } |
121 | 122 |
122 /** | 123 void destroy() { |
123 * Disposes of the operating system resources associated with | |
124 * the color. Applications must dispose of all colors which | |
125 * they allocate. | |
126 */ | |
127 override public void dispose() { | |
128 if (handle is -1) return; | |
129 if (device.isDisposed()) return; | |
130 | |
131 /* | 124 /* |
132 * If this is a palette-based device, | 125 * If this is a palette-based device, |
133 * Decrease the reference count for this color. | 126 * Decrease the reference count for this color. |
134 * If the reference count reaches 0, the slot may | 127 * If the reference count reaches 0, the slot may |
135 * be reused when another color is allocated. | 128 * be reused when another color is allocated. |
141 if (colorRefCount[index] > 0) { | 134 if (colorRefCount[index] > 0) { |
142 colorRefCount[index]--; | 135 colorRefCount[index]--; |
143 } | 136 } |
144 } | 137 } |
145 handle = -1; | 138 handle = -1; |
146 if (device.tracking) device.dispose_Object(this); | |
147 device = null; | |
148 } | 139 } |
149 | 140 |
150 /** | 141 /** |
151 * Compares the argument to the receiver, and returns true | 142 * Compares the argument to the receiver, and returns true |
152 * if they represent the <em>same</em> object using a class | 143 * if they represent the <em>same</em> object using a class |
247 * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li> | 238 * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li> |
248 * </ul> | 239 * </ul> |
249 * | 240 * |
250 * @see #dispose | 241 * @see #dispose |
251 */ | 242 */ |
252 void init_(Device device, int red, int green, int blue) { | 243 void init_(int red, int green, int blue) { |
253 if (red > 255 || red < 0 || green > 255 || green < 0 || blue > 255 || blue < 0) { | 244 if (red > 255 || red < 0 || green > 255 || green < 0 || blue > 255 || blue < 0) { |
254 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 245 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
255 } | 246 } |
256 this.device = device; | |
257 handle = (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16); | 247 handle = (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16); |
258 | 248 |
259 /* If this is not a palette-based device, return */ | 249 /* If this is not a palette-based device, return */ |
260 auto hPal = device.hPalette; | 250 auto hPal = device.hPalette; |
261 if (hPal is null) return; | 251 if (hPal is null) return; |
336 * @param device the device on which to allocate the color | 326 * @param device the device on which to allocate the color |
337 * @param handle the handle for the color | 327 * @param handle the handle for the color |
338 * @return a new color object containing the specified device and handle | 328 * @return a new color object containing the specified device and handle |
339 */ | 329 */ |
340 public static Color win32_new(Device device, int handle) { | 330 public static Color win32_new(Device device, int handle) { |
341 if (device is null) device = Device.getDevice(); | 331 Color color = new Color(device); |
342 Color color = new Color(); | |
343 color.handle = handle; | 332 color.handle = handle; |
344 color.device = device; | |
345 return color; | 333 return color; |
346 } | 334 } |
347 | 335 |
348 } | 336 } |