comparison dwt/graphics/Pattern.d @ 30:93b13b15f0b1

Ported a couple of modules in dwt.graphics
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Thu, 11 Sep 2008 23:16:53 +0200
parents e831403a80a9
children db5a898b2119
comparison
equal deleted inserted replaced
29:d408fc12b991 30:93b13b15f0b1
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 *
11 * Port to the D programming language:
12 * Jacob Carlborg <jacob.carlborg@gmail.com>
10 *******************************************************************************/ 13 *******************************************************************************/
11 module dwt.graphics.Pattern; 14 module dwt.graphics.Pattern;
12 15
13 import dwt.dwthelper.utils; 16 import dwt.dwthelper.utils;
14 17
16 import dwt.DWTError; 19 import dwt.DWTError;
17 import dwt.DWTException; 20 import dwt.DWTException;
18 import dwt.internal.cocoa.NSColor; 21 import dwt.internal.cocoa.NSColor;
19 import dwt.internal.cocoa.NSGradient; 22 import dwt.internal.cocoa.NSGradient;
20 import dwt.internal.cocoa.NSPoint; 23 import dwt.internal.cocoa.NSPoint;
24
25 import tango.text.convert.Format;
26
27 import dwt.graphics.Color;
28 import dwt.graphics.Device;
29 import dwt.graphics.GC;
30 import dwt.graphics.Image;
31 import dwt.graphics.Resource;
32 import dwt.internal.cocoa.CGFloat;
21 33
22 /** 34 /**
23 * Instances of this class represent patterns to use while drawing. Patterns 35 * Instances of this class represent patterns to use while drawing. Patterns
24 * can be specified either as bitmaps or gradients. 36 * can be specified either as bitmaps or gradients.
25 * <p> 37 * <p>
152 super(device); 164 super(device);
153 if (color1 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 165 if (color1 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
154 if (color1.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 166 if (color1.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
155 if (color2 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 167 if (color2 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
156 if (color2.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 168 if (color2.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
157 pt1 = new NSPoint(); 169 pt1 = NSPoint();
158 pt2 = new NSPoint(); 170 pt2 = NSPoint();
159 pt1.x = x1; 171 pt1.x = x1;
160 pt1.y = y1; 172 pt1.y = y1;
161 pt2.x = x2; 173 pt2.x = x2;
162 pt2.y = y2; 174 pt2.y = y2;
163 this.color1 = color1.handle; 175 this.color1 = color1.handle;
164 this.color2 = color2.handle; 176 this.color2 = color2.handle;
165 this.alpha1 = alpha1; 177 this.alpha1 = alpha1;
166 this.alpha2 = alpha2; 178 this.alpha2 = alpha2;
167 NSColor start = NSColor.colorWithDeviceRed(color1.handle[0], color1.handle[1], color1.handle[2], alpha1 / 255f); 179 NSColor start = NSColor.colorWithDeviceRed(cast(CGFloat) color1.handle[0], cast(CGFloat) color1.handle[1], cast(CGFloat) color1.handle[2], cast(CGFloat) (alpha1 / 255f));
168 NSColor end = NSColor.colorWithDeviceRed(color2.handle[0], color2.handle[1], color2.handle[2], alpha2 / 255f); 180 NSColor end = NSColor.colorWithDeviceRed(cast(CGFloat) color2.handle[0], cast(CGFloat) color2.handle[1], cast(CGFloat) color2.handle[2], cast(CGFloat) (alpha2 / 255f));
169 gradient = (cast(NSGradient)new NSGradient().alloc()).initWithStartingColor(start, end); 181 gradient = (cast(NSGradient)(new NSGradient()).alloc()).initWithStartingColor(start, end);
170 init(); 182 init();
171 } 183 }
172 184
173 void destroy() { 185 void destroy() {
174 if (color !is null) color.release(); 186 if (color !is null) color.release();
199 * 211 *
200 * @return a string representation of the receiver 212 * @return a string representation of the receiver
201 */ 213 */
202 public String toString() { 214 public String toString() {
203 if (isDisposed()) return "Pattern {*DISPOSED*}"; 215 if (isDisposed()) return "Pattern {*DISPOSED*}";
204 return "Pattern {" + (color !is null ? color.id : gradient.id) + "}"; 216 return Format("Pattern {{}{}" , (color !is null ? color.id_ : gradient.id_) , "}");
205 } 217 }
206 218
207 } 219 }