Mercurial > projects > dwt-mac
comparison dwt/graphics/Color.d @ 29:d408fc12b991
Ported dwt.graphics.Color and RGB
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Wed, 10 Sep 2008 23:18:26 +0200 |
parents | a9ab4c738ed8 |
children | 5123b17c98ef |
comparison
equal
deleted
inserted
replaced
28:71b49a659702 | 29:d408fc12b991 |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.graphics.Color; | 14 module dwt.graphics.Color; |
12 | 15 |
13 import dwt.dwthelper.utils; | |
14 | |
15 | 16 |
16 import dwt.DWT; | 17 import dwt.DWT; |
17 import dwt.DWTException; | 18 import dwt.DWTException; |
19 | |
20 import dwt.dwthelper.utils; | |
21 import dwt.graphics.Device; | |
22 import dwt.graphics.Resource; | |
23 import dwt.graphics.RGB; | |
18 | 24 |
19 /** | 25 /** |
20 * Instances of this class manage the operating system resources that | 26 * Instances of this class manage the operating system resources that |
21 * implement DWT's RGB color model. To create a color you can either | 27 * implement DWT's RGB color model. To create a color you can either |
22 * specify the individual color components as integers in the range | 28 * specify the individual color components as integers in the range |
130 cast(int)(handle[0] * 255) is cast(int)(rgbColor[0] * 255) && | 136 cast(int)(handle[0] * 255) is cast(int)(rgbColor[0] * 255) && |
131 cast(int)(handle[1] * 255) is cast(int)(rgbColor[1] * 255) && | 137 cast(int)(handle[1] * 255) is cast(int)(rgbColor[1] * 255) && |
132 cast(int)(handle[2] * 255) is cast(int)(rgbColor[2] * 255); | 138 cast(int)(handle[2] * 255) is cast(int)(rgbColor[2] * 255); |
133 } | 139 } |
134 | 140 |
141 alias equals opEquals; | |
142 | |
135 /** | 143 /** |
136 * Returns the amount of blue in the color, from 0 to 255. | 144 * Returns the amount of blue in the color, from 0 to 255. |
137 * | 145 * |
138 * @return the blue component of the color | 146 * @return the blue component of the color |
139 * | 147 * |
182 * | 190 * |
183 * @return the receiver's hash | 191 * @return the receiver's hash |
184 * | 192 * |
185 * @see #equals | 193 * @see #equals |
186 */ | 194 */ |
187 public int hashCode() { | 195 public hash_t toHash() { |
188 if (isDisposed()) return 0; | 196 if (isDisposed()) return 0; |
189 return cast(int)(handle[0] * 255) ^ cast(int)(handle[1] * 255) ^ cast(int)(handle[2] * 255); | 197 return cast(int)(handle[0] * 255) ^ cast(int)(handle[1] * 255) ^ cast(int)(handle[2] * 255); |
190 } | 198 } |
199 | |
200 alias toHash hashCode; | |
191 | 201 |
192 /** | 202 /** |
193 * Returns an <code>RGB</code> representing the receiver. | 203 * Returns an <code>RGB</code> representing the receiver. |
194 * | 204 * |
195 * @return the RGB for the color | 205 * @return the RGB for the color |
258 * | 268 * |
259 * @return a string representation of the receiver | 269 * @return a string representation of the receiver |
260 */ | 270 */ |
261 public String toString () { | 271 public String toString () { |
262 if (isDisposed()) return "Color {*DISPOSED*}"; | 272 if (isDisposed()) return "Color {*DISPOSED*}"; |
263 return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}"; | 273 return "Color {" ~ getRed() ~ ", " ~ getGreen() ~ ", " ~ getBlue() + "}"; |
264 } | 274 } |
265 | 275 |
266 } | 276 } |