-4

I have to draw lines few times. I do this now:

- (void)drawRect:(NSRect)dirtyRect
    {
        [NSGraphicsContext saveGraphicsState];
        NSBezierPath *path = [NSBezierPath bezierPath];
        [path moveToPoint:point];

        [[NSColor blackColor] set];

        [path lineToPoint:point2];
        [path stroke];
        [NSGraphicsContext restoreGraphicsState];
    }

And i call this from other class many time with other parameters:

    [workspace setPoint1:someValue setPoint2:someOtherValue];
    [workspace setNeedsDisplay:YES];

What i need?

I call this few times with changing parameters someValue and someOtherValue and I have to draw all lines and I want to see it. Now i see only last path. Where is the problem? How can i do this correctly?

Thank you.

4

1 回答 1

2

If you want to draw more than one line, you'll need to... well... draw more than one line.

You'll need to come up with some way of storing all of the line segments that you want to draw, not just the most recent one. (Use NSMutableArray for this.) Once you've got that, you'll need to loop through that array and draw each line.

于 2013-01-27T00:47:02.990 回答