comparison 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
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * 10 *
11 * Port to the D programming language: 11 * Port to the D programming language:
12 * Jacob Carlborg <jacob.carlborg@gmail.com> 12 * Jacob Carlborg <doob@me.com>
13 *******************************************************************************/ 13 *******************************************************************************/
14 module dwt.graphics.Pattern; 14 module dwt.graphics.Pattern;
15 15
16 import dwt.dwthelper.utils; 16 import dwt.dwthelper.utils;
17 17
18 import dwt.DWT; 18 import dwt.DWT;
19 import dwt.DWTError; 19 import dwt.DWTError;
20 import dwt.DWTException; 20 import dwt.DWTException;
21 import dwt.internal.cocoa.NSAutoreleasePool;
21 import dwt.internal.cocoa.NSColor; 22 import dwt.internal.cocoa.NSColor;
22 import dwt.internal.cocoa.NSGradient; 23 import dwt.internal.cocoa.NSGradient;
23 import dwt.internal.cocoa.NSPoint; 24 import dwt.internal.cocoa.NSPoint;
25 import dwt.internal.cocoa.NSThread;
24 26
25 import tango.text.convert.Format; 27 import tango.text.convert.Format;
26 28
27 import dwt.graphics.Color; 29 import dwt.graphics.Color;
28 import dwt.graphics.Device; 30 import dwt.graphics.Device;
42 * <p> 44 * <p>
43 * This class requires the operating system's advanced graphics subsystem 45 * This class requires the operating system's advanced graphics subsystem
44 * which may not be available on some platforms. 46 * which may not be available on some platforms.
45 * </p> 47 * </p>
46 * 48 *
49 * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
50 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: GraphicsExample</a>
51 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
52 *
47 * @since 3.1 53 * @since 3.1
48 */ 54 */
49 public class Pattern : Resource { 55 public class Pattern : Resource {
50 alias Resource.init_ init_; 56 alias Resource.init_ init_;
51 57
83 */ 89 */
84 public this(Device device, Image image) { 90 public this(Device device, Image image) {
85 super(device); 91 super(device);
86 if (image is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 92 if (image is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
87 if (image.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 93 if (image.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
88 this.image = image; 94 NSAutoreleasePool pool = null;
89 color = NSColor.colorWithPatternImage(image.handle); 95 if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
90 color.retain(); 96 try {
97 this.image = image;
98 color = NSColor.colorWithPatternImage(image.handle);
99 color.retain();
91 init_(); 100 init_();
101 } finally {
102 if (pool !is null) pool.release();
103 }
92 } 104 }
93 105
94 /** 106 /**
95 * Constructs a new Pattern that represents a linear, two color 107 * Constructs a new Pattern that represents a linear, two color
96 * gradient. Drawing with the pattern will cause the resulting area to be 108 * gradient. Drawing with the pattern will cause the resulting area to be
166 super(device); 178 super(device);
167 if (color1 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 179 if (color1 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
168 if (color1.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 180 if (color1.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
169 if (color2 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 181 if (color2 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
170 if (color2.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 182 if (color2.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
171 pt1 = NSPoint(); 183 NSAutoreleasePool pool = null;
172 pt2 = NSPoint(); 184 if (!NSThread.isMainThread()) pool = cast(NSAutoreleasePool) (new NSAutoreleasePool()).alloc().init();
173 pt1.x = x1; 185 try {
174 pt1.y = y1; 186 pt1 = NSPoint();
175 pt2.x = x2; 187 pt2 = NSPoint();
176 pt2.y = y2; 188 pt1.x = x1;
177 this.color1 = color1.handle; 189 pt1.y = y1;
178 this.color2 = color2.handle; 190 pt2.x = x2;
179 this.alpha1 = alpha1; 191 pt2.y = y2;
180 this.alpha2 = alpha2; 192 this.color1 = color1.handle;
193 this.color2 = color2.handle;
194 this.alpha1 = alpha1;
195 this.alpha2 = alpha2;
181 NSColor start = NSColor.colorWithDeviceRed(cast(CGFloat) color1.handle[0], cast(CGFloat) color1.handle[1], cast(CGFloat) color1.handle[2], cast(CGFloat) (alpha1 / 255f)); 196 NSColor start = NSColor.colorWithDeviceRed(cast(CGFloat) color1.handle[0], cast(CGFloat) color1.handle[1], cast(CGFloat) color1.handle[2], cast(CGFloat) (alpha1 / 255f));
182 NSColor end = NSColor.colorWithDeviceRed(cast(CGFloat) color2.handle[0], cast(CGFloat) color2.handle[1], cast(CGFloat) color2.handle[2], cast(CGFloat) (alpha2 / 255f)); 197 NSColor end = NSColor.colorWithDeviceRed(cast(CGFloat) color2.handle[0], cast(CGFloat) color2.handle[1], cast(CGFloat) color2.handle[2], cast(CGFloat) (alpha2 / 255f));
183 gradient = (cast(NSGradient)(new NSGradient()).alloc()).initWithStartingColor(start, end); 198 gradient = (cast(NSGradient)(new NSGradient()).alloc()).initWithStartingColor(start, end);
184 init_(); 199 init_();
200 } finally {
201 if (pool !is null) pool.release();
202 }
185 } 203 }
186 204
187 void destroy() { 205 void destroy() {
188 if (color !is null) color.release(); 206 if (color !is null) color.release();
189 color = null; 207 color = null;