NSBezierPath and setLineWidth (stupid ?) question
NSBezierPath and setLineWidth (stupid ?) question
- Subject: NSBezierPath and setLineWidth (stupid ?) question
- From: Laurent Charbonnel <email@hidden>
- Date: Wed, 05 Sep 2001 17:58:51 -0700
I have a very simple drawRect method of a custom view that draws a grid :
- (void)drawRect:(NSRect)rect {
// Drawing code here.
float x,y;
NSBezierPath *gridPath = [NSBezierPath bezierPath];
[[NSColor redColor] set];
[gridPath setLineWidth:2.0];
for(x = _drawingRect.origin.x; x <=
_drawingRect.origin.x+_drawingRect.size.width; x += _gridSpacing.width) {
[gridPath moveToPoint:NSMakePoint(x, _drawingRect.origin.y)];
[gridPath lineToPoint:NSMakePoint(x,
_drawingRect.origin.y+_drawingRect.size.height)];
}
for(y = _drawingRect.origin.y; y <=
_drawingRect.origin.y+_drawingRect.size.height; y +=
_gridSpacing.height) {
[gridPath moveToPoint:NSMakePoint(_drawingRect.origin.x, y)];
[gridPath
lineToPoint:NSMakePoint(_drawingRect.origin.x+_drawingRect.size.width,
y)];
}
[gridPath stroke];
}
If the value for the line width is even, nothing is drawn, but it works
for odd values.
Also, if I add before the stroke command:
[gridPath
lineToPoint:NSMakePoint(_drawingRect.origin.x+_drawingRect.size.width,
_drawingRect.origin.y+_drawingRect.size.height+1)];
then it works for all the values that I have tried.
What am I doing wrong ?
Thanks, Laurent.