# HG changeset patch # User Jacob Carlborg # Date 1221081506 -7200 # Node ID d408fc12b991fc4edf62406a3d2c4cd35dcae05a # Parent 71b49a65970214c2222b05d81894c6cc39554e40 Ported dwt.graphics.Color and RGB diff -r 71b49a659702 -r d408fc12b991 dwt/graphics/Color.d --- a/dwt/graphics/Color.d Mon Sep 08 22:42:00 2008 +0200 +++ b/dwt/graphics/Color.d Wed Sep 10 23:18:26 2008 +0200 @@ -7,15 +7,21 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg *******************************************************************************/ module dwt.graphics.Color; -import dwt.dwthelper.utils; - import dwt.DWT; import dwt.DWTException; +import dwt.dwthelper.utils; +import dwt.graphics.Device; +import dwt.graphics.Resource; +import dwt.graphics.RGB; + /** * Instances of this class manage the operating system resources that * implement DWT's RGB color model. To create a color you can either @@ -132,6 +138,8 @@ cast(int)(handle[2] * 255) is cast(int)(rgbColor[2] * 255); } +alias equals opEquals; + /** * Returns the amount of blue in the color, from 0 to 255. * @@ -184,11 +192,13 @@ * * @see #equals */ -public int hashCode() { +public hash_t toHash() { if (isDisposed()) return 0; return cast(int)(handle[0] * 255) ^ cast(int)(handle[1] * 255) ^ cast(int)(handle[2] * 255); } +alias toHash hashCode; + /** * Returns an RGB representing the receiver. * @@ -260,7 +270,7 @@ */ public String toString () { if (isDisposed()) return "Color {*DISPOSED*}"; - return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}"; + return "Color {" ~ getRed() ~ ", " ~ getGreen() ~ ", " ~ getBlue() + "}"; } } diff -r 71b49a659702 -r d408fc12b991 dwt/graphics/RGB.d --- a/dwt/graphics/RGB.d Mon Sep 08 22:42:00 2008 +0200 +++ b/dwt/graphics/RGB.d Wed Sep 10 23:18:26 2008 +0200 @@ -7,14 +7,18 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg *******************************************************************************/ module dwt.graphics.RGB; -import dwt.dwthelper.utils; import dwt.DWT; import dwt.internal.SerializableCompatibility; +import dwt.dwthelper.utils; + /** * Instances of this class are descriptions of colors in * terms of the primary additive color model (red, green and @@ -55,7 +59,7 @@ */ public int blue; - static final long serialVersionUID = 3258415023461249074L; + static const long serialVersionUID = 3258415023461249074L; /** * Constructs an instance of this class with the given @@ -179,7 +183,7 @@ hue *= 60; if (hue < 0) hue += 360; } - return new float[] {hue, saturation, brightness}; + return new float[] [hue, saturation, brightness]; } /** @@ -192,13 +196,15 @@ * * @see #hashCode() */ -public bool equals(Object object) { +public bool opEquals(Object object) { if (object is this) return true; if (!( null !is cast(RGB)object )) return false; RGB rgb = cast(RGB)object; return (rgb.red is this.red) && (rgb.green is this.green) && (rgb.blue is this.blue); } +alias opEquals equals; + /** * Returns an integer hash code for the receiver. Any two * objects that return true when passed to @@ -209,10 +215,12 @@ * * @see #equals(Object) */ -public int hashCode() { +public hash_t toHash() { return (blue << 16) | (green << 8) | red; } +alias toHash hashCode; + /** * Returns a string containing a concise, human-readable * description of the receiver. @@ -220,7 +228,7 @@ * @return a string representation of the RGB */ public String toString() { - return "RGB {" + red + ", " + green + ", " + blue + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + return "RGB {" ~ red ~ ", " ~ green ~ ", " ~ blue ~ "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } }