Mercurial > projects > dwt-mac
diff dwt/graphics/Pattern.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | db5a898b2119 |
children | cfa563df4fdd |
line wrap: on
line diff
--- a/dwt/graphics/Pattern.d Tue Oct 21 15:20:04 2008 +0200 +++ b/dwt/graphics/Pattern.d Mon Dec 01 17:07:00 2008 +0100 @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,7 +9,7 @@ * IBM Corporation - initial API and implementation * * Port to the D programming language: - * Jacob Carlborg <jacob.carlborg@gmail.com> + * Jacob Carlborg <doob@me.com> *******************************************************************************/ module dwt.graphics.Pattern; @@ -18,9 +18,11 @@ import dwt.DWT; import dwt.DWTError; import dwt.DWTException; +import dwt.internal.cocoa.NSAutoreleasePool; import dwt.internal.cocoa.NSColor; import dwt.internal.cocoa.NSGradient; import dwt.internal.cocoa.NSPoint; +import dwt.internal.cocoa.NSThread; import tango.text.convert.Format; @@ -44,6 +46,10 @@ * which may not be available on some platforms. * </p> * + * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: GraphicsExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + * * @since 3.1 */ public class Pattern : Resource { @@ -85,10 +91,16 @@ super(device); if (image is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); if (image.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); - this.image = image; - color = NSColor.colorWithPatternImage(image.handle); - color.retain(); + NSAutoreleasePool pool = null; + if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); + try { + this.image = image; + color = NSColor.colorWithPatternImage(image.handle); + color.retain(); init_(); + } finally { + if (pool !is null) pool.release(); + } } /** @@ -168,20 +180,26 @@ 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 = NSPoint(); - pt2 = NSPoint(); - pt1.x = x1; - pt1.y = y1; - pt2.x = x2; - pt2.y = y2; - this.color1 = color1.handle; - this.color2 = color2.handle; - this.alpha1 = alpha1; - this.alpha2 = alpha2; + NSAutoreleasePool pool = null; + if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init(); + try { + pt1 = NSPoint(); + pt2 = NSPoint(); + pt1.x = x1; + pt1.y = y1; + pt2.x = x2; + pt2.y = y2; + this.color1 = color1.handle; + this.color2 = color2.handle; + this.alpha1 = alpha1; + this.alpha2 = alpha2; 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_(); + } finally { + if (pool !is null) pool.release(); + } } void destroy() {