diff dwt/graphics/GC.d @ 36:db5a898b2119

Fixed a lot of compile errors
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Tue, 07 Oct 2008 12:56:18 +0200
parents 5123b17c98ef
children 642f460a0908
line wrap: on
line diff
--- a/dwt/graphics/GC.d	Sun Sep 14 23:32:29 2008 +0200
+++ b/dwt/graphics/GC.d	Tue Oct 07 12:56:18 2008 +0200
@@ -26,6 +26,7 @@
 import dwt.internal.cocoa.NSGradient;
 import dwt.internal.cocoa.NSGraphicsContext;
 import dwt.internal.cocoa.NSImage;
+import dwt.internal.cocoa.NSInteger;
 import dwt.internal.cocoa.NSMutableDictionary;
 import dwt.internal.cocoa.NSPoint;
 import dwt.internal.cocoa.NSRect;
@@ -86,6 +87,9 @@
  * @see dwt.events.PaintEvent
  */
 public final class GC : Resource {
+   
+    alias Resource.init_ init_;
+    
     /**
      * the handle to the OS device context
      * (Warning: This field is platform dependent)
@@ -118,14 +122,14 @@
     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 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];
+    static const CGFloat[] LINE_DOT = [1, 1];
+    static const CGFloat[] LINE_DASH = [3, 1];
+    static const CGFloat[] LINE_DASHDOT = [3, 1, 1, 1];
+    static const CGFloat[] LINE_DASHDOTDOT = [3, 1, 1, 1, 1, 1];
+    static const CGFloat[] LINE_DOT_ZERO = [3, 3];
+    static const CGFloat[] LINE_DASH_ZERO = [18, 6];
+    static const CGFloat[] LINE_DASHDOT_ZERO = [9, 6, 3, 6];
+    static const CGFloat[] LINE_DASHDOTDOT_ZERO = [9, 3, 3, 3, 3, 3];
 
 this() {
 }
@@ -151,7 +155,7 @@
  *    <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
  *    <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
  * </ul>
- */
+ */ 
 public this(Drawable drawable) {
     this(drawable, 0);
 }
@@ -187,13 +191,13 @@
     if (drawable is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     GCData data = new GCData();
     data.style = checkStyle(style);
-    size_t contextId = drawable.internal_new_GC(data);
+    objc.id 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);
     this.device = data.device = device;
-    init(drawable, data, contextId);
-    init();
+    init_(drawable, data, contextId);
+    init_();
 }
 
 static int checkStyle (int style) {
@@ -220,9 +224,9 @@
  */
 public static GC cocoa_new(Drawable drawable, GCData data) {
     GC gc = new GC();
-    size_t context = drawable.internal_new_GC(data);
+    objc.id context = drawable.internal_new_GC(data);
     gc.device = data.device;
-    gc.init(drawable, data, context);
+    gc.init_(drawable, data, context);
     return gc;
 }
 
@@ -241,10 +245,10 @@
  *
  * @return a new <code>GC</code>
  */
-public static GC carbon_new(int context, GCData data) {
+public static GC carbon_new(objc.id context, GCData data) {
     GC gc = new GC();
     gc.device = data.device;
-    gc.init(null, data, context);
+    gc.init_(null, data, context);
     return gc;
 }
 
@@ -329,22 +333,22 @@
         path.setMiterLimit(data.lineMiterLimit);
     }
     if ((state & LINE_JOIN) !is 0) {
-        int joinStyle = 0;
+        NSLineJoinStyle joinStyle;
         switch (data.lineJoin) {
-            case DWT.JOIN_MITER: joinStyle = OS.NSMiterLineJoinStyle; break;
-            case DWT.JOIN_ROUND: joinStyle = OS.NSRoundLineJoinStyle; break;
-            case DWT.JOIN_BEVEL: joinStyle = OS.NSBevelLineJoinStyle; break;
+            case DWT.JOIN_MITER: joinStyle = NSMiterLineJoinStyle; break;
+            case DWT.JOIN_ROUND: joinStyle = NSRoundLineJoinStyle; break;
+            case DWT.JOIN_BEVEL: joinStyle = NSBevelLineJoinStyle; break;
         }
-        path.setLineJoinStyle(cast(objc.id_) joinStyle);
+        path.setLineJoinStyle(joinStyle);
     }
     if ((state & LINE_CAP) !is 0) {
-        int capStyle = 0;
+        NSLineCapStyle capStyle;
         switch (data.lineCap) {
-            case DWT.CAP_ROUND: capStyle = OS.NSRoundLineCapStyle; break;
-            case DWT.CAP_FLAT: capStyle = OS.NSButtLineCapStyle; break;
-            case DWT.CAP_SQUARE: capStyle = OS.NSSquareLineCapStyle; break;
+            case DWT.CAP_ROUND: capStyle = NSRoundLineCapStyle; break;
+            case DWT.CAP_FLAT: capStyle = NSButtLineCapStyle; break;
+            case DWT.CAP_SQUARE: capStyle = NSSquareLineCapStyle; break;
         }
-        path.setLineCapStyle(cast(objc.id_) capStyle);
+        path.setLineCapStyle(capStyle);
     }
     if ((state & DRAW_OFFSET) !is 0) {
         data.drawXOffset = data.drawYOffset = 0;
@@ -366,7 +370,7 @@
             data.drawYOffset = 0.5f / scaling;
         }
     }
