diff dwt/graphics/Region.d @ 46:cfa563df4fdd

Updated Widget and Display to 3.514
author Jacob Carlborg <doob@me.com>
date Fri, 05 Dec 2008 16:00:41 +0100
parents d8635bb48c7c
children 62202ce0039f
line wrap: on
line diff
--- a/dwt/graphics/Region.d	Mon Dec 01 17:07:00 2008 +0100
+++ b/dwt/graphics/Region.d	Fri Dec 05 16:00:41 2008 +0100
@@ -33,9 +33,7 @@
 import dwt.graphics.Point;
 import dwt.graphics.Rectangle;
 import dwt.graphics.Resource;
-import dwt.internal.c.carboncore.MacTypes;
-import dwt.internal.c.qd.Quickdraw;
-static import QuickdrawTypes = dwt.internal.c.qd.QuickdrawTypes;
+import Carbon = dwt.internal.c.Carbon;
 
 /**
  * Instances of this class represent areas of an x-y coordinate
@@ -64,7 +62,7 @@
      * platforms and should never be accessed from application code.
      * </p>
      */
-    public QuickdrawTypes.RgnHandle handle;
+    public Carbon.RgnHandle handle;
 
 /**
  * Constructs a new empty region.
@@ -99,7 +97,7 @@
 public this(Device device) {
     super(device);
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         handle = OS.NewRgn();
     if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
@@ -109,18 +107,18 @@
     }
 }
 
-this(Device device, QuickdrawTypes.RgnHandle handle) {
+this(Device device, Carbon.RgnHandle handle) {
     super(device);
     this.handle = handle;
 }
 
-public static Region cocoa_new(Device device, int handle) {
+public static Region cocoa_new(Device device, Carbon.RgnHandle handle) {
     return new Region(device, handle);
 }
 
-static int /*long*/ polyToRgn(int[] poly, int length) {
-    short[] r = new short[4];
-    int /*long*/ polyRgn = OS.NewRgn(), rectRgn = OS.NewRgn();
+static Carbon.RgnHandle polyToRgn(int[] poly, int length) {
+    Carbon.Rect r;
+    Carbon.RgnHandle polyRgn = OS.NewRgn(), rectRgn = OS.NewRgn();
     int minY = poly[1], maxY = poly[1];
     for (int y = 3; y < length; y += 2) {
         if (poly[y] < minY) minY = poly[y];
@@ -133,14 +131,14 @@
         for (int p = 2; p < length; p += 2) {
             int x2 = poly[p], y2 = poly[p + 1];
             if (y1 !is y2 && ((y1 <= y && y < y2) || (y2 <= y && y < y1))) {
-                inter[count++] = (int)((((y - y1) / (float)(y2 - y1)) * (x2 - x1)) + x1 + 0.5f);
+                inter[count++] = cast(int)((((y - y1) / cast(float)(y2 - y1)) * (x2 - x1)) + x1 + 0.5f);
             }
             x1 = x2;
             y1 = y2;
         }
         int x2 = poly[0], y2 = poly[1];         
         if (y1 !is y2 && ((y1 <= y && y < y2) || (y2 <= y && y < y1))) {
-            inter[count++] = (int)((((y - y1) / (float)(y2 - y1)) * (x2 - x1)) + x1 + 0.5f);
+            inter[count++] = cast(int)((((y - y1) / cast(float)(y2 - y1)) * (x2 - x1)) + x1 + 0.5f);
         }
         for (int gap=count/2; gap>0; gap/=2) {
             for (int i=gap; i<count; i++) {
@@ -154,8 +152,8 @@
             }
         }
         for (int i = 0; i < count; i += 2) {
-            OS.SetRect(r, (short)inter[i], (short)y, (short)(inter[i + 1]),(short)(y + 1));
-            OS.RectRgn(rectRgn, r);
+            OS.SetRect(&r, cast(short)inter[i], cast(short)y, cast(short)(inter[i + 1]), cast(short)(y + 1));
+            OS.RectRgn(rectRgn, &r);
             OS.UnionRgn(polyRgn, rectRgn, polyRgn);
         }
     }
@@ -163,19 +161,19 @@
     return polyRgn;
 }
 
-static int /*long*/ polyRgn(int[] pointArray, int count) {
+static Carbon.RgnHandle polyRgn(int[] pointArray, int count) {
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
-        int /*long*/ polyRgn;
+        Carbon.RgnHandle polyRgn;
         if (C.PTR_SIZEOF is 4) {
             polyRgn = OS.NewRgn();
             OS.OpenRgn();
-            OS.MoveTo((short)pointArray[0], (short)pointArray[1]);
+            OS.MoveTo(cast(short)pointArray[0], cast(short)pointArray[1]);
             for (int i = 1; i < count / 2; i++) {
-                OS.LineTo((short)pointArray[2 * i], (short)pointArray[2 * i + 1]);
+                OS.LineTo(cast(short)pointArray[2 * i], cast(short)pointArray[2 * i + 1]);
             }
-            OS.LineTo((short)pointArray[0], (short)pointArray[1]);
+            OS.LineTo(cast(short)pointArray[0], cast(short)pointArray[1]);
             OS.CloseRgn(polyRgn);
         } else {
             polyRgn = polyToRgn(pointArray, count);
@@ -206,7 +204,7 @@
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         add(pointArray, pointArray.length);
     } finally {
@@ -219,7 +217,7 @@
     NSAutoreleasePool pool = null;
     if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
-        int /*long*/ polyRgn = polyRgn(pointArray, count);
+        Carbon.RgnHandle polyRgn = polyRgn(pointArray, count);
         OS.UnionRgn(handle, polyRgn, handle);
         OS.DisposeRgn(polyRgn);
     } finally {
@@ -246,7 +244,7 @@
     if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (rect.width < 0 || rect.height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         add (rect.x, rect.y, rect.width, rect.height);
     } finally {
@@ -278,8 +276,8 @@
     NSAutoreleasePool pool = null;
     if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
-        QuickdrawTypes.RgnHandle rectRgn = OS.NewRgn();
-        Rect r;
+        Carbon.RgnHandle rectRgn = OS.NewRgn();
+        Carbon.Rect r;
         OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
         OS.RectRgn(rectRgn, &r);
         OS.UnionRgn(handle, rectRgn, handle);
@@ -309,7 +307,7 @@
     if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         OS.UnionRgn(handle, region.handle, handle);
     } finally {
@@ -335,7 +333,7 @@
     NSAutoreleasePool pool = null;
     if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
-        QuickdrawTypes.Point point = {cast(short)x, cast(short)y};
+        Carbon.Point point = {cast(short)x, cast(short)y};
         return OS.PtInRgn(point, handle);
     } finally {
         if (pool !is null) pool.release();
@@ -364,8 +362,8 @@
 
 static NSAffineTransform transform;
 void convertRgn(NSAffineTransform transform) {
-    QuickdrawTypes.RgnHandle newRgn = OS.NewRgn();
-    RegionToRectsUPP proc = &Region.convertRgn_;
+    Carbon.RgnHandle newRgn = OS.NewRgn();
+    Carbon.RegionToRectsUPP proc = &Region.convertRgn_;
     this.transform = transform;
     OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, proc, newRgn);
     this.transform = null;
@@ -373,9 +371,9 @@
     OS.DisposeRgn(newRgn);
 }
 
-extern(C) private static OSStatus* convertRgn_(ushort message, QuickdrawTypes.RgnHandle rgn, Rect* r, void* newRgn) {
+extern(C) private static Carbon.OSStatus convertRgn_(ushort message, Carbon.RgnHandle rgn, Carbon.Rect* r, void* newRgn) {
     if (message is OS.kQDRegionToRectsMsgParse) {
-        Rect rect;
+        Carbon.Rect rect;
         OS.memmove(&rect, r, rect.sizeof);
         int i = 0;
         NSPoint point = NSPoint();
@@ -384,26 +382,26 @@
         point.y = rect.top;
         point = transform.transformPoint(point);
         short startX, startY;
-        points[i++] = startX = (short)point.x;
-        points[i++] = startY = (short)point.y;
+        points[i++] = startX = cast(short)point.x;
+        points[i++] = startY = cast(short)point.y;
         point.y = rect.top;
         point = transform.transformPoint(point);
-        points[i++] = (short)Math.round(point.x);
-        points[i++] = (short)point.y;
+        points[i++] = cast(short)Math.round(point.x);
+        points[i++] = cast(short)point.y;
         point.y = rect.bottom;
         point = transform.transformPoint(point);
-        points[i++] = (short)Math.round(point.x);
-        points[i++] = (short)Math.round(point.y);
+        points[i++] = cast(short)Math.round(point.x);
+        points[i++] = cast(short)Math.round(point.y);
         point.y = rect.bottom;
         point = transform.transformPoint(point);
-        points[i++] = (short)point.x;
-        points[i++] = (short)Math.round(point.y);
+        points[i++] = cast(short)point.x;
+        points[i++] = cast(short)Math.round(point.y);
         points[i++] = startX;
         points[i++] = startY;
-        int /*long*/ polyRgn = polyRgn(points, points.length);
+        Carbon.RgnHandle polyRgn = polyRgn(points, points.length);
         OS.DisposeRgn(polyRgn);
     }
-    return null;
+    return 0;
 }
 
 void destroy() {
@@ -446,7 +444,7 @@
 public Rectangle getBounds() {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     NSAutoreleasePool pool = null;
-    Rect bounds;
+    Carbon.Rect bounds;
 
     if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
@@ -462,14 +460,14 @@
 NSBezierPath getPath() {
     NSBezierPath path = NSBezierPath.bezierPath();
     path.retain();
-    OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, &Region.regionToRects, path.id_);
+    OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, &Region.regionToRects, path.id);
     if (path.isEmpty()) path.appendBezierPathWithRect(NSRect());
     return path;
 }
 
 static NSPoint pt = NSPoint();
-static Rect rect;
-extern(C) private static OSStatus* regionToRects(ushort message, QuickdrawTypes.RgnHandle rgn, Rect* r, objc.id path) {
+static Carbon.Rect rect;
+extern(C) private static Carbon.OSStatus regionToRects(ushort message, Carbon.RgnHandle rgn, Carbon.Rect* r, void* path) {
     if (message is OS.kQDRegionToRectsMsgParse) {
         OS.memmove(&rect, r, rect.sizeof);
         pt.x = rect.left;
@@ -484,7 +482,7 @@
         OS.objc_msgSend(path, OS.sel_lineToPoint_, pt);
         OS.objc_msgSend(path, OS.sel_closePath);
     }
-    return null;
+    return 0;
 }
 
 /**
@@ -547,10 +545,10 @@
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
-        QuickdrawTypes.RgnHandle rectRgn = OS.NewRgn();
-        Rect r;
+        Carbon.RgnHandle rectRgn = OS.NewRgn();
+        Carbon.Rect r;
         OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
         OS.RectRgn(rectRgn, &r);
         OS.SectRgn(handle, rectRgn, handle);
@@ -582,7 +580,7 @@
     if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         OS.SectRgn(handle, region.handle, handle);
     } finally {
@@ -612,7 +610,7 @@
     NSAutoreleasePool pool = null;
     if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
-        Rect r;
+        Carbon.Rect r;
         OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
         return OS.RectInRgn(&rect, handle);
     } finally {
@@ -670,7 +668,7 @@
 public bool isEmpty() {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         return OS.EmptyRgn(handle);
     } finally {
@@ -700,7 +698,7 @@
     NSAutoreleasePool pool = null;
     if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
-        int /*long*/ polyRgn = polyRgn(pointArray, pointArray.length);
+        Carbon.RgnHandle polyRgn = polyRgn(pointArray, pointArray.length);
         OS.DiffRgn(handle, polyRgn, handle);
         OS.DisposeRgn(polyRgn);
     } finally {
@@ -754,8 +752,8 @@
     NSAutoreleasePool pool = null;
     if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
-        int /*long*/ rectRgn = OS.NewRgn();
-        Rect r;
+        Carbon.RgnHandle rectRgn = OS.NewRgn();
+        Carbon.Rect r;
         OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
         OS.RectRgn(rectRgn, &r);
         OS.DiffRgn(handle, rectRgn, handle);
@@ -838,7 +836,7 @@
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (pt is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     NSAutoreleasePool pool = null;
-    if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+    if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
     try {
         translate (pt.x, pt.y);
     } finally {