comparison 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
comparison
equal deleted inserted replaced
45:d8635bb48c7c 46:cfa563df4fdd
31 import dwt.dwthelper.utils; 31 import dwt.dwthelper.utils;
32 import dwt.graphics.Device; 32 import dwt.graphics.Device;
33 import dwt.graphics.Point; 33 import dwt.graphics.Point;
34 import dwt.graphics.Rectangle; 34 import dwt.graphics.Rectangle;
35 import dwt.graphics.Resource; 35 import dwt.graphics.Resource;
36 import dwt.internal.c.carboncore.MacTypes; 36 import Carbon = dwt.internal.c.Carbon;
37 import dwt.internal.c.qd.Quickdraw;
38 static import QuickdrawTypes = dwt.internal.c.qd.QuickdrawTypes;
39 37
40 /** 38 /**
41 * Instances of this class represent areas of an x-y coordinate 39 * Instances of this class represent areas of an x-y coordinate
42 * system that are aggregates of the areas covered by a number 40 * system that are aggregates of the areas covered by a number
43 * of polygons. 41 * of polygons.
62 * public API. It is marked public only so that it can be shared 60 * public API. It is marked public only so that it can be shared
63 * within the packages provided by DWT. It is not available on all 61 * within the packages provided by DWT. It is not available on all
64 * platforms and should never be accessed from application code. 62 * platforms and should never be accessed from application code.
65 * </p> 63 * </p>
66 */ 64 */
67 public QuickdrawTypes.RgnHandle handle; 65 public Carbon.RgnHandle handle;
68 66
69 /** 67 /**
70 * Constructs a new empty region. 68 * Constructs a new empty region.
71 * 69 *
72 * @exception DWTError <ul> 70 * @exception DWTError <ul>
97 * @since 3.0 95 * @since 3.0
98 */ 96 */
99 public this(Device device) { 97 public this(Device device) {
100 super(device); 98 super(device);
101 NSAutoreleasePool pool = null; 99 NSAutoreleasePool pool = null;
102 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); 100 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
103 try { 101 try {
104 handle = OS.NewRgn(); 102 handle = OS.NewRgn();
105 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); 103 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
106 init_(); 104 init_();
107 } finally { 105 } finally {
108 if (pool !is null) pool.release(); 106 if (pool !is null) pool.release();
109 } 107 }
110 } 108 }
111 109
112 this(Device device, QuickdrawTypes.RgnHandle handle) { 110 this(Device device, Carbon.RgnHandle handle) {
113 super(device); 111 super(device);
114 this.handle = handle; 112 this.handle = handle;
115 } 113 }
116 114
117 public static Region cocoa_new(Device device, int handle) { 115 public static Region cocoa_new(Device device, Carbon.RgnHandle handle) {
118 return new Region(device, handle); 116 return new Region(device, handle);
119 } 117 }
120 118
121 static int /*long*/ polyToRgn(int[] poly, int length) { 119 static Carbon.RgnHandle polyToRgn(int[] poly, int length) {
122 short[] r = new short[4]; 120 Carbon.Rect r;
123 int /*long*/ polyRgn = OS.NewRgn(), rectRgn = OS.NewRgn(); 121 Carbon.RgnHandle polyRgn = OS.NewRgn(), rectRgn = OS.NewRgn();
124 int minY = poly[1], maxY = poly[1]; 122 int minY = poly[1], maxY = poly[1];
125 for (int y = 3; y < length; y += 2) { 123 for (int y = 3; y < length; y += 2) {
126 if (poly[y] < minY) minY = poly[y]; 124 if (poly[y] < minY) minY = poly[y];
127 if (poly[y] > maxY) maxY = poly[y]; 125 if (poly[y] > maxY) maxY = poly[y];
128 } 126 }
131 int count = 0; 129 int count = 0;
132 int x1 = poly[0], y1 = poly[1]; 130 int x1 = poly[0], y1 = poly[1];
133 for (int p = 2; p < length; p += 2) { 131 for (int p = 2; p < length; p += 2) {
134 int x2 = poly[p], y2 = poly[p + 1]; 132 int x2 = poly[p], y2 = poly[p + 1];
135 if (y1 !is y2 && ((y1 <= y && y < y2) || (y2 <= y && y < y1))) { 133 if (y1 !is y2 && ((y1 <= y && y < y2) || (y2 <= y && y < y1))) {
136 inter[count++] = (int)((((y - y1) / (float)(y2 - y1)) * (x2 - x1)) + x1 + 0.5f); 134 inter[count++] = cast(int)((((y - y1) / cast(float)(y2 - y1)) * (x2 - x1)) + x1 + 0.5f);
137 } 135 }
138 x1 = x2; 136 x1 = x2;
139 y1 = y2; 137 y1 = y2;
140 } 138 }
141 int x2 = poly[0], y2 = poly[1]; 139 int x2 = poly[0], y2 = poly[1];
142 if (y1 !is y2 && ((y1 <= y && y < y2) || (y2 <= y && y < y1))) { 140 if (y1 !is y2 && ((y1 <= y && y < y2) || (y2 <= y && y < y1))) {
143 inter[count++] = (int)((((y - y1) / (float)(y2 - y1)) * (x2 - x1)) + x1 + 0.5f); 141 inter[count++] = cast(int)((((y - y1) / cast(float)(y2 - y1)) * (x2 - x1)) + x1 + 0.5f);
144 } 142 }
145 for (int gap=count/2; gap>0; gap/=2) { 143 for (int gap=count/2; gap>0; gap/=2) {
146 for (int i=gap; i<count; i++) { 144 for (int i=gap; i<count; i++) {
147 for (int j=i-gap; j>=0; j-=gap) { 145 for (int j=i-gap; j>=0; j-=gap) {
148 if ((inter[j] - inter[j + gap]) <= 0) 146 if ((inter[j] - inter[j + gap]) <= 0)
152 inter[j + gap] = temp; 150 inter[j + gap] = temp;
153 } 151 }
154 } 152 }
155 } 153 }
156 for (int i = 0; i < count; i += 2) { 154 for (int i = 0; i < count; i += 2) {
157 OS.SetRect(r, (short)inter[i], (short)y, (short)(inter[i + 1]),(short)(y + 1)); 155 OS.SetRect(&r, cast(short)inter[i], cast(short)y, cast(short)(inter[i + 1]), cast(short)(y + 1));
158 OS.RectRgn(rectRgn, r); 156 OS.RectRgn(rectRgn, &r);
159 OS.UnionRgn(polyRgn, rectRgn, polyRgn); 157 OS.UnionRgn(polyRgn, rectRgn, polyRgn);
160 } 158 }
161 } 159 }
162 OS.DisposeRgn(rectRgn); 160 OS.DisposeRgn(rectRgn);
163 return polyRgn; 161 return polyRgn;
164 } 162 }
165 163
166 static int /*long*/ polyRgn(int[] pointArray, int count) { 164 static Carbon.RgnHandle polyRgn(int[] pointArray, int count) {
167 NSAutoreleasePool pool = null; 165 NSAutoreleasePool pool = null;
168 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); 166 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
169 try { 167 try {
170 int /*long*/ polyRgn; 168 Carbon.RgnHandle polyRgn;
171 if (C.PTR_SIZEOF is 4) { 169 if (C.PTR_SIZEOF is 4) {
172 polyRgn = OS.NewRgn(); 170 polyRgn = OS.NewRgn();
173 OS.OpenRgn(); 171 OS.OpenRgn();
174 OS.MoveTo((short)pointArray[0], (short)pointArray[1]); 172 OS.MoveTo(cast(short)pointArray[0], cast(short)pointArray[1]);
175 for (int i = 1; i < count / 2; i++) { 173 for (int i = 1; i < count / 2; i++) {
176 OS.LineTo((short)pointArray[2 * i], (short)pointArray[2 * i + 1]); 174 OS.LineTo(cast(short)pointArray[2 * i], cast(short)pointArray[2 * i + 1]);
177 } 175 }
178 OS.LineTo((short)pointArray[0], (short)pointArray[1]); 176 OS.LineTo(cast(short)pointArray[0], cast(short)pointArray[1]);
179 OS.CloseRgn(polyRgn); 177 OS.CloseRgn(polyRgn);
180 } else { 178 } else {
181 polyRgn = polyToRgn(pointArray, count); 179 polyRgn = polyToRgn(pointArray, count);
182 } 180 }
183 return polyRgn; 181 return polyRgn;
204 */ 202 */
205 public void add (int[] pointArray) { 203 public void add (int[] pointArray) {
206 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 204 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
207 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 205 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
208 NSAutoreleasePool pool = null; 206 NSAutoreleasePool pool = null;
209 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); 207 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
210 try { 208 try {
211 add(pointArray, pointArray.length); 209 add(pointArray, pointArray.length);
212 } finally { 210 } finally {
213 if (pool !is null) pool.release(); 211 if (pool !is null) pool.release();
214 } 212 }
217 void add(int[] pointArray, int count) { 215 void add(int[] pointArray, int count) {
218 if (count <= 2) return; 216 if (count <= 2) return;
219 NSAutoreleasePool pool = null; 217 NSAutoreleasePool pool = null;
220 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); 218 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
221 try { 219 try {
222 int /*long*/ polyRgn = polyRgn(pointArray, count); 220 Carbon.RgnHandle polyRgn = polyRgn(pointArray, count);
223 OS.UnionRgn(handle, polyRgn, handle); 221 OS.UnionRgn(handle, polyRgn, handle);
224 OS.DisposeRgn(polyRgn); 222 OS.DisposeRgn(polyRgn);
225 } finally { 223 } finally {
226 if (pool !is null) pool.release(); 224 if (pool !is null) pool.release();
227 } 225 }
244 public void add(Rectangle rect) { 242 public void add(Rectangle rect) {
245 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 243 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
246 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 244 if (rect is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
247 if (rect.width < 0 || rect.height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 245 if (rect.width < 0 || rect.height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
248 NSAutoreleasePool pool = null; 246 NSAutoreleasePool pool = null;
249 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); 247 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
250 try { 248 try {
251 add (rect.x, rect.y, rect.width, rect.height); 249 add (rect.x, rect.y, rect.width, rect.height);
252 } finally { 250 } finally {
253 if (pool !is null) pool.release(); 251 if (pool !is null) pool.release();
254 } 252 }
276 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 274 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
277 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 275 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
278 NSAutoreleasePool pool = null; 276 NSAutoreleasePool pool = null;
279 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); 277 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
280 try { 278 try {
281 QuickdrawTypes.RgnHandle rectRgn = OS.NewRgn(); 279 Carbon.RgnHandle rectRgn = OS.NewRgn();
282 Rect r; 280 Carbon.Rect r;
283 OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height)); 281 OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
284 OS.RectRgn(rectRgn, &r); 282 OS.RectRgn(rectRgn, &r);
285 OS.UnionRgn(handle, rectRgn, handle); 283 OS.UnionRgn(handle, rectRgn, handle);
286 OS.DisposeRgn(rectRgn); 284 OS.DisposeRgn(rectRgn);
287 } finally { 285 } finally {
307 public void add(Region region) { 305 public void add(Region region) {
308 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 306 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
309 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 307 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
310 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 308 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
311 NSAutoreleasePool pool = null; 309 NSAutoreleasePool pool = null;
312 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); 310 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
313 try { 311 try {
314 OS.UnionRgn(handle, region.handle, handle); 312 OS.UnionRgn(handle, region.handle, handle);
315 } finally { 313 } finally {
316 if (pool !is null) pool.release(); 314 if (pool !is null) pool.release();
317 } 315 }
333 public bool contains(int x, int y) { 331 public bool contains(int x, int y) {
334 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 332 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
335 NSAutoreleasePool pool = null; 333 NSAutoreleasePool pool = null;
336 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); 334 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
337 try { 335 try {
338 QuickdrawTypes.Point point = {cast(short)x, cast(short)y}; 336 Carbon.Point point = {cast(short)x, cast(short)y};
339 return OS.PtInRgn(point, handle); 337 return OS.PtInRgn(point, handle);
340 } finally { 338 } finally {
341 if (pool !is null) pool.release(); 339 if (pool !is null) pool.release();
342 } 340 }
343 } 341 }
362 return contains(pt.x, pt.y); 360 return contains(pt.x, pt.y);
363 } 361 }
364 362
365 static NSAffineTransform transform; 363 static NSAffineTransform transform;
366 void convertRgn(NSAffineTransform transform) { 364 void convertRgn(NSAffineTransform transform) {
367 QuickdrawTypes.RgnHandle newRgn = OS.NewRgn(); 365 Carbon.RgnHandle newRgn = OS.NewRgn();
368 RegionToRectsUPP proc = &Region.convertRgn_; 366 Carbon.RegionToRectsUPP proc = &Region.convertRgn_;
369 this.transform = transform; 367 this.transform = transform;
370 OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, proc, newRgn); 368 OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, proc, newRgn);
371 this.transform = null; 369 this.transform = null;
372 OS.CopyRgn(newRgn, handle); 370 OS.CopyRgn(newRgn, handle);
373 OS.DisposeRgn(newRgn); 371 OS.DisposeRgn(newRgn);
374 } 372 }
375 373
376 extern(C) private static OSStatus* convertRgn_(ushort message, QuickdrawTypes.RgnHandle rgn, Rect* r, void* newRgn) { 374 extern(C) private static Carbon.OSStatus convertRgn_(ushort message, Carbon.RgnHandle rgn, Carbon.Rect* r, void* newRgn) {
377 if (message is OS.kQDRegionToRectsMsgParse) { 375 if (message is OS.kQDRegionToRectsMsgParse) {
378 Rect rect; 376 Carbon.Rect rect;
379 OS.memmove(&rect, r, rect.sizeof); 377 OS.memmove(&rect, r, rect.sizeof);
380 int i = 0; 378 int i = 0;
381 NSPoint point = NSPoint(); 379 NSPoint point = NSPoint();
382 int[] points = new int[10]; 380 int[] points = new int[10];
383 point.x = rect.left; 381 point.x = rect.left;
384 point.y = rect.top; 382 point.y = rect.top;
385 point = transform.transformPoint(point); 383 point = transform.transformPoint(point);
386 short startX, startY; 384 short startX, startY;
387 points[i++] = startX = (short)point.x; 385 points[i++] = startX = cast(short)point.x;
388 points[i++] = startY = (short)point.y; 386 points[i++] = startY = cast(short)point.y;
389 point.y = rect.top; 387 point.y = rect.top;
390 point = transform.transformPoint(point); 388 point = transform.transformPoint(point);
391 points[i++] = (short)Math.round(point.x); 389 points[i++] = cast(short)Math.round(point.x);
392 points[i++] = (short)point.y; 390 points[i++] = cast(short)point.y;
393 point.y = rect.bottom; 391 point.y = rect.bottom;
394 point = transform.transformPoint(point); 392 point = transform.transformPoint(point);
395 points[i++] = (short)Math.round(point.x); 393 points[i++] = cast(short)Math.round(point.x);
396 points[i++] = (short)Math.round(point.y); 394 points[i++] = cast(short)Math.round(point.y);
397 point.y = rect.bottom; 395 point.y = rect.bottom;
398 point = transform.transformPoint(point); 396 point = transform.transformPoint(point);
399 points[i++] = (short)point.x; 397 points[i++] = cast(short)point.x;
400 points[i++] = (short)Math.round(point.y); 398 points[i++] = cast(short)Math.round(point.y);
401 points[i++] = startX; 399 points[i++] = startX;
402 points[i++] = startY; 400 points[i++] = startY;
403 int /*long*/ polyRgn = polyRgn(points, points.length); 401 Carbon.RgnHandle polyRgn = polyRgn(points, points.length);
404 OS.DisposeRgn(polyRgn); 402 OS.DisposeRgn(polyRgn);
405 } 403 }
406 return null; 404 return 0;
407 } 405 }
408 406
409 void destroy() { 407 void destroy() {
410 OS.DisposeRgn(handle); 408 OS.DisposeRgn(handle);
411 handle = null; 409 handle = null;
444 * @see Rectangle#union 442 * @see Rectangle#union
445 */ 443 */
446 public Rectangle getBounds() { 444 public Rectangle getBounds() {
447 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 445 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
448 NSAutoreleasePool pool = null; 446 NSAutoreleasePool pool = null;
449 Rect bounds; 447 Carbon.Rect bounds;
450 448
451 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); 449 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
452 try { 450 try {
453 OS.GetRegionBounds(handle, &bounds); 451 OS.GetRegionBounds(handle, &bounds);
454 int width = bounds.right - bounds.left; 452 int width = bounds.right - bounds.left;
460 } 458 }
461 459
462 NSBezierPath getPath() { 460 NSBezierPath getPath() {
463 NSBezierPath path = NSBezierPath.bezierPath(); 461 NSBezierPath path = NSBezierPath.bezierPath();
464 path.retain(); 462 path.retain();
465 OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, &Region.regionToRects, path.id_); 463 OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, &Region.regionToRects, path.id);
466 if (path.isEmpty()) path.appendBezierPathWithRect(NSRect()); 464 if (path.isEmpty()) path.appendBezierPathWithRect(NSRect());
467 return path; 465 return path;
468 } 466 }
469 467
470 static NSPoint pt = NSPoint(); 468 static NSPoint pt = NSPoint();
471 static Rect rect; 469 static Carbon.Rect rect;
472 extern(C) private static OSStatus* regionToRects(ushort message, QuickdrawTypes.RgnHandle rgn, Rect* r, objc.id path) { 470 extern(C) private static Carbon.OSStatus regionToRects(ushort message, Carbon.RgnHandle rgn, Carbon.Rect* r, void* path) {
473 if (message is OS.kQDRegionToRectsMsgParse) { 471 if (message is OS.kQDRegionToRectsMsgParse) {
474 OS.memmove(&rect, r, rect.sizeof); 472 OS.memmove(&rect, r, rect.sizeof);
475 pt.x = rect.left; 473 pt.x = rect.left;
476 pt.y = rect.top; 474 pt.y = rect.top;
477 OS.objc_msgSend(path, OS.sel_moveToPoint_, pt); 475 OS.objc_msgSend(path, OS.sel_moveToPoint_, pt);
482 OS.objc_msgSend(path, OS.sel_lineToPoint_, pt); 480 OS.objc_msgSend(path, OS.sel_lineToPoint_, pt);
483 pt.x = rect.left; 481 pt.x = rect.left;
484 OS.objc_msgSend(path, OS.sel_lineToPoint_, pt); 482 OS.objc_msgSend(path, OS.sel_lineToPoint_, pt);
485 OS.objc_msgSend(path, OS.sel_closePath); 483 OS.objc_msgSend(path, OS.sel_closePath);
486 } 484 }
487 return null; 485 return 0;
488 } 486 }
489 487
490 /** 488 /**
491 * Returns an integer hash code for the receiver. Any two 489 * Returns an integer hash code for the receiver. Any two
492 * objects that return <code>true</code> when passed to 490 * objects that return <code>true</code> when passed to
545 */ 543 */
546 public void intersect(int x, int y, int width, int height) { 544 public void intersect(int x, int y, int width, int height) {
547 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 545 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
548 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 546 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
549 NSAutoreleasePool pool = null; 547 NSAutoreleasePool pool = null;
550 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); 548 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
551 try { 549 try {
552 QuickdrawTypes.RgnHandle rectRgn = OS.NewRgn(); 550 Carbon.RgnHandle rectRgn = OS.NewRgn();
553 Rect r; 551 Carbon.Rect r;
554 OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height)); 552 OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
555 OS.RectRgn(rectRgn, &r); 553 OS.RectRgn(rectRgn, &r);
556 OS.SectRgn(handle, rectRgn, handle); 554 OS.SectRgn(handle, rectRgn, handle);
557 OS.DisposeRgn(rectRgn); 555 OS.DisposeRgn(rectRgn);
558 } finally { 556 } finally {
580 public void intersect(Region region) { 578 public void intersect(Region region) {
581 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 579 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
582 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 580 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
583 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 581 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
584 NSAutoreleasePool pool = null; 582 NSAutoreleasePool pool = null;
585 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); 583 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
586 try { 584 try {
587 OS.SectRgn(handle, region.handle, handle); 585 OS.SectRgn(handle, region.handle, handle);
588 } finally { 586 } finally {
589 if (pool !is null) pool.release(); 587 if (pool !is null) pool.release();
590 } 588 }
610 public bool intersects (int x, int y, int width, int height) { 608 public bool intersects (int x, int y, int width, int height) {
611 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 609 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
612 NSAutoreleasePool pool = null; 610 NSAutoreleasePool pool = null;
613 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); 611 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
614 try { 612 try {
615 Rect r; 613 Carbon.Rect r;
616 OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height)); 614 OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
617 return OS.RectInRgn(&rect, handle); 615 return OS.RectInRgn(&rect, handle);
618 } finally { 616 } finally {
619 if (pool !is null) pool.release(); 617 if (pool !is null) pool.release();
620 } 618 }
668 * </ul> 666 * </ul>
669 */ 667 */
670 public bool isEmpty() { 668 public bool isEmpty() {
671 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 669 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
672 NSAutoreleasePool pool = null; 670 NSAutoreleasePool pool = null;
673 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); 671 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
674 try { 672 try {
675 return OS.EmptyRgn(handle); 673 return OS.EmptyRgn(handle);
676 } finally { 674 } finally {
677 if (pool !is null) pool.release(); 675 if (pool !is null) pool.release();
678 } 676 }
698 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 696 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
699 if (pointArray.length < 2) return; 697 if (pointArray.length < 2) return;
700 NSAutoreleasePool pool = null; 698 NSAutoreleasePool pool = null;
701 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); 699 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
702 try { 700 try {
703 int /*long*/ polyRgn = polyRgn(pointArray, pointArray.length); 701 Carbon.RgnHandle polyRgn = polyRgn(pointArray, pointArray.length);
704 OS.DiffRgn(handle, polyRgn, handle); 702 OS.DiffRgn(handle, polyRgn, handle);
705 OS.DisposeRgn(polyRgn); 703 OS.DisposeRgn(polyRgn);
706 } finally { 704 } finally {
707 if (pool !is null) pool.release(); 705 if (pool !is null) pool.release();
708 } 706 }
752 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 750 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
753 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 751 if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
754 NSAutoreleasePool pool = null; 752 NSAutoreleasePool pool = null;
755 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); 753 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
756 try { 754 try {
757 int /*long*/ rectRgn = OS.NewRgn(); 755 Carbon.RgnHandle rectRgn = OS.NewRgn();
758 Rect r; 756 Carbon.Rect r;
759 OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height)); 757 OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
760 OS.RectRgn(rectRgn, &r); 758 OS.RectRgn(rectRgn, &r);
761 OS.DiffRgn(handle, rectRgn, handle); 759 OS.DiffRgn(handle, rectRgn, handle);
762 OS.DisposeRgn(rectRgn); 760 OS.DisposeRgn(rectRgn);
763 } finally { 761 } finally {
836 */ 834 */
837 public void translate (Point pt) { 835 public void translate (Point pt) {
838 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 836 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
839 if (pt is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 837 if (pt is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
840 NSAutoreleasePool pool = null; 838 NSAutoreleasePool pool = null;
841 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); 839 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
842 try { 840 try {
843 translate (pt.x, pt.y); 841 translate (pt.x, pt.y);
844 } finally { 842 } finally {
845 if (pool !is null) pool.release(); 843 if (pool !is null) pool.release();
846 } 844 }