0

I have 2 bezierPath. On a first path I draw grid. I handle mouse event and draw new path on first path. I use appendBezierPath, that's all ok, but style of second path don't copy. Cocoa use first path style. How can I append new bezier path with new style. As example, I draw black grid and I want draw red circle in second path.

UPD:

- (void)drawRect:(NSRect)dirtyRect {
    NSRect bounds = [self bounds];
    NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
    [backgroundColor set];
    NSRectFill(bounds);

    [lineColor set];
    for(NSUInteger i = 30; i < NSMaxX(bounds); i += 60) {
        [path moveToPoint: (NSPoint) {i, 0}];
        [path lineToPoint: (NSPoint) {i, NSMaxY(bounds)}];
        for(NSUInteger j = 30; j < NSMaxY(bounds); j += 60) {
            [path moveToPoint: (NSPoint) {0, j}];
            [path lineToPoint: (NSPoint) {NSMaxX(bounds), j}];
        }
    }
    [NSGraphicsContext saveGraphicsState];
    [path stroke];
    [currentContext restoreGraphicsState];
}

- (void)setDeniedPoint:(NSPoint)point {
    NSBezierPath *newPath = [NSBezierPath bezierPath];
    [deniedPointColor set];
    [newPath setLineWidth:3.0f];
    [newPath moveToPoint:(NSPoint) {point.x-4, point.y-4}];
    [newPath lineToPoint:(NSPoint) {point.x+4, point.y+4}];
    [newPath moveToPoint:(NSPoint) {point.x-4, point.y+4}];
    [newPath lineToPoint:(NSPoint) {point.x+4, point.y-4}];
    [path appendBezierPath:newPath];
    [self setNeedsDisplay:YES];
}

- (void)mouseDown:(NSEvent *)event {
    NSPoint currentLocationCursor = [self convertPoint:[event locationInWindow] fromView:nil];
    [self setDeniedPoint:currentLocationCursor];
}
Lee Twelve
  • 65
  • 8

0 Answers0