0

私は2つのbezierPathを持っています。最初のパスでは、グリッドを描画します。マウス イベントを処理し、最初のパスに新しいパスを描画します。私は appendBezierPath を使用しています。これで問題ありませんが、2 番目のパスのスタイルがコピーされません。Cocoa は最初のパス スタイルを使用します。新しいスタイルで新しいベジエ パスを追加するにはどうすればよいですか。例として、黒いグリッドを描画し、2 番目のパスに赤い円を描画します。

更新:

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

0 に答える 0