I am making a simple drawing app and am using NSBezierPath
to draw the lines. I am subclassing NSView
. I need to make a method which allows the user to change the color and size of the next path (so the user presses a button, then the next time they draw a path it is the specified color/size) but right now when I try doing that it changes the color and size of all EXISTING paths. How can I make them "individual", so to speak? Here is my code:
- (void)drawRect:(NSRect)dirtyRect
{
[path setLineWidth:5];
[path setLineJoinStyle:NSRoundLineJoinStyle];
[path setLineCapStyle:NSRoundLineCapStyle];
[path stroke];
}
- (void)mouseDown:(NSEvent *)theEvent {
NSPoint location = [theEvent locationInWindow];
NSLog(@"%f, %f", location.x, location.y);
[path moveToPoint:location];
[self setNeedsDisplay:YES];
}
- (void)mouseUp:(NSEvent *)theEvent {
}
- (void)mouseDragged:(NSEvent *)theEvent {
NSPoint location = [theEvent locationInWindow];
[path lineToPoint:location];
[self setNeedsDisplay:YES];
}
- (void)changeBrushColor:(NSString *)color {
// change color of the next path
[self setNeedsDisplay:YES]; // show it
}
So I need to make a individual NSBezierPath paths.