-}
+} 
 
 /**
  * Copies a rectangular area of the receiver at the specified
@@ -914,7 +918,7 @@
     destRect.y = destY;
     destRect.width = destWidth;
     destRect.height = destHeight;
-    imageHandle.drawInRect(destRect, srcRect, OS.NSCompositeSourceOver, 1);
+    imageHandle.drawInRect(destRect, srcRect, NSCompositeSourceOver, 1);
     handle.restoreGraphicsState();
     NSGraphicsContext.setCurrentContext(context);
 }
@@ -1423,7 +1427,7 @@
  *
  * @see #hashCode
  */
-public bool opEquals(Object object) {
+public int opEquals(Object object) {
     if (object is this) return true;
     if (!( null !is cast(GC)object )) return false;
     return handle is (cast(GC)object).handle;
@@ -1834,7 +1838,7 @@
 public int getAdvanceWidth(char ch) {   
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     //NOT DONE
-    return stringExtent(new char[][ch]).x;
+    return stringExtent([ch]).x;
 }
 
 /** 
@@ -1956,7 +1960,7 @@
 public int getCharWidth(char ch) {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     //NOT DONE
-    return stringExtent(new char[][ch]).x;
+    return stringExtent([ch]).x;
 }
 
 /** 
@@ -1973,7 +1977,7 @@
  */
 public Rectangle getClipping() {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSRect rect = void;
+    NSRect rect;
     if (data.view !is null) {
         rect = data.view.bounds();
     } else {
@@ -1989,11 +1993,11 @@
     }
     if (data.paintRect !is null || data.clipPath !is null || data.inverseTransform !is null) {
         if (data.paintRect !is null) {
-            OS.NSIntersectionRect(rect, rect, data.paintRect);
+            rect = OS.NSIntersectionRect(rect, *data.paintRect);
         }
         if (data.clipPath !is null) {
             NSRect clip = data.clipPath.bounds();
-            OS.NSIntersectionRect(rect, rect, clip);
+            rect = OS.NSIntersectionRect(rect, clip);
         }
         if (data.inverseTransform !is null && rect.width > 0 && rect.height > 0) {
             NSPoint pt = NSPoint();
@@ -2047,8 +2051,8 @@
         }
     }
     region.add(cast(int)rect.x, cast(int)rect.y, cast(int)rect.width, cast(int)rect.height);
-    NSRect paintRect = data.paintRect;
-    if (paintRect !is null) {
+    NSRect paintRect = *data.paintRect;
+    if (paintRect !is NSRect.init) {
         region.intersect(cast(int)paintRect.x, cast(int)paintRect.y, cast(int)paintRect.width, cast(int)paintRect.height);
     }
     if (data.clipPath !is null) {
@@ -2060,22 +2064,22 @@
         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++) {
+        for (int  i = 0; i < count; i++) {
             NSBezierPathElement element = clip.elementAtIndex_associatedPoints_(i, points);
             switch (element) {
-                case OS.NSMoveToBezierPathElement:
+                case NSMoveToBezierPathElement:
                     if (pointCount !is 0) clipRgn.add(pointArray, pointCount);
                     pointCount = 0;
-                    OS.memmove(pt, points, NSPoint.sizeof);
+                    OS.memmove(&pt, points, NSPoint.sizeof);
                     pointArray[pointCount++] = cast(int)pt.x;
                     pointArray[pointCount++] = cast(int)pt.y;
                     break;
-                case OS.NSLineToBezierPathElement:
-                    OS.memmove(pt, points, NSPoint.sizeof);
+                case NSLineToBezierPathElement:
+                    OS.memmove(&pt, points, NSPoint.sizeof);
                     pointArray[pointCount++] = cast(int)pt.x;
                     pointArray[pointCount++] = cast(int)pt.y;
                     break;
-                case OS.NSClosePathBezierPathElement:
+                case NSClosePathBezierPathElement:
                     if (pointCount !is 0) clipRgn.add(pointArray, pointCount);
                     pointCount = 0;
                     break;
@@ -2450,12 +2454,12 @@
  * @see #equals
  */
 public hash_t toHash() {
-    return handle !is null ? handle.id_ : 0;
+    return handle !is null ? cast(hash_t)handle.id_ : 0;
 }
 
 alias toHash hashCode;
 
-void init(Drawable drawable, GCData data, objc.id context) {
+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;
@@ -2469,7 +2473,7 @@
     handle.retain();
     handle.saveGraphicsState();
     data.path = NSBezierPath.bezierPath();
-    data.path.setWindingRule(data.fillRule is DWT.FILL_WINDING ? OS.NSNonZeroWindingRule : OS.NSEvenOddWindingRule);
+    data.path.setWindingRule(data.fillRule is DWT.FILL_WINDING ? NSNonZeroWindingRule : NSEvenOddWindingRule);
     data.path.retain();
 }
 
@@ -2694,7 +2698,7 @@
     data.backgroundPattern = pattern;
     data.state &= ~BACKGROUND;
 }
-
+    
 /**
  * Sets the area of the receiver which can be changed
  * by drawing operations to the rectangular area specified
@@ -2844,7 +2848,7 @@
             DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     }
     data.fillRule = rule;
-    data.path.setWindingRule(rule is DWT.FILL_WINDING ? cast(objc.id) OS.NSNonZeroWindingRule : cast(objc.id) OS.NSEvenOddWindingRule);
+    data.path.setWindingRule(rule is DWT.FILL_WINDING ? NSNonZeroWindingRule : NSEvenOddWindingRule);
 }
 
 /** 
@@ -2951,12 +2955,12 @@
  */
 public void setInterpolation(int interpolation) {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSImageInterpolation quality = 0;
+    NSImageInterpolation quality;
     switch (interpolation) {
-        case DWT.DEFAULT: quality = OS.NSImageInterpolationDefault; break;
-        case DWT.NONE: quality = OS.NSImageInterpolationNone; break;
-        case DWT.LOW: quality = OS.NSImageInterpolationLow; break;
-        case DWT.HIGH: quality = OS.NSImageInterpolationHigh; break;
+        case DWT.DEFAULT: quality = NSImageInterpolationDefault; break;
+        case DWT.NONE: quality = NSImageInterpolationNone; break;
+        case DWT.LOW: quality = NSImageInterpolationLow; break;
+        case DWT.HIGH: quality = NSImageInterpolationHigh; break;
         default:
             DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     }