diff dwt/graphics/GC.d @ 34:5123b17c98ef

Ported dwt.events.*, dwt.graphics.GC, Region, dwt.internal.image.*
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sun, 14 Sep 2008 01:45:57 +0200
parents a9ab4c738ed8
children db5a898b2119
line wrap: on
line diff
--- a/dwt/graphics/GC.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/graphics/GC.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,10 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.GC;
 
-import dwt.dwthelper.utils;
 
 import dwt.DWT;
 import dwt.DWTError;
@@ -31,6 +33,29 @@
 import dwt.internal.cocoa.NSString;
 import dwt.internal.cocoa.OS;
 
+import tango.text.convert.Format;
+
+import dwt.dwthelper.utils;
+import dwt.graphics.Color;
+import dwt.graphics.Device;
+import dwt.graphics.Drawable;
+import dwt.graphics.Font;
+import dwt.graphics.FontMetrics;
+import dwt.graphics.GCData;
+import dwt.graphics.Image;
+import dwt.graphics.ImageData;
+import dwt.graphics.LineAttributes;
+import dwt.graphics.Path;
+import dwt.graphics.Pattern;
+import dwt.graphics.Point;
+import dwt.graphics.Rectangle;
+import dwt.graphics.Region;
+import dwt.graphics.Resource;
+import dwt.graphics.RGB;
+import dwt.graphics.Transform;
+import dwt.internal.cocoa.CGFloat;
+import objc = dwt.internal.objc.runtime;
+
 /**
  * Class <code>GC</code> is where all of the drawing capabilities that are 
  * supported by DWT are located. Instances are used to draw on either an 
@@ -76,31 +101,31 @@
     Drawable drawable;
     GCData data;
 
-    static final int TAB_COUNT = 32;
+    static const int TAB_COUNT = 32;
 
-    final static int FOREGROUND = 1 << 0;
-    final static int BACKGROUND = 1 << 1;
-    final static int FONT = 1 << 2;
-    final static int LINE_STYLE = 1 << 3;
-    final static int LINE_CAP = 1 << 4;
-    final static int LINE_JOIN = 1 << 5;
-    final static int LINE_WIDTH = 1 << 6;
-    final static int LINE_MITERLIMIT = 1 << 7;
-    final static int FOREGROUND_FILL = 1 << 8;
-    final static int DRAW_OFFSET = 1 << 9;
-    final static int CLIPPING = 1 << 10;
-    final static int TRANSFORM = 1 << 11;
-    final static int DRAW = CLIPPING | TRANSFORM | FOREGROUND | LINE_WIDTH | LINE_STYLE  | LINE_CAP  | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET;
-    final static int FILL = CLIPPING | TRANSFORM | BACKGROUND;
+    const static int FOREGROUND = 1 << 0;
+    const static int BACKGROUND = 1 << 1;
+    const static int FONT = 1 << 2;
+    const static int LINE_STYLE = 1 << 3;
+    const static int LINE_CAP = 1 << 4;
+    const static int LINE_JOIN = 1 << 5;
+    const static int LINE_WIDTH = 1 << 6;
+    const static int LINE_MITERLIMIT = 1 << 7;
+    const static int FOREGROUND_FILL = 1 << 8;
+    const static int DRAW_OFFSET = 1 << 9;
+    const static int CLIPPING = 1 << 10;
+    const static int TRANSFORM = 1 << 11;
+    const static int DRAW = CLIPPING | TRANSFORM | FOREGROUND | LINE_WIDTH | LINE_STYLE  | LINE_CAP  | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET;
+    const static int FILL = CLIPPING | TRANSFORM | BACKGROUND;
 
-    static final float[] LINE_DOT = new float[]{1, 1};
-    static final float[] LINE_DASH = new float[]{3, 1};
-    static final float[] LINE_DASHDOT = new float[]{3, 1, 1, 1};
-    static final float[] LINE_DASHDOTDOT = new float[]{3, 1, 1, 1, 1, 1};
-    static final float[] LINE_DOT_ZERO = new float[]{3, 3};
-    static final float[] LINE_DASH_ZERO = new float[]{18, 6};
-    static final float[] LINE_DASHDOT_ZERO = new float[]{9, 6, 3, 6};
-    static final float[] LINE_DASHDOTDOT_ZERO = new float[]{9, 3, 3, 3, 3, 3};
+    static const CGFloat[] LINE_DOT = new CGFloat[][1, 1];
+    static const CGFloat[] LINE_DASH = new CGFloat[][3, 1];
+    static const CGFloat[] LINE_DASHDOT = new CGFloat[][3, 1, 1, 1];
+    static const CGFloat[] LINE_DASHDOTDOT = new CGFloat[][3, 1, 1, 1, 1, 1];
+    static const CGFloat[] LINE_DOT_ZERO = new CGFloat[][3, 3];
+    static const CGFloat[] LINE_DASH_ZERO = new CGFloat[][18, 6];
+    static const CGFloat[] LINE_DASHDOT_ZERO = new CGFloat[][9, 6, 3, 6];
+    static const CGFloat[] LINE_DASHDOTDOT_ZERO = new CGFloat[][9, 3, 3, 3, 3, 3];
 
 this() {
 }
@@ -162,7 +187,7 @@
     if (drawable is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     GCData data = new GCData();
     data.style = checkStyle(style);
-    int contextId = drawable.internal_new_GC(data);
+    size_t contextId = drawable.internal_new_GC(data);
     Device device = data.device;
     if (device is null) device = Device.getDevice();
     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
@@ -195,7 +220,7 @@
  */
 public static GC cocoa_new(Drawable drawable, GCData data) {
     GC gc = new GC();
-    int context = drawable.internal_new_GC(data);
+    size_t context = drawable.internal_new_GC(data);
     gc.device = data.device;
     gc.init(drawable, data, context);
     return gc;
@@ -244,7 +269,7 @@
         if (pattern !is null) {
             if (pattern.color !is null) pattern.color.setStroke();
         } else {
-            float[] color = data.foreground;
+            CGFloat[] color = data.foreground;
             NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setStroke();
         }
     }
@@ -253,7 +278,7 @@
         if (pattern !is null) {
             if (pattern.color !is null) pattern.color.setFill();
         } else {
-            float[] color = data.foreground;
+            CGFloat[] color = data.foreground;
             NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setFill();
         }
         data.state &= ~BACKGROUND;
@@ -263,14 +288,14 @@
         if (pattern !is null) {
             if (pattern.color !is null) pattern.color.setFill();
         } else {
-            float[] color = data.background;
+            CGFloat[] color = data.background;
             NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setFill();
         }
         data.state &= ~FOREGROUND_FILL;
     }
     NSBezierPath path = data.path;
     if ((state & LINE_WIDTH) !is 0) {
-        path.setLineWidth(data.lineWidth is 0 ?  1 : data.lineWidth);
+        path.setLineWidth((data.lineWidth is 0 ?  1 : data.lineWidth));
         switch (data.lineStyle) {
             case DWT.LINE_DOT:
             case DWT.LINE_DASH:
@@ -280,8 +305,8 @@
         }
     }
     if ((state & LINE_STYLE) !is 0) {
-        float[] dashes = null;
-        float width = data.lineWidth;
+        CGFloat[] dashes = null;
+        CGFloat width = data.lineWidth;
         switch (data.lineStyle) {
             case DWT.LINE_SOLID: break;
             case DWT.LINE_DASH: dashes = width !is 0 ? LINE_DASH : LINE_DASH_ZERO; break;
@@ -291,11 +316,11 @@
             case DWT.LINE_CUSTOM: dashes = data.lineDashes; break;
         }
         if (dashes !is null) {
-            float[] lengths = new float[dashes.length];
+            CGFloat[] lengths = new CGFloat[dashes.length];
             for (int i = 0; i < lengths.length; i++) {
                 lengths[i] = width is 0 || data.lineStyle is DWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width;
             }
-            path.setLineDash(lengths, lengths.length, data.lineDashesOffset);
+            path.setLineDash(lengths.ptr, lengths.length, data.lineDashesOffset);
         } else {
             path.setLineDash(null, 0, 0);
         }
@@ -310,7 +335,7 @@
             case DWT.JOIN_ROUND: joinStyle = OS.NSRoundLineJoinStyle; break;
             case DWT.JOIN_BEVEL: joinStyle = OS.NSBevelLineJoinStyle; break;
         }
