appendBezierPath,具有第二个路径的样式

时间:2014-03-23 12:48:34

标签: objective-c cocoa nsbezierpath

我有2个bezierPath。在第一条路径上我绘制网格。我处理鼠标事件并在第一条路径上绘制新路径。我使用appendBezierPath,这一切都没问题,但第二条路径的样式不会复制。 Cocoa使用第一种路径样式。如何添加新风格的新bezier路径。 例如,我绘制黑色网格,我想在第二条路径中绘制红色圆圈。

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];
}

0 个答案:

没有答案