1//
2//  PXGrid.m
3//  Pixen-XCode
4//
5//  Created by Andy Matuschak on Wed Mar 17 2004.
6//  Copyright (c) 2004 Open Sword Group. All rights reserved.
7//
8
9#import "PXGrid.h"
10#ifndef __COCOA__
11#import <AppKit/NSGraphicsContext.h>
12#import <AppKit/NSBezierPath.h>
13#endif
14
15@implementation PXGrid
16
17- initWithUnitSize:(NSSize)newUnitSize color:newColor shouldDraw:(BOOL)newShouldDraw;
18{
19	[super init];
20	[self setUnitSize:newUnitSize];
21	[self setColor:newColor];
22	[self setShouldDraw:newShouldDraw];
23	return self;
24}
25
26- (void)drawRect:(NSRect)drawingRect
27{
28	if (!shouldDraw) { return; }
29	NSSize dimensions = drawingRect.size;
30	int i;
31	float lineWidth;
32    BOOL oldShouldAntialias = [[NSGraphicsContext currentContext] shouldAntialias];
33	[[NSGraphicsContext currentContext] setShouldAntialias:NO];
34	lineWidth = [NSBezierPath defaultLineWidth];
35	[NSBezierPath setDefaultLineWidth:0];
36	[color set];
37	for (i = 0; i < dimensions.width + unitSize.width; i+=unitSize.width)
38	{
39		[NSBezierPath strokeLineFromPoint:NSMakePoint(i, 0) toPoint:NSMakePoint(i, dimensions.height)];
40	}
41	for (i = 0; i < dimensions.height + unitSize.width; i+=unitSize.height)
42	{
43		[NSBezierPath strokeLineFromPoint:NSMakePoint(0, i) toPoint:NSMakePoint(dimensions.width, i)];
44	}
45	[NSBezierPath setDefaultLineWidth:lineWidth];
46	[[NSGraphicsContext currentContext] setShouldAntialias:oldShouldAntialias];
47}
48
49- (NSSize)unitSize
50{
51	return unitSize;
52}
53
54- color
55{
56	return color;
57}
58
59- (BOOL)shouldDraw
60{
61	return shouldDraw;
62}
63
64- (void)setShouldDraw:(BOOL)newShouldDraw
65{
66	shouldDraw = newShouldDraw;
67}
68
69- (void)setColor:newColor
70{
71	color = newColor;
72}
73
74- (void)setUnitSize:(NSSize)newUnitSize
75{
76	unitSize = newUnitSize;
77}
78
79@end
80