-        path.setLineJoinStyle(joinStyle);
+        path.setLineJoinStyle(cast(objc.id_) joinStyle);
     }
     if ((state & LINE_CAP) !is 0) {
         int capStyle = 0;
@@ -319,25 +344,25 @@
             case DWT.CAP_FLAT: capStyle = OS.NSButtLineCapStyle; break;
             case DWT.CAP_SQUARE: capStyle = OS.NSSquareLineCapStyle; break;
         }
-        path.setLineCapStyle(capStyle);
+        path.setLineCapStyle(cast(objc.id_) capStyle);
     }
     if ((state & DRAW_OFFSET) !is 0) {
         data.drawXOffset = data.drawYOffset = 0;
-        NSSize size = new NSSize();
+        NSSize size = NSSize();
         size.width = size.height = 1;
         if (data.transform !is null) {
             size = data.transform.transformSize(size);
         }
-        float scaling = size.width;
+        CGFloat scaling = size.width;
         if (scaling < 0) scaling = -scaling;
-        float strokeWidth = data.lineWidth * scaling;
-        if (strokeWidth is 0 || (cast(int)strokeWidth % 2) is 1) {
+        CGFloat strokeWidth = data.lineWidth * scaling;
+        if (strokeWidth is 0 || (cast(size_t)strokeWidth % 2) is 1) {
             data.drawXOffset = 0.5f / scaling;
         }
         scaling = size.height;
         if (scaling < 0) scaling = -scaling;
         strokeWidth = data.lineWidth * scaling;
-        if (strokeWidth is 0 || (cast(int)strokeWidth % 2) is 1) {
+        if (strokeWidth is 0 || (cast(size_t)strokeWidth % 2) is 1) {
             data.drawYOffset = 0.5f / scaling;
         }
     }
@@ -615,16 +640,16 @@
 
 NSAttributedString createString(String string, int flags) {
     NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4);
-    float[] foreground = data.foreground;
+    CGFloat[] foreground = data.foreground;
     NSColor color = NSColor.colorWithDeviceRed(foreground[0], foreground[1], foreground[2], data.alpha / 255f);
     dict.setObject(color, OS.NSForegroundColorAttributeName());
     dict.setObject(data.font.handle, OS.NSFontAttributeName());
     if ((flags & DWT.DRAW_TRANSPARENT) is 0) {
-        float[] background = data.background;
+        CGFloat[] background = data.background;
         color = NSColor.colorWithDeviceRed(background[0], background[1], background[2], data.alpha / 255f);
         dict.setObject(color, OS.NSBackgroundColorAttributeName());
     }
-    int length = string.length();
+    size_t length = string.length();
     char[] chars = new char[length];
     string.getChars(0, length, chars, 0);
 //  int breakCount = 0;
@@ -662,8 +687,8 @@
 //      }
 //      length = j;
 //  }
-    NSString str = NSString.stringWithCharacters(chars, length);
-    return (cast(NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict);
+    NSString str = NSString.stringWithCharacters(chars.toCharArray().ptr, length);
+    return (cast(NSAttributedString)(new NSAttributedString()).alloc()).initWithString_attributes_(str, dict);
 }
 
 void destroy() {
@@ -680,7 +705,7 @@
     data.transform = data.inverseTransform = null;
     
     /* Dispose the GC */
-    if (drawable !is null) drawable.internal_dispose_GC(handle.id, data);
+    if (drawable !is null) drawable.internal_dispose_GC(handle.id_, data);
     handle.restoreGraphicsState();
     handle.release();
 
@@ -735,13 +760,13 @@
     if (width is 0 || height is 0 || arcAngle is 0) return;
     handle.saveGraphicsState();
     NSAffineTransform transform = NSAffineTransform.transform();
-    float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
+    CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset;
     transform.translateXBy(x + xOffset + width / 2f, y + yOffset + height / 2f);
     transform.scaleXBy(width / 2f, height / 2f);
     NSBezierPath path = data.path;
-    NSPoint center = new NSPoint();
-    float sAngle = -startAngle;
-    float eAngle = -(startAngle + arcAngle);
+    NSPoint center = NSPoint();
+    CGFloat sAngle = -startAngle;
+    CGFloat eAngle = -(startAngle + arcAngle);
     path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_clockwise_(center, 1, sAngle,  eAngle, arcAngle>0);
     path.transformUsingAffineTransform(transform);
     path.stroke();
@@ -879,12 +904,12 @@
     transform.scaleXBy(1, -1);
     transform.translateXBy(0, -(destHeight + 2 * destY));
     transform.concat();
-    NSRect srcRect = new NSRect();
+    NSRect srcRect = NSRect();
     srcRect.x = srcX;
     srcRect.y = srcY;
     srcRect.width = srcWidth;
     srcRect.height = srcHeight;
-    NSRect destRect = new NSRect();
+    NSRect destRect = NSRect();
     destRect.x = destX;
     destRect.y = destY;
     destRect.width = destWidth;
@@ -913,7 +938,7 @@
     NSGraphicsContext.setCurrentContext(handle);
     checkGC(DRAW);
     NSBezierPath path = data.path;
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = x1 + data.drawXOffset;
     pt.y = y1 + data.drawYOffset;
     path.moveToPoint(pt);
@@ -960,7 +985,7 @@
         height = -height;
     }
     NSBezierPath path = data.path;
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x + data.drawXOffset;
     rect.y = y + data.drawXOffset;
     rect.width = width;
@@ -1035,7 +1060,7 @@
     NSGraphicsContext context = NSGraphicsContext.currentContext();
     NSGraphicsContext.setCurrentContext(handle);
     checkGC(FOREGROUND_FILL);
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = 1;
@@ -1071,9 +1096,9 @@
     NSGraphicsContext.setCurrentContext(handle);
     checkGC(DRAW);
     if (pointArray.length < 4) return;
-    float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
+    CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset;
     NSBezierPath path = data.path;
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = pointArray[0] + xOffset;
     pt.y = pointArray[1] + yOffset;
     path.moveToPoint(pt);
@@ -1113,9 +1138,9 @@
     NSGraphicsContext.setCurrentContext(handle);
     checkGC(DRAW);
     if (pointArray.length < 4) return;
-    float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
+    CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset;
     NSBezierPath path = data.path;
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = pointArray[0] + xOffset;
     pt.y = pointArray[1] + yOffset;
     path.moveToPoint(pt);
@@ -1158,7 +1183,7 @@
         y = y + height;
         height = -height;
     }
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x + data.drawXOffset;
     rect.y = y + data.drawYOffset;
     rect.width = width;
@@ -1224,7 +1249,7 @@
         return;
     }
     NSBezierPath path = data.path;
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x + data.drawXOffset;
     rect.y = y + data.drawYOffset;
     rect.width = width;
