comparison dwt/graphics/Path.d @ 36:db5a898b2119

Fixed a lot of compile errors
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Tue, 07 Oct 2008 12:56:18 +0200
parents 5123b17c98ef
children d8635bb48c7c
comparison
equal deleted inserted replaced
35:7d135fe0caf2 36:db5a898b2119
38 import dwt.graphics.GCData; 38 import dwt.graphics.GCData;
39 import dwt.graphics.PathData; 39 import dwt.graphics.PathData;
40 import dwt.graphics.Resource; 40 import dwt.graphics.Resource;
41 import dwt.internal.cocoa.CGFloat; 41 import dwt.internal.cocoa.CGFloat;
42 import dwt.internal.cocoa.NSFont : NSGlyph; 42 import dwt.internal.cocoa.NSFont : NSGlyph;
43 import dwt.internal.cocoa.NSInteger;
43 44
44 /** 45 /**
45 * Instances of this class represent paths through the two-dimensional 46 * Instances of this class represent paths through the two-dimensional
46 * coordinate system. Paths do not have to be continuous, and can be 47 * coordinate system. Paths do not have to be continuous, and can be
47 * described using lines, rectangles, arcs, cubic or quadratic bezier curves, 48 * described using lines, rectangles, arcs, cubic or quadratic bezier curves,
57 * </p> 58 * </p>
58 * 59 *
59 * @since 3.1 60 * @since 3.1
60 */ 61 */
61 public class Path : Resource { 62 public class Path : Resource {
63
64 alias Resource.init_ init_;
62 65
63 /** 66 /**
64 * the OS resource for the Path 67 * the OS resource for the Path
65 * (Warning: This field is platform dependent) 68 * (Warning: This field is platform dependent)
66 * <p> 69 * <p>
98 super(device); 101 super(device);
99 handle = NSBezierPath.bezierPath(); 102 handle = NSBezierPath.bezierPath();
100 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); 103 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
101 handle.retain(); 104 handle.retain();
102 handle.moveToPoint(NSPoint()); 105 handle.moveToPoint(NSPoint());
103 init(); 106 init_();
104 } 107 }
105 108
106 public this (Device device, Path path, float flatness) { 109 public this (Device device, Path path, float flatness) {
107 super(device); 110 super(device);
108 if (path is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 111 if (path is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
115 NSBezierPath.setDefaultFlatness(flatness); 118 NSBezierPath.setDefaultFlatness(flatness);
116 handle = path.handle.bezierPathByFlatteningPath(); 119 handle = path.handle.bezierPathByFlatteningPath();
117 NSBezierPath.setDefaultFlatness(defaultFlatness); 120 NSBezierPath.setDefaultFlatness(defaultFlatness);
118 } 121 }
119 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); 122 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
120 init(); 123 init_();
121 } 124 }
122 125
123 public this (Device device, PathData data) { 126 public this (Device device, PathData data) {
124 this(device); 127 this(device);
125 if (data is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 128 if (data is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
126 init(data); 129 init_(data);
127 } 130 }
128 131
129 /** 132 /**
130 * Adds to the receiver a circular or elliptical arc that lies within 133 * Adds to the receiver a circular or elliptical arc that lies within
131 * the specified rectangular area. 134 * the specified rectangular area.
248 textStorage.beginEditing(); 251 textStorage.beginEditing();
249 textStorage.addAttribute(OS.NSFontAttributeName(), font.handle, range); 252 textStorage.addAttribute(OS.NSFontAttributeName(), font.handle, range);
250 textStorage.endEditing(); 253 textStorage.endEditing();
251 range = layoutManager.glyphRangeForTextContainer(textContainer); 254 range = layoutManager.glyphRangeForTextContainer(textContainer);
252 if (range.length !is 0) { 255 if (range.length !is 0) {
253 NSGlyph* glyphs = OS.malloc(4 * range.length * 2); 256 NSGlyph* glyphs = cast(NSGlyph*) OS.malloc(4 * range.length * 2);
254 layoutManager.getGlyphs(glyphs, range); 257 layoutManager.getGlyphs(glyphs, range);
255 NSBezierPath path = NSBezierPath.bezierPath(); 258 NSBezierPath path = NSBezierPath.bezierPath();
256 NSPoint point = NSPoint(); 259 NSPoint point = NSPoint();
257 point.x = x; 260 point.x = x;
258 point.y = y; 261 point.y = y;
416 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 419 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
417 int count = handle.elementCount(); 420 int count = handle.elementCount();
418 int pointCount = 0, typeCount = 0; 421 int pointCount = 0, typeCount = 0;
419 byte[] types = new byte[count]; 422 byte[] types = new byte[count];
420 float[] pointArray = new float[count * 6]; 423 float[] pointArray = new float[count * 6];
421 NSPointArray points = OS.malloc(3 * NSPoint.sizeof); 424 NSPointArray points = cast(NSPointArray) OS.malloc(3 * NSPoint.sizeof);
422 if (points is 0) DWT.error(DWT.ERROR_NO_HANDLES); 425 if (points is null) DWT.error(DWT.ERROR_NO_HANDLES);
423 NSPoint pt = NSPoint(); 426 NSPoint pt = NSPoint();
424 for (NSInteger i = 0; i < count; i++) { 427 for (NSInteger i = 0; i < count; i++) {
425 NSBezierPathElement element = handle.elementAtIndex_associatedPoints_(i, points); 428 NSBezierPathElement element = handle.elementAtIndex_associatedPoints_(i, points);
426 switch (element) { 429 switch (element) {
427 case OS.NSMoveToBezierPathElement: 430 case NSMoveToBezierPathElement:
428 types[typeCount++] = DWT.PATH_MOVE_TO; 431 types[typeCount++] = DWT.PATH_MOVE_TO;
429 OS.memmove(pt, points, NSPoint.sizeof); 432 OS.memmove(&pt, points, NSPoint.sizeof);
430 pointArray[pointCount++] = cast(int)pt.x; 433 pointArray[pointCount++] = cast(int)pt.x;
431 pointArray[pointCount++] = cast(int)pt.y; 434 pointArray[pointCount++] = cast(int)pt.y;
432 break; 435 break;
433 case OS.NSLineToBezierPathElement: 436 case NSLineToBezierPathElement:
434 types[typeCount++] = DWT.PATH_LINE_TO; 437 types[typeCount++] = DWT.PATH_LINE_TO;
435 OS.memmove(pt, points, NSPoint.sizeof); 438 OS.memmove(&pt, points, NSPoint.sizeof);
436 pointArray[pointCount++] = cast(int)pt.x; 439 pointArray[pointCount++] = cast(int)pt.x;
437 pointArray[pointCount++] = cast(int)pt.y; 440 pointArray[pointCount++] = cast(int)pt.y;
438 break; 441 break;
439 case OS.NSCurveToBezierPathElement: 442 case NSCurveToBezierPathElement:
440 types[typeCount++] = DWT.PATH_CUBIC_TO; 443 types[typeCount++] = DWT.PATH_CUBIC_TO;
441 OS.memmove(pt, points, NSPoint.sizeof); 444 OS.memmove(&pt, points, NSPoint.sizeof);
442 pointArray[pointCount++] = cast(int)pt.x; 445 pointArray[pointCount++] = cast(int)pt.x;
443 pointArray[pointCount++] = cast(int)pt.y; 446 pointArray[pointCount++] = cast(int)pt.y;
444 OS.memmove(pt, points + NSPoint.sizeof, NSPoint.sizeof); 447 OS.memmove(&pt, points + NSPoint.sizeof, NSPoint.sizeof);
445 pointArray[pointCount++] = cast(int)pt.x; 448 pointArray[pointCount++] = cast(int)pt.x;
446 pointArray[pointCount++] = cast(int)pt.y; 449 pointArray[pointCount++] = cast(int)pt.y;
447 OS.memmove(pt, points + NSPoint.sizeof + NSPoint.sizeof, NSPoint.sizeof); 450 OS.memmove(&pt, points + NSPoint.sizeof + NSPoint.sizeof, NSPoint.sizeof);
448 pointArray[pointCount++] = cast(int)pt.x; 451 pointArray[pointCount++] = cast(int)pt.x;
449 pointArray[pointCount++] = cast(int)pt.y; 452 pointArray[pointCount++] = cast(int)pt.y;
450 break; 453 break;
451 case OS.NSClosePathBezierPathElement: 454 case NSClosePathBezierPathElement:
452 types[typeCount++] = DWT.PATH_CLOSE; 455 types[typeCount++] = DWT.PATH_CLOSE;
453 break; 456 break;
454 } 457 }
455 } 458 }
456 OS.free(points); 459 OS.free(points);
463 data.types = types; 466 data.types = types;
464 data.points = pointArray; 467 data.points = pointArray;
465 return data; 468 return data;
466 } 469 }
467 470
468 void init(PathData data) { 471 void init_(PathData data) {
469 byte[] types = data.types; 472 byte[] types = data.types;
470 float[] points = data.points; 473 float[] points = data.points;
471 for (int i = 0, j = 0; i < types.length; i++) { 474 for (int i = 0, j = 0; i < types.length; i++) {
472 switch (types[i]) { 475 switch (types[i]) {
473 case DWT.PATH_MOVE_TO: 476 case DWT.PATH_MOVE_TO: