changeset 30:93b13b15f0b1

Ported a couple of modules in dwt.graphics
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Thu, 11 Sep 2008 23:16:53 +0200
parents d408fc12b991
children 9a3047e87f1d
files dwt/graphics/DeviceData.d dwt/graphics/Font.d dwt/graphics/FontData.d dwt/graphics/GCData.d dwt/graphics/Pattern.d dwt/graphics/Rectangle.d dwt/graphics/Resource.d
diffstat 7 files changed, 110 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/graphics/DeviceData.d	Wed Sep 10 23:18:26 2008 +0200
+++ b/dwt/graphics/DeviceData.d	Thu Sep 11 23:16:53 2008 +0200
@@ -7,18 +7,20 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.DeviceData;
 
 import dwt.dwthelper.utils;
 
-
 public class DeviceData {
     /*
     * Debug fields - may not be honoured
     * on some DWT platforms.
     */
-    public bool debug;
+    public bool debugg;
     public bool tracking;
     public Error [] errors;
     public Object [] objects;
--- a/dwt/graphics/Font.d	Wed Sep 10 23:18:26 2008 +0200
+++ b/dwt/graphics/Font.d	Thu Sep 11 23:16:53 2008 +0200
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.Font;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.DWT;
 import dwt.DWTError;
@@ -19,6 +20,15 @@
 import dwt.internal.cocoa.NSFont;
 import dwt.internal.cocoa.NSString;
 
+import tango.stdc.stringz;
+import tango.text.convert.Utf;
+
+import dwt.dwthelper.utils;
+import dwt.graphics.Device;
+import dwt.graphics.FontData;
+import dwt.graphics.Resource;
+import dwt.internal.cocoa.CGFloat;
+
 /**
  * Instances of this class manage operating system resources that
  * define how text looks when it is displayed. Fonts may be constructed
@@ -138,7 +148,7 @@
     init();
 }
 
-/*public*/ Font(Device device, String name, float height, int style) {
+/*public*/ this(Device device, String name, float height, int style) {
     super(device);
     init(name, height, style, null);
     init();
@@ -159,13 +169,15 @@
  *
  * @see #hashCode
  */
-public bool equals(Object object) {
+public bool opEquals(Object object) {
     if (object is this) return true;
     if (!( null !is cast(Font)object )) return false;
     Font font = cast(Font)object;
     return handle is font.handle;
 }
 
+alias opEquals equals;
+
 /**
  * Returns an array of <code>FontData</code>s representing the receiver.
  * On Windows, only one FontData will be returned per font. On X however, 
@@ -181,19 +193,19 @@
 public FontData[] getFontData() {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     NSString family = handle.familyName();
-    char[] buffer1 = new char[family.length()];
+    wchar[] buffer1 = new wchar[family.length()];
     family.getCharacters_(buffer1);
-    String name = new String(buffer1);
+    String name = buffer1.toString().dup;
     NSString str = handle.fontName();
-    char[] buffer = new char[str.length()];
+    wchar[] buffer = new wchar[str.length()];
     str.getCharacters_(buffer);
-    String nsName = new String(buffer);
+    String nsName = buffer.toString().dup;
     int style = DWT.NORMAL;
     if (nsName.indexOf("Italic") !is -1) style |= DWT.ITALIC;
     if (nsName.indexOf("Bold") !is -1) style |= DWT.BOLD;
     FontData data = new FontData(name, handle.pointSize(), style);
     data.nsName = nsName;
-    return new FontData[]{data};
+    return new FontData[][data];
 }
 
 /**  
@@ -229,28 +241,30 @@
  *
  * @see #equals
  */
-public int hashCode() {
+public hash_t toHash() {
     return handle !is null ? handle.id : 0;
 }
 
+alias toHash hashCode;
+
 void init(String name, float height, int style, String nsName) {
-    if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
+    //if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     if (nsName !is null) {
-        handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), height);
+        handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height);
     } else {
         nsName = name;
         if ((style & DWT.BOLD) !is 0) nsName += " Bold";
         if ((style & DWT.ITALIC) !is 0) nsName += " Italic";
-        handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), height);
+        handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height);
         if (handle is null && (style & DWT.ITALIC) !is 0) {
             nsName = name;
             if ((style & DWT.BOLD) !is 0) nsName += " Bold";
-            handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), height);
+            handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height);
         }
         if (handle is null && (style & DWT.BOLD) !is 0) {
             nsName = name;
-            handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), height);
+            handle = NSFont.static_fontWithName_size_(NSString.stringWith(nsName), cast(CGFloat) height);
         }
     }
     if (handle is null) {
@@ -281,7 +295,7 @@
  */
 public String toString () {
     if (isDisposed()) return "Font {*DISPOSED*}";
-    return "Font {" + handle + "}";
+    return "Font {" ~ handle ~ "}";
 }
 
 }