@@ -1377,7 +1402,7 @@
         transform.translateXBy(0, -(str.size().height + 2 * y));
         transform.concat();
     }
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = x;
     pt.y = y;
     str.drawAtPoint(pt);
@@ -1398,12 +1423,14 @@
  *
  * @see #hashCode
  */
-public bool equals(Object object) {
+public bool opEquals(Object object) {
     if (object is this) return true;
     if (!( null !is cast(GC)object )) return false;
     return handle is (cast(GC)object).handle;
 }
 
+alias opEquals equals;
+
 /**
  * Fills the interior of a circular or elliptical arc within
  * the specified rectangular area, with the receiver's background
@@ -1452,14 +1479,14 @@
     if (width is 0 || height is 0 || arcAngle is 0) return;
     handle.saveGraphicsState();
     NSAffineTransform transform = NSAffineTransform.transform();
-    float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
+    CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset;
     transform.translateXBy(x + xOffset + width / 2f, y + yOffset + height / 2f);
     transform.scaleXBy(width / 2f, height / 2f);
     NSBezierPath path = data.path;
-    NSPoint center = new NSPoint();
+    NSPoint center = NSPoint();
     path.moveToPoint(center);
-    float sAngle = -startAngle;
-    float eAngle = -(startAngle + arcAngle);
+    CGFloat sAngle = -startAngle;
+    CGFloat eAngle = -(startAngle + arcAngle);
     path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_clockwise_(center, 1, sAngle,  eAngle, arcAngle>0);
     path.closePath();
     path.transformUsingAffineTransform(transform);
@@ -1521,8 +1548,8 @@
     } else {
         NSColor startingColor = NSColor.colorWithDeviceRed(fromRGB.red / 255f, fromRGB.green / 255f, fromRGB.blue / 255f, data.alpha / 255f);
         NSColor endingColor = NSColor.colorWithDeviceRed(toRGB.red / 255f, toRGB.green / 255f, toRGB.blue / 255f, data.alpha / 255f);
-        NSGradient gradient = (cast(NSGradient)new NSGradient().alloc()).initWithStartingColor(startingColor, endingColor);
-        NSRect rect = new NSRect();
+        NSGradient gradient = (cast(NSGradient)(new NSGradient()).alloc()).initWithStartingColor(startingColor, endingColor);
+        NSRect rect = NSRect();
         rect.x = x;
         rect.y = y;
         rect.width = width;
@@ -1563,7 +1590,7 @@
         height = -height;
     }
     NSBezierPath path = data.path;
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = width;
@@ -1656,7 +1683,7 @@
     checkGC(FILL);
     if (pointArray.length < 4) return;
     NSBezierPath path = data.path;
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = pointArray[0];
     pt.y = pointArray[1];
     path.moveToPoint(pt);
@@ -1705,7 +1732,7 @@
         y = y + height;
         height = -height;
     }
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = width;
@@ -1770,7 +1797,7 @@
         return;
     }
     NSBezierPath path = data.path;
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = width;
@@ -1807,7 +1834,7 @@
 public int getAdvanceWidth(char ch) {   
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     //NOT DONE
-    return stringExtent(new String(new char[]{ch})).x;
+    return stringExtent(new char[][ch]).x;
 }
 
 /** 
@@ -1929,7 +1956,7 @@
 public int getCharWidth(char ch) {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     //NOT DONE
-    return stringExtent(new String(new char[]{ch})).x;
+    return stringExtent(new char[][ch]).x;
 }
 
 /** 
@@ -1946,11 +1973,11 @@
  */
 public Rectangle getClipping() {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSRect rect = null;
+    NSRect rect = void;
     if (data.view !is null) {
         rect = data.view.bounds();
     } else {
-        rect = new NSRect();
+        rect = NSRect();
         if (data.image !is null) {
             NSSize size = data.image.handle.size();
             rect.width = size.width;
@@ -1969,10 +1996,10 @@
             OS.NSIntersectionRect(rect, rect, clip);
         }
         if (data.inverseTransform !is null && rect.width > 0 && rect.height > 0) {
-            NSPoint pt = new NSPoint();
+            NSPoint pt = NSPoint();
             pt.x = rect.x;
             pt.y = rect.y;
-            NSSize size = new NSSize();
+            NSSize size = NSSize();
             size.width = rect.width;
             size.height = rect.height;
             pt = data.inverseTransform.transformPoint(pt);
@@ -2005,11 +2032,11 @@
     if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     region.subtract(region);
-    NSRect rect = null;
+    NSRect rect = void;
     if (data.view !is null) {
         rect = data.view.bounds();
     } else {
-        rect = new NSRect();
+        rect = NSRect();
         if (data.image !is null) {
             NSSize size = data.image.handle.size();
             rect.width = size.width;
@@ -2030,11 +2057,11 @@
         int pointCount = 0;
         Region clipRgn = new Region(device);
         int[] pointArray = new int[count * 2];
-        int points = OS.malloc(NSPoint.sizeof);
-        if (points is 0) DWT.error(DWT.ERROR_NO_HANDLES);
-        NSPoint pt = new NSPoint();
-        for (int i = 0; i < count; i++) {
-            int element = clip.elementAtIndex_associatedPoints_(i, points);
+        NSPointArray points = cast(NSPointArray) OS.malloc(NSPoint.sizeof);
+        if (points is null) DWT.error(DWT.ERROR_NO_HANDLES);
+        NSPoint pt = NSPoint();
+        for (NSInteger  i = 0; i < count; i++) {
+            NSBezierPathElement element = clip.elementAtIndex_associatedPoints_(i, points);
             switch (element) {
                 case OS.NSMoveToBezierPathElement:
                     if (pointCount !is 0) clipRgn.add(pointArray, pointCount);
@@ -2214,9 +2241,9 @@
  */
 public LineAttributes getLineAttributes() {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    float[] dashes = null;
+    CGFloat[] dashes = null;
     if (data.lineDashes !is null) {
-        dashes = new float[data.lineDashes.length];
+        dashes = new CGFloat[data.lineDashes.length];
         System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length);
     }
     return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit);
@@ -2382,8 +2409,8 @@
     if (transform.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     NSAffineTransform cmt = data.transform;
     if (cmt !is null) {
-        NSAffineTransformStruct struct = cmt.transformStruct();
-        transform.handle.setTransformStruct(struct);
+        NSAffineTransformStruct structt = cmt.transformStruct();
+        transform.handle.setTransformStruct(structt);
     } else {
         transform.setElements(1, 0, 0, 1, 0, 0);
     }
@@ -2422,11 +2449,13 @@
  *
  * @see #equals
  */
-public int hashCode() {
-    return handle !is null ? handle.id : 0;
+public hash_t toHash() {
+    return handle !is null ? handle.id_ : 0;
 }
 
-void init(Drawable drawable, GCData data, int context) {
+alias toHash hashCode;
+
+void init(Drawable drawable, GCData data, objc.id context) {
     if (data.foreground !is null) data.state &= ~(FOREGROUND | FOREGROUND_FILL);
     if (data.background !is null)  data.state &= ~BACKGROUND;
     if (data.font !is null) data.state &= ~FONT;
@@ -2690,7 +2719,7 @@
         y = y + height;
         height = -height;
     }
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = width;
@@ -2729,7 +2758,7 @@
 public void setClipping(Path path) {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (path !is null && path.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    setClipping(new NSBezierPath(path.handle.copy().id));
+    setClipping(new NSBezierPath(path.handle.copy().id_));
 }
 
 /**
@@ -2815,7 +2844,7 @@
             DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     }
     data.fillRule = rule;
-    data.path.setWindingRule(rule is DWT.FILL_WINDING ? OS.NSNonZeroWindingRule : OS.NSEvenOddWindingRule);
+    data.path.setWindingRule(rule is DWT.FILL_WINDING ? cast(objc.id) OS.NSNonZeroWindingRule : cast(objc.id) OS.NSEvenOddWindingRule);
 }
 
 /** 
@@ -2922,7 +2951,7 @@
  */
 public void setInterpolation(int interpolation) {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    int quality = 0;
+    NSImageInterpolation quality = 0;
     switch (interpolation) {
         case DWT.DEFAULT: quality = OS.NSImageInterpolationDefault; break;
         case DWT.NONE: quality = OS.NSImageInterpolationNone; break;
@@ -2962,7 +2991,7 @@
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (attributes is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     int mask = 0;
-    float lineWidth = attributes.width;
+    CGFloat lineWidth = attributes.width;
     if (lineWidth !is data.lineWidth) {
         mask |= LINE_WIDTH | DRAW_OFFSET;
     }
@@ -3007,8 +3036,8 @@
                 DWT.error(DWT.ERROR_INVALID_ARGUMENT);
         }
     }
-    float[] dashes = attributes.dash;
-    float[] lineDashes = data.lineDashes;
+    CGFloat[] dashes = attributes.dash;
+    CGFloat[] lineDashes = data.lineDashes;
     if (dashes !is null && dashes.length > 0) {
         bool changed = lineDashes is null || lineDashes.length !is dashes.length;
         for (int i = 0; i < dashes.length; i++) {
@@ -3017,7 +3046,7 @@
             if (!changed && lineDashes[i] !is dash) changed = true;
         }
         if (changed) {
-            float[] newDashes = new float[dashes.length];
+            CGFloat[] newDashes = new CGFloat[dashes.length];
             System.arraycopy(dashes, 0, newDashes, 0, dashes.length);
             dashes = newDashes;
             mask |= LINE_STYLE;
@@ -3031,7 +3060,7 @@
             dashes = lineDashes;
         }
     }
-    float dashOffset = attributes.dashOffset;
+    CGFloat dashOffset = attributes.dashOffset;
     if (dashOffset !is data.lineDashesOffset) {
         mask |= LINE_STYLE;     
     }
@@ -3100,7 +3129,7 @@
  */
 public void setLineDash(int[] dashes) {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    float[] lineDashes = data.lineDashes;
+    CGFloat[] lineDashes = data.lineDashes;
     if (dashes !is null && dashes.length > 0) {
         bool changed = data.lineStyle !is DWT.LINE_CUSTOM || lineDashes is null || lineDashes.length !is dashes.length;
         for (int i = 0; i < dashes.length; i++) {
@@ -3109,7 +3138,7 @@
             if (!changed && lineDashes[i] !is dash) changed = true;
         }
         if (!changed) return;
-        data.lineDashes = new float[dashes.length];
+        data.lineDashes = new CGFloat[dashes.length];
         for (int i = 0; i < dashes.length; i++) {
             data.lineDashes[i] = dashes[i];
         }
@@ -3312,10 +3341,10 @@
     if (transform !is null) {
         if (data.transform !is null) data.transform.release();
         if (data.inverseTransform !is null) data.inverseTransform.release();
-        data.transform = (cast(NSAffineTransform)new NSAffineTransform().alloc()).initWithTransform(transform.handle);
-        data.inverseTransform = (cast(NSAffineTransform)new NSAffineTransform().alloc()).initWithTransform(transform.handle);
-        NSAffineTransformStruct struct = data.inverseTransform.transformStruct();
-        if ((struct.m11 * struct.m22 - struct.m12 * struct.m21) !is 0) {
+        data.transform = (cast(NSAffineTransform)(new NSAffineTransform()).alloc()).initWithTransform(transform.handle);
+        data.inverseTransform = (cast(NSAffineTransform)(new NSAffineTransform()).alloc()).initWithTransform(transform.handle);
+        NSAffineTransformStruct structt = data.inverseTransform.transformStruct();
+        if ((structt.m11 * structt.m22 - structt.m12 * structt.m21) !is 0) {
             data.inverseTransform.invert();
         }
     } else {
@@ -3418,7 +3447,7 @@
  */
 public String toString () {
     if (isDisposed()) return "GC {*DISPOSED*}";
-    return "GC {" + handle + "}";
+    return Format("GC {{}{}" , handle , "}");
 }
 
 }