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