--- a/dwt/graphics/FontData.d	Wed Sep 10 23:18:26 2008 +0200
+++ b/dwt/graphics/FontData.d	Thu Sep 11 23:16:53 2008 +0200
@@ -7,14 +7,17 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.FontData;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.DWT;
 
+import dwt.dwthelper.utils;
+
 /**
  * Instances of this class describe operating system fonts.
  * <p>
@@ -110,7 +113,7 @@
  * generated on the same platform.
  * </p>
  *
- * @param string the string representation of a <code>FontData</code> (must not be null)
+ * @param str the string representation of a <code>FontData</code> (must not be null)
  *
  * @exception IllegalArgumentException <ul>
  *    <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
@@ -119,12 +122,12 @@
  *
  * @see #toString
  */
-public this(String string) {
-    if (string is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
+public this(String str) {
+    //if (str is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     int start = 0;
-    int end = string.indexOf('|');
+    int end = str.indexOf('|');
     if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    String version1 = string.substring(start, end);
+    String version1 = str.substring(start, end);
     try {
         if (Integer.parseInt(version1) !is 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     } catch (NumberFormatException e) {
@@ -132,47 +135,47 @@
     }
     
     start = end + 1;
-    end = string.indexOf('|', start);
+    end = str.indexOf('|', start);
     if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    String name = string.substring(start, end);
+    String name = str.substring(start, end);
     
     start = end + 1;
-    end = string.indexOf('|', start);
+    end = str.indexOf('|', start);
     if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     float height = 0;
     try {
-        height = Float.parseFloat(string.substring(start, end));
+        height = Float.parseFloat(str.substring(start, end));
     } catch (NumberFormatException e) {
         DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     }
     
     start = end + 1;
-    end = string.indexOf('|', start);
+    end = str.indexOf('|', start);
     if (end is -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     int style = 0;
     try {
-        style = Integer.parseInt(string.substring(start, end));
+        style = Integer.parseInt(str.substring(start, end));
     } catch (NumberFormatException e) {
         DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     }
 
     start = end + 1;
-    end = string.indexOf('|', start);
+    end = str.indexOf('|', start);
     setName(name);
     setHeight(height);
     setStyle(style);
     if (end is -1) return;
-    String platform = string.substring(start, end);
+    String platform = str.substring(start, end);
 
     start = end + 1;
-    end = string.indexOf('|', start);
+    end = str.indexOf('|', start);
     if (end is -1) return;
-    String version2 = string.substring(start, end);
+    String version2 = str.substring(start, end);
 
     if (platform.equals("COCOA") && version2.equals("1")) {
         start = end + 1;
-        end = string.length();
-        if (start < end) nsName = string.substring(start, end);
+        end = str.length();
+        if (start < end) nsName = str.substring(start, end);
     }
 }
 
@@ -196,7 +199,7 @@
     setStyle(style);
 }
 
-/*public*/ FontData(String name, float height, int style) {
+/*public*/ this(String name, float height, int style) {
     setName(name);
     setHeight(height);
     setStyle(style);
@@ -212,13 +215,15 @@
  *
  * @see #hashCode
  */
-public bool equals (Object object) {
+public bool opEquals (Object object) {
     if (object is this) return true;
     if (!( null !is cast(FontData)object )) return false;
     FontData data = cast(FontData)object;
     return name.equals(data.name) && height is data.height && style is data.style;
 }
 
+alias opEquals equals;
+
 /**
  * Returns the height of the receiver in points.
  *
@@ -312,10 +317,12 @@
  *
  * @see #equals
  */
-public int hashCode () {
+public hast_t toHash () {
     return name.hashCode() ^ getHeight() ^ style;
 }
 
+alias toHash hashCode;
+
 /**
  * Sets the height of the receiver. The parameter is
  * specified in terms of points, where a point is one
@@ -402,7 +409,7 @@
  * @see #getName
  */
 public void setName(String name) {
-    if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
+    //if (name is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     this.name = name;
     nsName = null;
 }
--- a/dwt/graphics/GCData.d	Wed Sep 10 23:18:26 2008 +0200
+++ b/dwt/graphics/GCData.d	Thu Sep 11 23:16:53 2008 +0200
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.GCData;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.DWT;
 import dwt.internal.cocoa.NSAffineTransform;
@@ -20,6 +21,12 @@
 import dwt.internal.cocoa.NSSize;
 import dwt.internal.cocoa.NSView;
 
+import dwt.dwthelper.utils;
+import dwt.graphics.Device;
+import dwt.graphics.Pattern;
+import dwt.graphics.Image;
+import dwt.graphics.Font;
+
 /**
  * Instances of this class are descriptions of GCs in terms
  * of unallocated platform-specific data fields.
--- a/dwt/graphics/Pattern.d	Wed Sep 10 23:18:26 2008 +0200
+++ b/dwt/graphics/Pattern.d	Thu Sep 11 23:16:53 2008 +0200
@@ -7,6 +7,9 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.Pattern;
 
@@ -19,6 +22,15 @@
 import dwt.internal.cocoa.NSGradient;
 import dwt.internal.cocoa.NSPoint;
 
+import tango.text.convert.Format;
+
+import dwt.graphics.Color;
+import dwt.graphics.Device;
+import dwt.graphics.GC;
+import dwt.graphics.Image;
+import dwt.graphics.Resource;
+import dwt.internal.cocoa.CGFloat;
+
 /**
  * Instances of this class represent patterns to use while drawing. Patterns
  * can be specified either as bitmaps or gradients.
@@ -154,8 +166,8 @@
     if (color1.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     if (color2 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (color2.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    pt1 = new NSPoint();
-    pt2 = new NSPoint();
+    pt1 = NSPoint();
+    pt2 = NSPoint();
     pt1.x = x1;
     pt1.y = y1;
     pt2.x = x2;
@@ -164,9 +176,9 @@
     this.color2 = color2.handle;
     this.alpha1 = alpha1;
     this.alpha2 = alpha2;
-    NSColor start = NSColor.colorWithDeviceRed(color1.handle[0], color1.handle[1], color1.handle[2], alpha1 / 255f);
-    NSColor end = NSColor.colorWithDeviceRed(color2.handle[0], color2.handle[1], color2.handle[2], alpha2 / 255f);
-    gradient = (cast(NSGradient)new NSGradient().alloc()).initWithStartingColor(start, end);
+    NSColor start = NSColor.colorWithDeviceRed(cast(CGFloat) color1.handle[0], cast(CGFloat) color1.handle[1], cast(CGFloat) color1.handle[2], cast(CGFloat) (alpha1 / 255f));
+    NSColor end = NSColor.colorWithDeviceRed(cast(CGFloat) color2.handle[0], cast(CGFloat) color2.handle[1], cast(CGFloat) color2.handle[2], cast(CGFloat) (alpha2 / 255f));
+    gradient = (cast(NSGradient)(new NSGradient()).alloc()).initWithStartingColor(start, end);
     init();
 }
 
@@ -201,7 +213,7 @@
  */
 public String toString() {
     if (isDisposed()) return "Pattern {*DISPOSED*}";
-    return "Pattern {" + (color !is null ? color.id : gradient.id) + "}";
+    return Format("Pattern {{}{}" , (color !is null ? color.id_ : gradient.id_) , "}");
 }
     
 }
--- a/dwt/graphics/Rectangle.d	Wed Sep 10 23:18:26 2008 +0200
+++ b/dwt/graphics/Rectangle.d	Thu Sep 11 23:16:53 2008 +0200
@@ -7,14 +7,19 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.Rectangle;
 
-import dwt.dwthelper.utils;
-
 import dwt.DWT;
 import dwt.internal.SerializableCompatibility;
 
+import tango.text.convert.Format;
+
+import dwt.dwthelper.utils;
+
 /**
  * Instances of this class represent rectangular areas in an
  * (x, y) coordinate system. The top left corner of the rectangle
@@ -63,7 +68,7 @@
      */
     public int height;
 
-    static final long serialVersionUID = 3256439218279428914L;
+    static const long serialVersionUID = 3256439218279428914L;
     
 /**
  * Construct a new instance of this class given the 
@@ -150,13 +155,15 @@
  *
  * @see #hashCode()
  */
-public bool equals (Object object) {
+public bool opEquals (Object object) {
     if (object is this) return true;
     if (!( null !is cast(Rectangle)object )) return false;
     Rectangle r = cast(Rectangle)object;
     return (r.x is this.x) && (r.y is this.y) && (r.width is this.width) && (r.height is this.height);
 }
 
+alias opEquals equals;
+
 /**
  * Returns an integer hash code for the receiver. Any two 
  * objects that return <code>true</code> when passed to 
@@ -167,10 +174,12 @@
  *
  * @see #equals(Object)
  */
-public int hashCode () {
+public hash_t toHash () {
     return x ^ y ^ width ^ height;
 }
 
+alias toHash hashCode;
+
 /**
  * Destructively replaces the x, y, width and height values
  * in the receiver with ones which represent the intersection of the
@@ -309,7 +318,7 @@
  * @return a string representation of the rectangle
  */
 public String toString () {
-    return "Rectangle {" + x + ", " + y + ", " + width + ", " + height + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+    return Format( "Rectangle {{{}, {}, {}, {}}", x, y, width, height ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
 }
 
 /**
@@ -330,7 +339,7 @@
  *
  * @see #add(Rectangle)
  */
-public Rectangle union (Rectangle rect) {
+public Rectangle unionn (Rectangle rect) {
     if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     int left = x < rect.x ? x : rect.x;
     int top = y < rect.y ? y : rect.y;
--- a/dwt/graphics/Resource.d	Wed Sep 10 23:18:26 2008 +0200
+++ b/dwt/graphics/Resource.d	Thu Sep 11 23:16:53 2008 +0200
@@ -7,6 +7,9 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.Resource;