changeset 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 71b49a659702
children 93b13b15f0b1
files dwt/graphics/Color.d dwt/graphics/RGB.d
diffstat 2 files changed, 28 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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 <jacob.carlborg@gmail.com>
  *******************************************************************************/
 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 <code>RGB</code> 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() + "}";
 }
 
 }
--- 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 <jacob.carlborg@gmail.com>
  *******************************************************************************/
 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 <code>true</code> 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 <code>RGB</code>
  */
 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$
 }
 
 }