Hello, I am trying to draw in a grid in a NSScrollView, it works fine when the scrollView is resized, however, if the view contained within the NSScrollView changes size, and you then scroll, the view doesn't get redrawn correctly, and only part of the grid draws. Here's my code:
}
On a side note, if I use path -fill, it won't draw.
Code:
#define kGridSpace 15.0f
#define kGridLineSize 0.3f
- (void)drawRect:(NSRect)rect {
// Our path
NSBezierPath *path = [NSBezierPath bezierPath];
// The scale factor
CGFloat scaleFactor = [window userSpaceScaleFactor];
// The y beginning and end coords
CGFloat dypoint = 0.0;
CGFloat eypoint = rect.size.height * scaleFactor;
// the x beginning and end coords
CGFloat dxpoint = 0.0;
CGFloat expoint = rect.size.width * scaleFactor;
[[NSColor whiteColor] setStroke];
[path setLineWidth:kGridLineSize];
BOOL continueDrawing = TRUE;
while (continueDrawing) {
// Create our line.
[path moveToPoint:NSMakePoint(0.0f, dypoint)];
[path lineToPoint:NSMakePoint(expoint, dypoint)];
[path closePath];
// Add our drawing point reference
dypoint += kGridSpace;
// Are we done drawing?
if (dypoint > eypoint)
continueDrawing = FALSE;
}
continueDrawing = TRUE;
while (continueDrawing) {
// Create our line.
[path moveToPoint:NSMakePoint(dxpoint, 0.0f)];
[path lineToPoint:NSMakePoint(dxpoint, eypoint)];
[path closePath];
// Add our drawing point reference
dxpoint += kGridSpace;
// Are we done drawing?
if (dxpoint > expoint)
continueDrawing = FALSE;
}
[path stroke];
On a side note, if I use path -fill, it won't draw.