public
Description: A simple tutorial project for Cocoa / Objective-C
Homepage: http://stompy.org
Clone URL: git://github.com/Abizern/sobezier.git
StompyDotOrg (author)
Wed Jul 30 00:53:43 -0700 2008
commit  7427e2d6a8e416b8a4adbfd58c04ba6bd1239035
tree    10f3b4dd76883186d7266d91da298e99ff72171f
parent  d3a8e9c3a83ed0dcd4bec48b2d1edb07e52b6201
sobezier / SOBezierCurve.m
aaacb876 » StompyDotOrg 2008-07-29 Basic working version. 1 //
2 // SOBezierCurve.m
3 // SOBezier
4 //
5
6 #import "SOBezierCurve.h"
7
8
9 @implementation SOBezierCurve
10 @synthesize pt1, pt2, ControlPt1, ControlPt2;
11
12 - (id) init
13 {
14 // This just calls the designated initialiser with zero points.
7427e2d6 » StompyDotOrg 2008-07-30 Corrected the initialisers ... 15 [self initWithPt1:NSZeroPoint
16 Pt2:NSZeroPoint
17 ControlPt1:NSZeroPoint
18 ControlPt2:NSZeroPoint];
aaacb876 » StompyDotOrg 2008-07-29 Basic working version. 19 return self;
20 }
21
22 - (id)initWithPt1:(NSPoint)point1
23 Pt2:(NSPoint)point2
24 ControlPt1:(NSPoint)cPoint1
25 ControlPt2:(NSPoint)cPoint2
26 {
27 // Designated initialiser.
7427e2d6 » StompyDotOrg 2008-07-30 Corrected the initialisers ... 28 if (![super init]) {
29 return nil;
30 }
aaacb876 » StompyDotOrg 2008-07-29 Basic working version. 31 pt1 = point1;
32 pt2 = point2;
33 ControlPt1 = cPoint1;
34 ControlPt2 = cPoint2;
35
36 return self;
37 }
38
39 - (void)drawCurve
40 {
41 NSBezierPath *path = [NSBezierPath bezierPath];
42 // Move to the first control point
43 [path moveToPoint:ControlPt1];
44 // Add a line from the control point to the first point of the curve
45 [path lineToPoint:pt1];
46 // Create the curve
47 [path curveToPoint:pt2 controlPoint1:ControlPt1 controlPoint2:ControlPt2];
48 // Draw a line from the end of the curve to the second control point
49 [path lineToPoint:ControlPt2];
50
51 // Now draw the curve
52 [[NSColor blackColor] set];
53 [path stroke];
54 }
55
56
57 @end