Mercurial > projects > dwt-mac
comparison dwt/graphics/GC.d @ 34:5123b17c98ef
Ported dwt.events.*, dwt.graphics.GC, Region, dwt.internal.image.*
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sun, 14 Sep 2008 01:45:57 +0200 |
parents | a9ab4c738ed8 |
children | db5a898b2119 |
comparison
equal
deleted
inserted
replaced
33:965ac0a77267 | 34:5123b17c98ef |
---|---|
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.GC; | 14 module dwt.graphics.GC; |
12 | 15 |
13 import dwt.dwthelper.utils; | |
14 | 16 |
15 import dwt.DWT; | 17 import dwt.DWT; |
16 import dwt.DWTError; | 18 import dwt.DWTError; |
17 import dwt.DWTException; | 19 import dwt.DWTException; |
18 import dwt.internal.cocoa.NSAffineTransform; | 20 import dwt.internal.cocoa.NSAffineTransform; |
29 import dwt.internal.cocoa.NSRect; | 31 import dwt.internal.cocoa.NSRect; |
30 import dwt.internal.cocoa.NSSize; | 32 import dwt.internal.cocoa.NSSize; |
31 import dwt.internal.cocoa.NSString; | 33 import dwt.internal.cocoa.NSString; |
32 import dwt.internal.cocoa.OS; | 34 import dwt.internal.cocoa.OS; |
33 | 35 |
36 import tango.text.convert.Format; | |
37 | |
38 import dwt.dwthelper.utils; | |
39 import dwt.graphics.Color; | |
40 import dwt.graphics.Device; | |
41 import dwt.graphics.Drawable; | |
42 import dwt.graphics.Font; | |
43 import dwt.graphics.FontMetrics; | |
44 import dwt.graphics.GCData; | |
45 import dwt.graphics.Image; | |
46 import dwt.graphics.ImageData; | |
47 import dwt.graphics.LineAttributes; | |
48 import dwt.graphics.Path; | |
49 import dwt.graphics.Pattern; | |
50 import dwt.graphics.Point; | |
51 import dwt.graphics.Rectangle; | |
52 import dwt.graphics.Region; | |
53 import dwt.graphics.Resource; | |
54 import dwt.graphics.RGB; | |
55 import dwt.graphics.Transform; | |
56 import dwt.internal.cocoa.CGFloat; | |
57 import objc = dwt.internal.objc.runtime; | |
58 | |
34 /** | 59 /** |
35 * Class <code>GC</code> is where all of the drawing capabilities that are | 60 * Class <code>GC</code> is where all of the drawing capabilities that are |
36 * supported by DWT are located. Instances are used to draw on either an | 61 * supported by DWT are located. Instances are used to draw on either an |
37 * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>. | 62 * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>. |
38 * <dl> | 63 * <dl> |
74 public NSGraphicsContext handle; | 99 public NSGraphicsContext handle; |
75 | 100 |
76 Drawable drawable; | 101 Drawable drawable; |
77 GCData data; | 102 GCData data; |
78 | 103 |
79 static final int TAB_COUNT = 32; | 104 static const int TAB_COUNT = 32; |
80 | 105 |
81 final static int FOREGROUND = 1 << 0; | 106 const static int FOREGROUND = 1 << 0; |
82 final static int BACKGROUND = 1 << 1; | 107 const static int BACKGROUND = 1 << 1; |
83 final static int FONT = 1 << 2; | 108 const static int FONT = 1 << 2; |
84 final static int LINE_STYLE = 1 << 3; | 109 const static int LINE_STYLE = 1 << 3; |
85 final static int LINE_CAP = 1 << 4; | 110 const static int LINE_CAP = 1 << 4; |
86 final static int LINE_JOIN = 1 << 5; | 111 const static int LINE_JOIN = 1 << 5; |
87 final static int LINE_WIDTH = 1 << 6; | 112 const static int LINE_WIDTH = 1 << 6; |
88 final static int LINE_MITERLIMIT = 1 << 7; | 113 const static int LINE_MITERLIMIT = 1 << 7; |
89 final static int FOREGROUND_FILL = 1 << 8; | 114 const static int FOREGROUND_FILL = 1 << 8; |
90 final static int DRAW_OFFSET = 1 << 9; | 115 const static int DRAW_OFFSET = 1 << 9; |
91 final static int CLIPPING = 1 << 10; | 116 const static int CLIPPING = 1 << 10; |
92 final static int TRANSFORM = 1 << 11; | 117 const static int TRANSFORM = 1 << 11; |
93 final static int DRAW = CLIPPING | TRANSFORM | FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET; | 118 const static int DRAW = CLIPPING | TRANSFORM | FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET; |
94 final static int FILL = CLIPPING | TRANSFORM | BACKGROUND; | 119 const static int FILL = CLIPPING | TRANSFORM | BACKGROUND; |
95 | 120 |
96 static final float[] LINE_DOT = new float[]{1, 1}; | 121 static const CGFloat[] LINE_DOT = new CGFloat[][1, 1]; |
97 static final float[] LINE_DASH = new float[]{3, 1}; | 122 static const CGFloat[] LINE_DASH = new CGFloat[][3, 1]; |
98 static final float[] LINE_DASHDOT = new float[]{3, 1, 1, 1}; | 123 static const CGFloat[] LINE_DASHDOT = new CGFloat[][3, 1, 1, 1]; |
99 static final float[] LINE_DASHDOTDOT = new float[]{3, 1, 1, 1, 1, 1}; | 124 static const CGFloat[] LINE_DASHDOTDOT = new CGFloat[][3, 1, 1, 1, 1, 1]; |
100 static final float[] LINE_DOT_ZERO = new float[]{3, 3}; | 125 static const CGFloat[] LINE_DOT_ZERO = new CGFloat[][3, 3]; |
101 static final float[] LINE_DASH_ZERO = new float[]{18, 6}; | 126 static const CGFloat[] LINE_DASH_ZERO = new CGFloat[][18, 6]; |
102 static final float[] LINE_DASHDOT_ZERO = new float[]{9, 6, 3, 6}; | 127 static const CGFloat[] LINE_DASHDOT_ZERO = new CGFloat[][9, 6, 3, 6]; |
103 static final float[] LINE_DASHDOTDOT_ZERO = new float[]{9, 3, 3, 3, 3, 3}; | 128 static const CGFloat[] LINE_DASHDOTDOT_ZERO = new CGFloat[][9, 3, 3, 3, 3, 3]; |
104 | 129 |
105 this() { | 130 this() { |
106 } | 131 } |
107 | 132 |
108 /** | 133 /** |
160 */ | 185 */ |
161 public this(Drawable drawable, int style) { | 186 public this(Drawable drawable, int style) { |
162 if (drawable is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 187 if (drawable is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
163 GCData data = new GCData(); | 188 GCData data = new GCData(); |
164 data.style = checkStyle(style); | 189 data.style = checkStyle(style); |
165 int contextId = drawable.internal_new_GC(data); | 190 size_t contextId = drawable.internal_new_GC(data); |
166 Device device = data.device; | 191 Device device = data.device; |
167 if (device is null) device = Device.getDevice(); | 192 if (device is null) device = Device.getDevice(); |
168 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 193 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
169 this.device = data.device = device; | 194 this.device = data.device = device; |
170 init(drawable, data, contextId); | 195 init(drawable, data, contextId); |
193 * | 218 * |
194 * @private | 219 * @private |
195 */ | 220 */ |
196 public static GC cocoa_new(Drawable drawable, GCData data) { | 221 public static GC cocoa_new(Drawable drawable, GCData data) { |
197 GC gc = new GC(); | 222 GC gc = new GC(); |
198 int context = drawable.internal_new_GC(data); | 223 size_t context = drawable.internal_new_GC(data); |
199 gc.device = data.device; | 224 gc.device = data.device; |
200 gc.init(drawable, data, context); | 225 gc.init(drawable, data, context); |
201 return gc; | 226 return gc; |
202 } | 227 } |
203 | 228 |
242 if ((state & FOREGROUND) !is 0) { | 267 if ((state & FOREGROUND) !is 0) { |
243 Pattern pattern = data.foregroundPattern; | 268 Pattern pattern = data.foregroundPattern; |
244 if (pattern !is null) { | 269 if (pattern !is null) { |
245 if (pattern.color !is null) pattern.color.setStroke(); | 270 if (pattern.color !is null) pattern.color.setStroke(); |
246 } else { | 271 } else { |
247 float[] color = data.foreground; | 272 CGFloat[] color = data.foreground; |
248 NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setStroke(); | 273 NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setStroke(); |
249 } | 274 } |
250 } | 275 } |
251 if ((state & FOREGROUND_FILL) !is 0) { | 276 if ((state & FOREGROUND_FILL) !is 0) { |
252 Pattern pattern = data.foregroundPattern; | 277 Pattern pattern = data.foregroundPattern; |
253 if (pattern !is null) { | 278 if (pattern !is null) { |
254 if (pattern.color !is null) pattern.color.setFill(); | 279 if (pattern.color !is null) pattern.color.setFill(); |
255 } else { | 280 } else { |
256 float[] color = data.foreground; | 281 CGFloat[] color = data.foreground; |
257 NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setFill(); | 282 NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setFill(); |
258 } | 283 } |
259 data.state &= ~BACKGROUND; | 284 data.state &= ~BACKGROUND; |
260 } | 285 } |
261 if ((state & BACKGROUND) !is 0) { | 286 if ((state & BACKGROUND) !is 0) { |
262 Pattern pattern = data.backgroundPattern; | 287 Pattern pattern = data.backgroundPattern; |
263 if (pattern !is null) { | 288 if (pattern !is null) { |
264 if (pattern.color !is null) pattern.color.setFill(); | 289 if (pattern.color !is null) pattern.color.setFill(); |
265 } else { | 290 } else { |
266 float[] color = data.background; | 291 CGFloat[] color = data.background; |
267 NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setFill(); | 292 NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setFill(); |
268 } | 293 } |
269 data.state &= ~FOREGROUND_FILL; | 294 data.state &= ~FOREGROUND_FILL; |
270 } | 295 } |
271 NSBezierPath path = data.path; | 296 NSBezierPath path = data.path; |
272 if ((state & LINE_WIDTH) !is 0) { | 297 if ((state & LINE_WIDTH) !is 0) { |
273 path.setLineWidth(data.lineWidth is 0 ? 1 : data.lineWidth); | 298 path.setLineWidth((data.lineWidth is 0 ? 1 : data.lineWidth)); |
274 switch (data.lineStyle) { | 299 switch (data.lineStyle) { |
275 case DWT.LINE_DOT: | 300 case DWT.LINE_DOT: |
276 case DWT.LINE_DASH: | 301 case DWT.LINE_DASH: |
277 case DWT.LINE_DASHDOT: | 302 case DWT.LINE_DASHDOT: |
278 case DWT.LINE_DASHDOTDOT: | 303 case DWT.LINE_DASHDOTDOT: |
279 state |= LINE_STYLE; | 304 state |= LINE_STYLE; |
280 } | 305 } |
281 } | 306 } |
282 if ((state & LINE_STYLE) !is 0) { | 307 if ((state & LINE_STYLE) !is 0) { |
283 float[] dashes = null; | 308 CGFloat[] dashes = null; |
284 float width = data.lineWidth; | 309 CGFloat width = data.lineWidth; |
285 switch (data.lineStyle) { | 310 switch (data.lineStyle) { |
286 case DWT.LINE_SOLID: break; | 311 case DWT.LINE_SOLID: break; |
287 case DWT.LINE_DASH: dashes = width !is 0 ? LINE_DASH : LINE_DASH_ZERO; break; | 312 case DWT.LINE_DASH: dashes = width !is 0 ? LINE_DASH : LINE_DASH_ZERO; break; |
288 case DWT.LINE_DOT: dashes = width !is 0 ? LINE_DOT : LINE_DOT_ZERO; break; | 313 case DWT.LINE_DOT: dashes = width !is 0 ? LINE_DOT : LINE_DOT_ZERO; break; |
289 case DWT.LINE_DASHDOT: dashes = width !is 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break; | 314 case DWT.LINE_DASHDOT: dashes = width !is 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break; |
290 case DWT.LINE_DASHDOTDOT: dashes = width !is 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break; | 315 case DWT.LINE_DASHDOTDOT: dashes = width !is 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break; |
291 case DWT.LINE_CUSTOM: dashes = data.lineDashes; break; | 316 case DWT.LINE_CUSTOM: dashes = data.lineDashes; break; |
292 } | 317 } |
293 if (dashes !is null) { | 318 if (dashes !is null) { |
294 float[] lengths = new float[dashes.length]; | 319 CGFloat[] lengths = new CGFloat[dashes.length]; |
295 for (int i = 0; i < lengths.length; i++) { | 320 for (int i = 0; i < lengths.length; i++) { |
296 lengths[i] = width is 0 || data.lineStyle is DWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width; | 321 lengths[i] = width is 0 || data.lineStyle is DWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width; |
297 } | 322 } |
298 path.setLineDash(lengths, lengths.length, data.lineDashesOffset); | 323 path.setLineDash(lengths.ptr, lengths.length, data.lineDashesOffset); |
299 } else { | 324 } else { |
300 path.setLineDash(null, 0, 0); | 325 path.setLineDash(null, 0, 0); |
301 } | 326 } |
302 } | 327 } |
303 if ((state & LINE_MITERLIMIT) !is 0) { | 328 if ((state & LINE_MITERLIMIT) !is 0) { |
308 switch (data.lineJoin) { | 333 switch (data.lineJoin) { |
309 case DWT.JOIN_MITER: joinStyle = OS.NSMiterLineJoinStyle; break; | 334 case DWT.JOIN_MITER: joinStyle = OS.NSMiterLineJoinStyle; break; |
310 case DWT.JOIN_ROUND: joinStyle = OS.NSRoundLineJoinStyle; break; | 335 case DWT.JOIN_ROUND: joinStyle = OS.NSRoundLineJoinStyle; break; |
311 case DWT.JOIN_BEVEL: joinStyle = OS.NSBevelLineJoinStyle; break; | 336 case DWT.JOIN_BEVEL: joinStyle = OS.NSBevelLineJoinStyle; break; |
312 } | 337 } |
313 path.setLineJoinStyle(joinStyle); | 338 path.setLineJoinStyle(cast(objc.id_) joinStyle); |
314 } | 339 } |
315 if ((state & LINE_CAP) !is 0) { | 340 if ((state & LINE_CAP) !is 0) { |
316 int capStyle = 0; | 341 int capStyle = 0; |
317 switch (data.lineCap) { | 342 switch (data.lineCap) { |
318 case DWT.CAP_ROUND: capStyle = OS.NSRoundLineCapStyle; break; | 343 case DWT.CAP_ROUND: capStyle = OS.NSRoundLineCapStyle; break; |
319 case DWT.CAP_FLAT: capStyle = OS.NSButtLineCapStyle; break; | 344 case DWT.CAP_FLAT: capStyle = OS.NSButtLineCapStyle; break; |
320 case DWT.CAP_SQUARE: capStyle = OS.NSSquareLineCapStyle; break; | 345 case DWT.CAP_SQUARE: capStyle = OS.NSSquareLineCapStyle; break; |
321 } | 346 } |
322 path.setLineCapStyle(capStyle); | 347 path.setLineCapStyle(cast(objc.id_) capStyle); |
323 } | 348 } |
324 if ((state & DRAW_OFFSET) !is 0) { | 349 if ((state & DRAW_OFFSET) !is 0) { |
325 data.drawXOffset = data.drawYOffset = 0; | 350 data.drawXOffset = data.drawYOffset = 0; |
326 NSSize size = new NSSize(); | 351 NSSize size = NSSize(); |
327 size.width = size.height = 1; | 352 size.width = size.height = 1; |
328 if (data.transform !is null) { | 353 if (data.transform !is null) { |
329 size = data.transform.transformSize(size); | 354 size = data.transform.transformSize(size); |
330 } | 355 } |
331 float scaling = size.width; | 356 CGFloat scaling = size.width; |
332 if (scaling < 0) scaling = -scaling; | 357 if (scaling < 0) scaling = -scaling; |
333 float strokeWidth = data.lineWidth * scaling; | 358 CGFloat strokeWidth = data.lineWidth * scaling; |
334 if (strokeWidth is 0 || (cast(int)strokeWidth % 2) is 1) { | 359 if (strokeWidth is 0 || (cast(size_t)strokeWidth % 2) is 1) { |
335 data.drawXOffset = 0.5f / scaling; | 360 data.drawXOffset = 0.5f / scaling; |
336 } | 361 } |
337 scaling = size.height; | 362 scaling = size.height; |
338 if (scaling < 0) scaling = -scaling; | 363 if (scaling < 0) scaling = -scaling; |
339 strokeWidth = data.lineWidth * scaling; | 364 strokeWidth = data.lineWidth * scaling; |
340 if (strokeWidth is 0 || (cast(int)strokeWidth % 2) is 1) { | 365 if (strokeWidth is 0 || (cast(size_t)strokeWidth % 2) is 1) { |
341 data.drawYOffset = 0.5f / scaling; | 366 data.drawYOffset = 0.5f / scaling; |
342 } | 367 } |
343 } | 368 } |
344 } | 369 } |
345 | 370 |
613 // } | 638 // } |
614 } | 639 } |
615 | 640 |
616 NSAttributedString createString(String string, int flags) { | 641 NSAttributedString createString(String string, int flags) { |
617 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); | 642 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); |
618 float[] foreground = data.foreground; | 643 CGFloat[] foreground = data.foreground; |
619 NSColor color = NSColor.colorWithDeviceRed(foreground[0], foreground[1], foreground[2], data.alpha / 255f); | 644 NSColor color = NSColor.colorWithDeviceRed(foreground[0], foreground[1], foreground[2], data.alpha / 255f); |
620 dict.setObject(color, OS.NSForegroundColorAttributeName()); | 645 dict.setObject(color, OS.NSForegroundColorAttributeName()); |
621 dict.setObject(data.font.handle, OS.NSFontAttributeName()); | 646 dict.setObject(data.font.handle, OS.NSFontAttributeName()); |
622 if ((flags & DWT.DRAW_TRANSPARENT) is 0) { | 647 if ((flags & DWT.DRAW_TRANSPARENT) is 0) { |
623 float[] background = data.background; | 648 CGFloat[] background = data.background; |
624 color = NSColor.colorWithDeviceRed(background[0], background[1], background[2], data.alpha / 255f); | 649 color = NSColor.colorWithDeviceRed(background[0], background[1], background[2], data.alpha / 255f); |
625 dict.setObject(color, OS.NSBackgroundColorAttributeName()); | 650 dict.setObject(color, OS.NSBackgroundColorAttributeName()); |
626 } | 651 } |
627 int length = string.length(); | 652 size_t length = string.length(); |
628 char[] chars = new char[length]; | 653 char[] chars = new char[length]; |
629 string.getChars(0, length, chars, 0); | 654 string.getChars(0, length, chars, 0); |
630 // int breakCount = 0; | 655 // int breakCount = 0; |
631 // int[] breaks = null; | 656 // int[] breaks = null; |
632 // if ((flags & (DWT.DRAW_MNEMONIC | DWT.DRAW_DELIMITER)) !is 0) { | 657 // if ((flags & (DWT.DRAW_MNEMONIC | DWT.DRAW_DELIMITER)) !is 0) { |
660 // } | 685 // } |
661 // } | 686 // } |
662 // } | 687 // } |
663 // length = j; | 688 // length = j; |
664 // } | 689 // } |
665 NSString str = NSString.stringWithCharacters(chars, length); | 690 NSString str = NSString.stringWithCharacters(chars.toCharArray().ptr, length); |
666 return (cast(NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict); | 691 return (cast(NSAttributedString)(new NSAttributedString()).alloc()).initWithString_attributes_(str, dict); |
667 } | 692 } |
668 | 693 |
669 void destroy() { | 694 void destroy() { |
670 /* Free resources */ | 695 /* Free resources */ |
671 Image image = data.image; | 696 Image image = data.image; |
678 if (data.inverseTransform !is null) data.inverseTransform.release(); | 703 if (data.inverseTransform !is null) data.inverseTransform.release(); |
679 data.path = data.clipPath = null; | 704 data.path = data.clipPath = null; |
680 data.transform = data.inverseTransform = null; | 705 data.transform = data.inverseTransform = null; |
681 | 706 |
682 /* Dispose the GC */ | 707 /* Dispose the GC */ |
683 if (drawable !is null) drawable.internal_dispose_GC(handle.id, data); | 708 if (drawable !is null) drawable.internal_dispose_GC(handle.id_, data); |
684 handle.restoreGraphicsState(); | 709 handle.restoreGraphicsState(); |
685 handle.release(); | 710 handle.release(); |
686 | 711 |
687 drawable = null; | 712 drawable = null; |
688 data.image = null; | 713 data.image = null; |
733 height = -height; | 758 height = -height; |
734 } | 759 } |
735 if (width is 0 || height is 0 || arcAngle is 0) return; | 760 if (width is 0 || height is 0 || arcAngle is 0) return; |
736 handle.saveGraphicsState(); | 761 handle.saveGraphicsState(); |
737 NSAffineTransform transform = NSAffineTransform.transform(); | 762 NSAffineTransform transform = NSAffineTransform.transform(); |
738 float xOffset = data.drawXOffset, yOffset = data.drawYOffset; | 763 CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset; |
739 transform.translateXBy(x + xOffset + width / 2f, y + yOffset + height / 2f); | 764 transform.translateXBy(x + xOffset + width / 2f, y + yOffset + height / 2f); |
740 transform.scaleXBy(width / 2f, height / 2f); | 765 transform.scaleXBy(width / 2f, height / 2f); |
741 NSBezierPath path = data.path; | 766 NSBezierPath path = data.path; |
742 NSPoint center = new NSPoint(); | 767 NSPoint center = NSPoint(); |
743 float sAngle = -startAngle; | 768 CGFloat sAngle = -startAngle; |
744 float eAngle = -(startAngle + arcAngle); | 769 CGFloat eAngle = -(startAngle + arcAngle); |
745 path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_clockwise_(center, 1, sAngle, eAngle, arcAngle>0); | 770 path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_clockwise_(center, 1, sAngle, eAngle, arcAngle>0); |
746 path.transformUsingAffineTransform(transform); | 771 path.transformUsingAffineTransform(transform); |
747 path.stroke(); | 772 path.stroke(); |
748 path.removeAllPoints(); | 773 path.removeAllPoints(); |
749 handle.restoreGraphicsState(); | 774 handle.restoreGraphicsState(); |
877 handle.saveGraphicsState(); | 902 handle.saveGraphicsState(); |
878 NSAffineTransform transform = NSAffineTransform.transform(); | 903 NSAffineTransform transform = NSAffineTransform.transform(); |
879 transform.scaleXBy(1, -1); | 904 transform.scaleXBy(1, -1); |
880 transform.translateXBy(0, -(destHeight + 2 * destY)); | 905 transform.translateXBy(0, -(destHeight + 2 * destY)); |
881 transform.concat(); | 906 transform.concat(); |
882 NSRect srcRect = new NSRect(); | 907 NSRect srcRect = NSRect(); |
883 srcRect.x = srcX; | 908 srcRect.x = srcX; |
884 srcRect.y = srcY; | 909 srcRect.y = srcY; |
885 srcRect.width = srcWidth; | 910 srcRect.width = srcWidth; |
886 srcRect.height = srcHeight; | 911 srcRect.height = srcHeight; |
887 NSRect destRect = new NSRect(); | 912 NSRect destRect = NSRect(); |
888 destRect.x = destX; | 913 destRect.x = destX; |
889 destRect.y = destY; | 914 destRect.y = destY; |
890 destRect.width = destWidth; | 915 destRect.width = destWidth; |
891 destRect.height = destHeight; | 916 destRect.height = destHeight; |
892 imageHandle.drawInRect(destRect, srcRect, OS.NSCompositeSourceOver, 1); | 917 imageHandle.drawInRect(destRect, srcRect, OS.NSCompositeSourceOver, 1); |
911 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 936 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
912 NSGraphicsContext context = NSGraphicsContext.currentContext(); | 937 NSGraphicsContext context = NSGraphicsContext.currentContext(); |
913 NSGraphicsContext.setCurrentContext(handle); | 938 NSGraphicsContext.setCurrentContext(handle); |
914 checkGC(DRAW); | 939 checkGC(DRAW); |
915 NSBezierPath path = data.path; | 940 NSBezierPath path = data.path; |
916 NSPoint pt = new NSPoint(); | 941 NSPoint pt = NSPoint(); |
917 pt.x = x1 + data.drawXOffset; | 942 pt.x = x1 + data.drawXOffset; |
918 pt.y = y1 + data.drawYOffset; | 943 pt.y = y1 + data.drawYOffset; |
919 path.moveToPoint(pt); | 944 path.moveToPoint(pt); |
920 pt.x = x2 + data.drawXOffset; | 945 pt.x = x2 + data.drawXOffset; |
921 pt.y = y2 + data.drawYOffset; | 946 pt.y = y2 + data.drawYOffset; |
958 if (height < 0) { | 983 if (height < 0) { |
959 y = y + height; | 984 y = y + height; |
960 height = -height; | 985 height = -height; |
961 } | 986 } |
962 NSBezierPath path = data.path; | 987 NSBezierPath path = data.path; |
963 NSRect rect = new NSRect(); | 988 NSRect rect = NSRect(); |
964 rect.x = x + data.drawXOffset; | 989 rect.x = x + data.drawXOffset; |
965 rect.y = y + data.drawXOffset; | 990 rect.y = y + data.drawXOffset; |
966 rect.width = width; | 991 rect.width = width; |
967 rect.height = height; | 992 rect.height = height; |
968 path.appendBezierPathWithOvalInRect(rect); | 993 path.appendBezierPathWithOvalInRect(rect); |
1033 public void drawPoint(int x, int y) { | 1058 public void drawPoint(int x, int y) { |
1034 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 1059 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
1035 NSGraphicsContext context = NSGraphicsContext.currentContext(); | 1060 NSGraphicsContext context = NSGraphicsContext.currentContext(); |
1036 NSGraphicsContext.setCurrentContext(handle); | 1061 NSGraphicsContext.setCurrentContext(handle); |
1037 checkGC(FOREGROUND_FILL); | 1062 checkGC(FOREGROUND_FILL); |
1038 NSRect rect = new NSRect(); | 1063 NSRect rect = NSRect(); |
1039 rect.x = x; | 1064 rect.x = x; |
1040 rect.y = y; | 1065 rect.y = y; |
1041 rect.width = 1; | 1066 rect.width = 1; |
1042 rect.height = 1; | 1067 rect.height = 1; |
1043 NSBezierPath path = data.path; | 1068 NSBezierPath path = data.path; |
1069 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 1094 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
1070 NSGraphicsContext context = NSGraphicsContext.currentContext(); | 1095 NSGraphicsContext context = NSGraphicsContext.currentContext(); |
1071 NSGraphicsContext.setCurrentContext(handle); | 1096 NSGraphicsContext.setCurrentContext(handle); |
1072 checkGC(DRAW); | 1097 checkGC(DRAW); |
1073 if (pointArray.length < 4) return; | 1098 if (pointArray.length < 4) return; |
1074 float xOffset = data.drawXOffset, yOffset = data.drawYOffset; | 1099 CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset; |
1075 NSBezierPath path = data.path; | 1100 NSBezierPath path = data.path; |
1076 NSPoint pt = new NSPoint(); | 1101 NSPoint pt = NSPoint(); |
1077 pt.x = pointArray[0] + xOffset; | 1102 pt.x = pointArray[0] + xOffset; |
1078 pt.y = pointArray[1] + yOffset; | 1103 pt.y = pointArray[1] + yOffset; |
1079 path.moveToPoint(pt); | 1104 path.moveToPoint(pt); |
1080 int end = pointArray.length / 2 * 2; | 1105 int end = pointArray.length / 2 * 2; |
1081 for (int i = 2; i < end; i+=2) { | 1106 for (int i = 2; i < end; i+=2) { |
1111 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 1136 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
1112 NSGraphicsContext context = NSGraphicsContext.currentContext(); | 1137 NSGraphicsContext context = NSGraphicsContext.currentContext(); |
1113 NSGraphicsContext.setCurrentContext(handle); | 1138 NSGraphicsContext.setCurrentContext(handle); |
1114 checkGC(DRAW); | 1139 checkGC(DRAW); |
1115 if (pointArray.length < 4) return; | 1140 if (pointArray.length < 4) return; |
1116 float xOffset = data.drawXOffset, yOffset = data.drawYOffset; | 1141 CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset; |
1117 NSBezierPath path = data.path; | 1142 NSBezierPath path = data.path; |
1118 NSPoint pt = new NSPoint(); | 1143 NSPoint pt = NSPoint(); |
1119 pt.x = pointArray[0] + xOffset; | 1144 pt.x = pointArray[0] + xOffset; |
1120 pt.y = pointArray[1] + yOffset; | 1145 pt.y = pointArray[1] + yOffset; |
1121 path.moveToPoint(pt); | 1146 path.moveToPoint(pt); |
1122 int end = pointArray.length / 2 * 2; | 1147 int end = pointArray.length / 2 * 2; |
1123 for (int i = 2; i < end; i+=2) { | 1148 for (int i = 2; i < end; i+=2) { |
1156 } | 1181 } |
1157 if (height < 0) { | 1182 if (height < 0) { |
1158 y = y + height; | 1183 y = y + height; |
1159 height = -height; | 1184 height = -height; |
1160 } | 1185 } |
1161 NSRect rect = new NSRect(); | 1186 NSRect rect = NSRect(); |
1162 rect.x = x + data.drawXOffset; | 1187 rect.x = x + data.drawXOffset; |
1163 rect.y = y + data.drawYOffset; | 1188 rect.y = y + data.drawYOffset; |
1164 rect.width = width; | 1189 rect.width = width; |
1165 rect.height = height; | 1190 rect.height = height; |
1166 NSBezierPath path = data.path; | 1191 NSBezierPath path = data.path; |
1222 drawRectangle(x, y, width, height); | 1247 drawRectangle(x, y, width, height); |
1223 NSGraphicsContext.setCurrentContext(context); | 1248 NSGraphicsContext.setCurrentContext(context); |
1224 return; | 1249 return; |
1225 } | 1250 } |
1226 NSBezierPath path = data.path; | 1251 NSBezierPath path = data.path; |
1227 NSRect rect = new NSRect(); | 1252 NSRect rect = NSRect(); |
1228 rect.x = x + data.drawXOffset; | 1253 rect.x = x + data.drawXOffset; |
1229 rect.y = y + data.drawYOffset; | 1254 rect.y = y + data.drawYOffset; |
1230 rect.width = width; | 1255 rect.width = width; |
1231 rect.height = height; | 1256 rect.height = height; |
1232 path.appendBezierPathWithRoundedRect(rect, arcWidth, arcHeight); | 1257 path.appendBezierPathWithRoundedRect(rect, arcWidth, arcHeight); |
1375 NSAffineTransform transform = NSAffineTransform.transform(); | 1400 NSAffineTransform transform = NSAffineTransform.transform(); |
1376 transform.scaleXBy(1, -1); | 1401 transform.scaleXBy(1, -1); |
1377 transform.translateXBy(0, -(str.size().height + 2 * y)); | 1402 transform.translateXBy(0, -(str.size().height + 2 * y)); |
1378 transform.concat(); | 1403 transform.concat(); |
1379 } | 1404 } |
1380 NSPoint pt = new NSPoint(); | 1405 NSPoint pt = NSPoint(); |
1381 pt.x = x; | 1406 pt.x = x; |
1382 pt.y = y; | 1407 pt.y = y; |
1383 str.drawAtPoint(pt); | 1408 str.drawAtPoint(pt); |
1384 str.release(); | 1409 str.release(); |
1385 if (data.paintRect is null) { | 1410 if (data.paintRect is null) { |
1396 * @param object the object to compare with this object | 1421 * @param object the object to compare with this object |
1397 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | 1422 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise |
1398 * | 1423 * |
1399 * @see #hashCode | 1424 * @see #hashCode |
1400 */ | 1425 */ |
1401 public bool equals(Object object) { | 1426 public bool opEquals(Object object) { |
1402 if (object is this) return true; | 1427 if (object is this) return true; |
1403 if (!( null !is cast(GC)object )) return false; | 1428 if (!( null !is cast(GC)object )) return false; |
1404 return handle is (cast(GC)object).handle; | 1429 return handle is (cast(GC)object).handle; |
1405 } | 1430 } |
1431 | |
1432 alias opEquals equals; | |
1406 | 1433 |
1407 /** | 1434 /** |
1408 * Fills the interior of a circular or elliptical arc within | 1435 * Fills the interior of a circular or elliptical arc within |
1409 * the specified rectangular area, with the receiver's background | 1436 * the specified rectangular area, with the receiver's background |
1410 * color. | 1437 * color. |
1450 height = -height; | 1477 height = -height; |
1451 } | 1478 } |
1452 if (width is 0 || height is 0 || arcAngle is 0) return; | 1479 if (width is 0 || height is 0 || arcAngle is 0) return; |
1453 handle.saveGraphicsState(); | 1480 handle.saveGraphicsState(); |
1454 NSAffineTransform transform = NSAffineTransform.transform(); | 1481 NSAffineTransform transform = NSAffineTransform.transform(); |
1455 float xOffset = data.drawXOffset, yOffset = data.drawYOffset; | 1482 CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset; |
1456 transform.translateXBy(x + xOffset + width / 2f, y + yOffset + height / 2f); | 1483 transform.translateXBy(x + xOffset + width / 2f, y + yOffset + height / 2f); |
1457 transform.scaleXBy(width / 2f, height / 2f); | 1484 transform.scaleXBy(width / 2f, height / 2f); |
1458 NSBezierPath path = data.path; | 1485 NSBezierPath path = data.path; |
1459 NSPoint center = new NSPoint(); | 1486 NSPoint center = NSPoint(); |
1460 path.moveToPoint(center); | 1487 path.moveToPoint(center); |
1461 float sAngle = -startAngle; | 1488 CGFloat sAngle = -startAngle; |
1462 float eAngle = -(startAngle + arcAngle); | 1489 CGFloat eAngle = -(startAngle + arcAngle); |
1463 path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_clockwise_(center, 1, sAngle, eAngle, arcAngle>0); | 1490 path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_clockwise_(center, 1, sAngle, eAngle, arcAngle>0); |
1464 path.closePath(); | 1491 path.closePath(); |
1465 path.transformUsingAffineTransform(transform); | 1492 path.transformUsingAffineTransform(transform); |
1466 path.fill(); | 1493 path.fill(); |
1467 path.removeAllPoints(); | 1494 path.removeAllPoints(); |
1519 if (fromRGB.equals(toRGB)) { | 1546 if (fromRGB.equals(toRGB)) { |
1520 fillRectangle(x, y, width, height); | 1547 fillRectangle(x, y, width, height); |
1521 } else { | 1548 } else { |
1522 NSColor startingColor = NSColor.colorWithDeviceRed(fromRGB.red / 255f, fromRGB.green / 255f, fromRGB.blue / 255f, data.alpha / 255f); | 1549 NSColor startingColor = NSColor.colorWithDeviceRed(fromRGB.red / 255f, fromRGB.green / 255f, fromRGB.blue / 255f, data.alpha / 255f); |
1523 NSColor endingColor = NSColor.colorWithDeviceRed(toRGB.red / 255f, toRGB.green / 255f, toRGB.blue / 255f, data.alpha / 255f); | 1550 NSColor endingColor = NSColor.colorWithDeviceRed(toRGB.red / 255f, toRGB.green / 255f, toRGB.blue / 255f, data.alpha / 255f); |
1524 NSGradient gradient = (cast(NSGradient)new NSGradient().alloc()).initWithStartingColor(startingColor, endingColor); | 1551 NSGradient gradient = (cast(NSGradient)(new NSGradient()).alloc()).initWithStartingColor(startingColor, endingColor); |
1525 NSRect rect = new NSRect(); | 1552 NSRect rect = NSRect(); |
1526 rect.x = x; | 1553 rect.x = x; |
1527 rect.y = y; | 1554 rect.y = y; |
1528 rect.width = width; | 1555 rect.width = width; |
1529 rect.height = height; | 1556 rect.height = height; |
1530 gradient.drawInRect_angle_(rect, vertical ? 90 : 0); | 1557 gradient.drawInRect_angle_(rect, vertical ? 90 : 0); |
1561 if (height < 0) { | 1588 if (height < 0) { |
1562 y = y + height; | 1589 y = y + height; |
1563 height = -height; | 1590 height = -height; |
1564 } | 1591 } |
1565 NSBezierPath path = data.path; | 1592 NSBezierPath path = data.path; |
1566 NSRect rect = new NSRect(); | 1593 NSRect rect = NSRect(); |
1567 rect.x = x; | 1594 rect.x = x; |
1568 rect.y = y; | 1595 rect.y = y; |
1569 rect.width = width; | 1596 rect.width = width; |
1570 rect.height = height; | 1597 rect.height = height; |
1571 path.appendBezierPathWithOvalInRect(rect); | 1598 path.appendBezierPathWithOvalInRect(rect); |
1654 NSGraphicsContext context = NSGraphicsContext.currentContext(); | 1681 NSGraphicsContext context = NSGraphicsContext.currentContext(); |
1655 NSGraphicsContext.setCurrentContext(handle); | 1682 NSGraphicsContext.setCurrentContext(handle); |
1656 checkGC(FILL); | 1683 checkGC(FILL); |
1657 if (pointArray.length < 4) return; | 1684 if (pointArray.length < 4) return; |
1658 NSBezierPath path = data.path; | 1685 NSBezierPath path = data.path; |
1659 NSPoint pt = new NSPoint(); | 1686 NSPoint pt = NSPoint(); |
1660 pt.x = pointArray[0]; | 1687 pt.x = pointArray[0]; |
1661 pt.y = pointArray[1]; | 1688 pt.y = pointArray[1]; |
1662 path.moveToPoint(pt); | 1689 path.moveToPoint(pt); |
1663 int end = pointArray.length / 2 * 2; | 1690 int end = pointArray.length / 2 * 2; |
1664 for (int i = 2; i < end; i+=2) { | 1691 for (int i = 2; i < end; i+=2) { |
1703 } | 1730 } |
1704 if (height < 0) { | 1731 if (height < 0) { |
1705 y = y + height; | 1732 y = y + height; |
1706 height = -height; | 1733 height = -height; |
1707 } | 1734 } |
1708 NSRect rect = new NSRect(); | 1735 NSRect rect = NSRect(); |
1709 rect.x = x; | 1736 rect.x = x; |
1710 rect.y = y; | 1737 rect.y = y; |
1711 rect.width = width; | 1738 rect.width = width; |
1712 rect.height = height; | 1739 rect.height = height; |
1713 NSBezierPath path = data.path; | 1740 NSBezierPath path = data.path; |
1768 if (arcWidth is 0 || arcHeight is 0) { | 1795 if (arcWidth is 0 || arcHeight is 0) { |
1769 fillRectangle(x, y, width, height); | 1796 fillRectangle(x, y, width, height); |
1770 return; | 1797 return; |
1771 } | 1798 } |
1772 NSBezierPath path = data.path; | 1799 NSBezierPath path = data.path; |
1773 NSRect rect = new NSRect(); | 1800 NSRect rect = NSRect(); |
1774 rect.x = x; | 1801 rect.x = x; |
1775 rect.y = y; | 1802 rect.y = y; |
1776 rect.width = width; | 1803 rect.width = width; |
1777 rect.height = height; | 1804 rect.height = height; |
1778 path.appendBezierPathWithRoundedRect(rect, arcWidth, arcHeight); | 1805 path.appendBezierPathWithRoundedRect(rect, arcWidth, arcHeight); |
1805 * </ul> | 1832 * </ul> |
1806 */ | 1833 */ |
1807 public int getAdvanceWidth(char ch) { | 1834 public int getAdvanceWidth(char ch) { |
1808 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 1835 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
1809 //NOT DONE | 1836 //NOT DONE |
1810 return stringExtent(new String(new char[]{ch})).x; | 1837 return stringExtent(new char[][ch]).x; |
1811 } | 1838 } |
1812 | 1839 |
1813 /** | 1840 /** |
1814 * Returns the background color. | 1841 * Returns the background color. |
1815 * | 1842 * |
1927 * </ul> | 1954 * </ul> |
1928 */ | 1955 */ |
1929 public int getCharWidth(char ch) { | 1956 public int getCharWidth(char ch) { |
1930 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 1957 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
1931 //NOT DONE | 1958 //NOT DONE |
1932 return stringExtent(new String(new char[]{ch})).x; | 1959 return stringExtent(new char[][ch]).x; |
1933 } | 1960 } |
1934 | 1961 |
1935 /** | 1962 /** |
1936 * Returns the bounding rectangle of the receiver's clipping | 1963 * Returns the bounding rectangle of the receiver's clipping |
1937 * region. If no clipping region is set, the return value | 1964 * region. If no clipping region is set, the return value |
1944 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | 1971 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> |
1945 * </ul> | 1972 * </ul> |
1946 */ | 1973 */ |
1947 public Rectangle getClipping() { | 1974 public Rectangle getClipping() { |
1948 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 1975 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
1949 NSRect rect = null; | 1976 NSRect rect = void; |
1950 if (data.view !is null) { | 1977 if (data.view !is null) { |
1951 rect = data.view.bounds(); | 1978 rect = data.view.bounds(); |
1952 } else { | 1979 } else { |
1953 rect = new NSRect(); | 1980 rect = NSRect(); |
1954 if (data.image !is null) { | 1981 if (data.image !is null) { |
1955 NSSize size = data.image.handle.size(); | 1982 NSSize size = data.image.handle.size(); |
1956 rect.width = size.width; | 1983 rect.width = size.width; |
1957 rect.height = size.height; | 1984 rect.height = size.height; |
1958 } else if (data.size !is null) { | 1985 } else if (data.size !is null) { |
1967 if (data.clipPath !is null) { | 1994 if (data.clipPath !is null) { |
1968 NSRect clip = data.clipPath.bounds(); | 1995 NSRect clip = data.clipPath.bounds(); |
1969 OS.NSIntersectionRect(rect, rect, clip); | 1996 OS.NSIntersectionRect(rect, rect, clip); |
1970 } | 1997 } |
1971 if (data.inverseTransform !is null && rect.width > 0 && rect.height > 0) { | 1998 if (data.inverseTransform !is null && rect.width > 0 && rect.height > 0) { |
1972 NSPoint pt = new NSPoint(); | 1999 NSPoint pt = NSPoint(); |
1973 pt.x = rect.x; | 2000 pt.x = rect.x; |
1974 pt.y = rect.y; | 2001 pt.y = rect.y; |
1975 NSSize size = new NSSize(); | 2002 NSSize size = NSSize(); |
1976 size.width = rect.width; | 2003 size.width = rect.width; |
1977 size.height = rect.height; | 2004 size.height = rect.height; |
1978 pt = data.inverseTransform.transformPoint(pt); | 2005 pt = data.inverseTransform.transformPoint(pt); |
1979 size = data.inverseTransform.transformSize(size); | 2006 size = data.inverseTransform.transformSize(size); |
1980 rect.x = pt.x; | 2007 rect.x = pt.x; |
2003 public void getClipping(Region region) { | 2030 public void getClipping(Region region) { |
2004 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 2031 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
2005 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 2032 if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
2006 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 2033 if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
2007 region.subtract(region); | 2034 region.subtract(region); |
2008 NSRect rect = null; | 2035 NSRect rect = void; |
2009 if (data.view !is null) { | 2036 if (data.view !is null) { |
2010 rect = data.view.bounds(); | 2037 rect = data.view.bounds(); |
2011 } else { | 2038 } else { |
2012 rect = new NSRect(); | 2039 rect = NSRect(); |
2013 if (data.image !is null) { | 2040 if (data.image !is null) { |
2014 NSSize size = data.image.handle.size(); | 2041 NSSize size = data.image.handle.size(); |
2015 rect.width = size.width; | 2042 rect.width = size.width; |
2016 rect.height = size.height; | 2043 rect.height = size.height; |
2017 } else if (data.size !is null) { | 2044 } else if (data.size !is null) { |
2028 NSBezierPath clip = data.clipPath.bezierPathByFlatteningPath(); | 2055 NSBezierPath clip = data.clipPath.bezierPathByFlatteningPath(); |
2029 int count = clip.elementCount(); | 2056 int count = clip.elementCount(); |
2030 int pointCount = 0; | 2057 int pointCount = 0; |
2031 Region clipRgn = new Region(device); | 2058 Region clipRgn = new Region(device); |
2032 int[] pointArray = new int[count * 2]; | 2059 int[] pointArray = new int[count * 2]; |
2033 int points = OS.malloc(NSPoint.sizeof); | 2060 NSPointArray points = cast(NSPointArray) OS.malloc(NSPoint.sizeof); |
2034 if (points is 0) DWT.error(DWT.ERROR_NO_HANDLES); | 2061 if (points is null) DWT.error(DWT.ERROR_NO_HANDLES); |
2035 NSPoint pt = new NSPoint(); | 2062 NSPoint pt = NSPoint(); |
2036 for (int i = 0; i < count; i++) { | 2063 for (NSInteger i = 0; i < count; i++) { |
2037 int element = clip.elementAtIndex_associatedPoints_(i, points); | 2064 NSBezierPathElement element = clip.elementAtIndex_associatedPoints_(i, points); |
2038 switch (element) { | 2065 switch (element) { |
2039 case OS.NSMoveToBezierPathElement: | 2066 case OS.NSMoveToBezierPathElement: |
2040 if (pointCount !is 0) clipRgn.add(pointArray, pointCount); | 2067 if (pointCount !is 0) clipRgn.add(pointArray, pointCount); |
2041 pointCount = 0; | 2068 pointCount = 0; |
2042 OS.memmove(pt, points, NSPoint.sizeof); | 2069 OS.memmove(pt, points, NSPoint.sizeof); |
2212 * | 2239 * |
2213 * @since 3.3 | 2240 * @since 3.3 |
2214 */ | 2241 */ |
2215 public LineAttributes getLineAttributes() { | 2242 public LineAttributes getLineAttributes() { |
2216 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 2243 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
2217 float[] dashes = null; | 2244 CGFloat[] dashes = null; |
2218 if (data.lineDashes !is null) { | 2245 if (data.lineDashes !is null) { |
2219 dashes = new float[data.lineDashes.length]; | 2246 dashes = new CGFloat[data.lineDashes.length]; |
2220 System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length); | 2247 System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length); |
2221 } | 2248 } |
2222 return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit); | 2249 return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit); |
2223 } | 2250 } |
2224 | 2251 |
2380 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 2407 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
2381 if (transform is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 2408 if (transform is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
2382 if (transform.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 2409 if (transform.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
2383 NSAffineTransform cmt = data.transform; | 2410 NSAffineTransform cmt = data.transform; |
2384 if (cmt !is null) { | 2411 if (cmt !is null) { |
2385 NSAffineTransformStruct struct = cmt.transformStruct(); | 2412 NSAffineTransformStruct structt = cmt.transformStruct(); |
2386 transform.handle.setTransformStruct(struct); | 2413 transform.handle.setTransformStruct(structt); |
2387 } else { | 2414 } else { |
2388 transform.setElements(1, 0, 0, 1, 0, 0); | 2415 transform.setElements(1, 0, 0, 1, 0, 0); |
2389 } | 2416 } |
2390 } | 2417 } |
2391 | 2418 |
2420 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | 2447 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> |
2421 * </ul> | 2448 * </ul> |
2422 * | 2449 * |
2423 * @see #equals | 2450 * @see #equals |
2424 */ | 2451 */ |
2425 public int hashCode() { | 2452 public hash_t toHash() { |
2426 return handle !is null ? handle.id : 0; | 2453 return handle !is null ? handle.id_ : 0; |
2427 } | 2454 } |
2428 | 2455 |
2429 void init(Drawable drawable, GCData data, int context) { | 2456 alias toHash hashCode; |
2457 | |
2458 void init(Drawable drawable, GCData data, objc.id context) { | |
2430 if (data.foreground !is null) data.state &= ~(FOREGROUND | FOREGROUND_FILL); | 2459 if (data.foreground !is null) data.state &= ~(FOREGROUND | FOREGROUND_FILL); |
2431 if (data.background !is null) data.state &= ~BACKGROUND; | 2460 if (data.background !is null) data.state &= ~BACKGROUND; |
2432 if (data.font !is null) data.state &= ~FONT; | 2461 if (data.font !is null) data.state &= ~FONT; |
2433 data.state &= ~DRAW_OFFSET; | 2462 data.state &= ~DRAW_OFFSET; |
2434 | 2463 |
2688 } | 2717 } |
2689 if (height < 0) { | 2718 if (height < 0) { |
2690 y = y + height; | 2719 y = y + height; |
2691 height = -height; | 2720 height = -height; |
2692 } | 2721 } |
2693 NSRect rect = new NSRect(); | 2722 NSRect rect = NSRect(); |
2694 rect.x = x; | 2723 rect.x = x; |
2695 rect.y = y; | 2724 rect.y = y; |
2696 rect.width = width; | 2725 rect.width = width; |
2697 rect.height = height; | 2726 rect.height = height; |
2698 NSBezierPath path = NSBezierPath.bezierPathWithRect(rect); | 2727 NSBezierPath path = NSBezierPath.bezierPathWithRect(rect); |
2727 * @since 3.1 | 2756 * @since 3.1 |
2728 */ | 2757 */ |
2729 public void setClipping(Path path) { | 2758 public void setClipping(Path path) { |
2730 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 2759 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
2731 if (path !is null && path.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 2760 if (path !is null && path.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
2732 setClipping(new NSBezierPath(path.handle.copy().id)); | 2761 setClipping(new NSBezierPath(path.handle.copy().id_)); |
2733 } | 2762 } |
2734 | 2763 |
2735 /** | 2764 /** |
2736 * Sets the area of the receiver which can be changed | 2765 * Sets the area of the receiver which can be changed |
2737 * by drawing operations to the rectangular area specified | 2766 * by drawing operations to the rectangular area specified |
2813 case DWT.FILL_EVEN_ODD: break; | 2842 case DWT.FILL_EVEN_ODD: break; |
2814 default: | 2843 default: |
2815 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 2844 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
2816 } | 2845 } |
2817 data.fillRule = rule; | 2846 data.fillRule = rule; |
2818 data.path.setWindingRule(rule is DWT.FILL_WINDING ? OS.NSNonZeroWindingRule : OS.NSEvenOddWindingRule); | 2847 data.path.setWindingRule(rule is DWT.FILL_WINDING ? cast(objc.id) OS.NSNonZeroWindingRule : cast(objc.id) OS.NSEvenOddWindingRule); |
2819 } | 2848 } |
2820 | 2849 |
2821 /** | 2850 /** |
2822 * Sets the font which will be used by the receiver | 2851 * Sets the font which will be used by the receiver |
2823 * to draw and measure text to the argument. If the | 2852 * to draw and measure text to the argument. If the |
2920 * | 2949 * |
2921 * @since 3.1 | 2950 * @since 3.1 |
2922 */ | 2951 */ |
2923 public void setInterpolation(int interpolation) { | 2952 public void setInterpolation(int interpolation) { |
2924 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 2953 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
2925 int quality = 0; | 2954 NSImageInterpolation quality = 0; |
2926 switch (interpolation) { | 2955 switch (interpolation) { |
2927 case DWT.DEFAULT: quality = OS.NSImageInterpolationDefault; break; | 2956 case DWT.DEFAULT: quality = OS.NSImageInterpolationDefault; break; |
2928 case DWT.NONE: quality = OS.NSImageInterpolationNone; break; | 2957 case DWT.NONE: quality = OS.NSImageInterpolationNone; break; |
2929 case DWT.LOW: quality = OS.NSImageInterpolationLow; break; | 2958 case DWT.LOW: quality = OS.NSImageInterpolationLow; break; |
2930 case DWT.HIGH: quality = OS.NSImageInterpolationHigh; break; | 2959 case DWT.HIGH: quality = OS.NSImageInterpolationHigh; break; |
2960 */ | 2989 */ |
2961 public void setLineAttributes(LineAttributes attributes) { | 2990 public void setLineAttributes(LineAttributes attributes) { |
2962 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 2991 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
2963 if (attributes is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 2992 if (attributes is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
2964 int mask = 0; | 2993 int mask = 0; |
2965 float lineWidth = attributes.width; | 2994 CGFloat lineWidth = attributes.width; |
2966 if (lineWidth !is data.lineWidth) { | 2995 if (lineWidth !is data.lineWidth) { |
2967 mask |= LINE_WIDTH | DRAW_OFFSET; | 2996 mask |= LINE_WIDTH | DRAW_OFFSET; |
2968 } | 2997 } |
2969 int lineStyle = attributes.style; | 2998 int lineStyle = attributes.style; |
2970 if (lineStyle !is data.lineStyle) { | 2999 if (lineStyle !is data.lineStyle) { |
3005 break; | 3034 break; |
3006 default: | 3035 default: |
3007 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 3036 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
3008 } | 3037 } |
3009 } | 3038 } |
3010 float[] dashes = attributes.dash; | 3039 CGFloat[] dashes = attributes.dash; |
3011 float[] lineDashes = data.lineDashes; | 3040 CGFloat[] lineDashes = data.lineDashes; |
3012 if (dashes !is null && dashes.length > 0) { | 3041 if (dashes !is null && dashes.length > 0) { |
3013 bool changed = lineDashes is null || lineDashes.length !is dashes.length; | 3042 bool changed = lineDashes is null || lineDashes.length !is dashes.length; |
3014 for (int i = 0; i < dashes.length; i++) { | 3043 for (int i = 0; i < dashes.length; i++) { |
3015 float dash = dashes[i]; | 3044 float dash = dashes[i]; |
3016 if (dash <= 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 3045 if (dash <= 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
3017 if (!changed && lineDashes[i] !is dash) changed = true; | 3046 if (!changed && lineDashes[i] !is dash) changed = true; |
3018 } | 3047 } |
3019 if (changed) { | 3048 if (changed) { |
3020 float[] newDashes = new float[dashes.length]; | 3049 CGFloat[] newDashes = new CGFloat[dashes.length]; |
3021 System.arraycopy(dashes, 0, newDashes, 0, dashes.length); | 3050 System.arraycopy(dashes, 0, newDashes, 0, dashes.length); |
3022 dashes = newDashes; | 3051 dashes = newDashes; |
3023 mask |= LINE_STYLE; | 3052 mask |= LINE_STYLE; |
3024 } else { | 3053 } else { |
3025 dashes = lineDashes; | 3054 dashes = lineDashes; |
3029 mask |= LINE_STYLE; | 3058 mask |= LINE_STYLE; |
3030 } else { | 3059 } else { |
3031 dashes = lineDashes; | 3060 dashes = lineDashes; |
3032 } | 3061 } |
3033 } | 3062 } |
3034 float dashOffset = attributes.dashOffset; | 3063 CGFloat dashOffset = attributes.dashOffset; |
3035 if (dashOffset !is data.lineDashesOffset) { | 3064 if (dashOffset !is data.lineDashesOffset) { |
3036 mask |= LINE_STYLE; | 3065 mask |= LINE_STYLE; |
3037 } | 3066 } |
3038 float miterLimit = attributes.miterLimit; | 3067 float miterLimit = attributes.miterLimit; |
3039 if (miterLimit !is data.lineMiterLimit) { | 3068 if (miterLimit !is data.lineMiterLimit) { |
3098 * | 3127 * |
3099 * @since 3.1 | 3128 * @since 3.1 |
3100 */ | 3129 */ |
3101 public void setLineDash(int[] dashes) { | 3130 public void setLineDash(int[] dashes) { |
3102 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 3131 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
3103 float[] lineDashes = data.lineDashes; | 3132 CGFloat[] lineDashes = data.lineDashes; |
3104 if (dashes !is null && dashes.length > 0) { | 3133 if (dashes !is null && dashes.length > 0) { |
3105 bool changed = data.lineStyle !is DWT.LINE_CUSTOM || lineDashes is null || lineDashes.length !is dashes.length; | 3134 bool changed = data.lineStyle !is DWT.LINE_CUSTOM || lineDashes is null || lineDashes.length !is dashes.length; |
3106 for (int i = 0; i < dashes.length; i++) { | 3135 for (int i = 0; i < dashes.length; i++) { |
3107 int dash = dashes[i]; | 3136 int dash = dashes[i]; |
3108 if (dash <= 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 3137 if (dash <= 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
3109 if (!changed && lineDashes[i] !is dash) changed = true; | 3138 if (!changed && lineDashes[i] !is dash) changed = true; |
3110 } | 3139 } |
3111 if (!changed) return; | 3140 if (!changed) return; |
3112 data.lineDashes = new float[dashes.length]; | 3141 data.lineDashes = new CGFloat[dashes.length]; |
3113 for (int i = 0; i < dashes.length; i++) { | 3142 for (int i = 0; i < dashes.length; i++) { |
3114 data.lineDashes[i] = dashes[i]; | 3143 data.lineDashes[i] = dashes[i]; |
3115 } | 3144 } |
3116 data.lineStyle = DWT.LINE_CUSTOM; | 3145 data.lineStyle = DWT.LINE_CUSTOM; |
3117 } else { | 3146 } else { |
3310 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 3339 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
3311 if (transform !is null && transform.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 3340 if (transform !is null && transform.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
3312 if (transform !is null) { | 3341 if (transform !is null) { |
3313 if (data.transform !is null) data.transform.release(); | 3342 if (data.transform !is null) data.transform.release(); |
3314 if (data.inverseTransform !is null) data.inverseTransform.release(); | 3343 if (data.inverseTransform !is null) data.inverseTransform.release(); |
3315 data.transform = (cast(NSAffineTransform)new NSAffineTransform().alloc()).initWithTransform(transform.handle); | 3344 data.transform = (cast(NSAffineTransform)(new NSAffineTransform()).alloc()).initWithTransform(transform.handle); |
3316 data.inverseTransform = (cast(NSAffineTransform)new NSAffineTransform().alloc()).initWithTransform(transform.handle); | 3345 data.inverseTransform = (cast(NSAffineTransform)(new NSAffineTransform()).alloc()).initWithTransform(transform.handle); |
3317 NSAffineTransformStruct struct = data.inverseTransform.transformStruct(); | 3346 NSAffineTransformStruct structt = data.inverseTransform.transformStruct(); |
3318 if ((struct.m11 * struct.m22 - struct.m12 * struct.m21) !is 0) { | 3347 if ((structt.m11 * structt.m22 - structt.m12 * structt.m21) !is 0) { |
3319 data.inverseTransform.invert(); | 3348 data.inverseTransform.invert(); |
3320 } | 3349 } |
3321 } else { | 3350 } else { |
3322 data.transform = data.inverseTransform = null; | 3351 data.transform = data.inverseTransform = null; |
3323 } | 3352 } |
3416 * | 3445 * |
3417 * @return a string representation of the receiver | 3446 * @return a string representation of the receiver |
3418 */ | 3447 */ |
3419 public String toString () { | 3448 public String toString () { |
3420 if (isDisposed()) return "GC {*DISPOSED*}"; | 3449 if (isDisposed()) return "GC {*DISPOSED*}"; |
3421 return "GC {" + handle + "}"; | 3450 return Format("GC {{}{}" , handle , "}"); |
3422 } | 3451 } |
3423 | 3452 |
3424 } | 3453 } |