1//
2//  PXPattern.m
3//  Pixen-XCode
4//
5//  Created by Ian Henderson on 07.10.04.
6//  Copyright 2004 Open Sword Group. All rights reserved.
7//
8
9#import "PXPattern.h"
10
11
12@implementation PXPattern
13
14
15- (void)addPoints:(NSArray *)points
16{
17	[self setColor:[NSColor blackColor] atPoints:points];
18}
19
20- (void)addPoint:(NSPoint)point
21{
22	[self setColor:[NSColor blackColor] atPoint:point];
23}
24
25- (NSArray *)pointsInPattern
26{
27	NSMutableArray *points = [NSMutableArray array];
28	int x, y, z;
29	for (x=0; x<[self size].width; x++) {
30		for (y=0; y<[self size].height; y++) {
31			for (z=0; z<[[self layers] count]; z++) {
32				if ([[[[self layers] objectAtIndex:z] colorAtPoint:NSMakePoint(x, y)] alphaComponent] > .5) {
33					[points addObject:[NSValue valueWithPoint:NSMakePoint(x, y)]];
34				}
35			}
36		}
37	}
38	return points;
39}
40
41- (void)drawRect:(NSRect)rect fixBug:(BOOL)fixBug // this is slow, but patterns are very small.
42{
43	NSEnumerator *pointsEnumerator = [[self pointsInPattern] objectEnumerator];
44	NSValue *point;
45	[[NSColor blackColor] set];
46	while ( ( point = [pointsEnumerator nextObject]) ) {
47		NSRectFill(NSMakeRect([point pointValue].x, [point pointValue].y, 1, 1));
48	}
49}
50
51@end
52