1//  PXSlashyBackground.m
2//  Pixen
3//
4//  Created by Joe Osborn on Thu Sep 18 2003.
5//  Copyright (c) 2003 Open Sword Group. All rights reserved.
6//
7
8#import "PXSlashyBackground.h"
9
10
11@implementation PXSlashyBackground
12
13- defaultName
14{
15    return NSLocalizedString(@"SLASHED_BACKGROUND", @"Slashed Background");
16}
17
18- (void)drawBackgroundLinesInRect:(NSRect)aRect
19{
20
21
22
23    //rounding off the values in aRect... we can't have them being floating points, can we?
24    NSRect rect = NSMakeRect((int)(aRect.origin.x), (int)(aRect.origin.y), (int)(aRect.size.width), (int)(aRect.size.height));
25    float oldWidth = [NSBezierPath defaultLineWidth];
26    BOOL oldShouldAntialias = [[NSGraphicsContext currentContext] shouldAntialias];
27    [[NSGraphicsContext currentContext] setShouldAntialias:NO];
28    [NSBezierPath setDefaultLineWidth:10];
29
30#ifdef __COCOA__
31    [color set];
32#else
33    [[colorWell color] set];
34#endif
35    int higherOrigin = (int)((rect.size.width >= rect.size.height) ? rect.origin.x : rect.origin.y);
36    int higherDimension = 2*(int)((rect.size.width >= rect.size.height) ? rect.size.width : rect.size.height);
37    int i = (int)(higherOrigin-higherDimension);
38    while(i < (higherOrigin+higherDimension))
39    {
40        NSPoint startPoint = NSMakePoint(i-20, rect.origin.y-20);
41        NSPoint endPoint = NSMakePoint(i+2*rect.size.width+20, rect.origin.y+2*rect.size.width+20);
42        if(rect.size.height > rect.size.width)
43        {
44            startPoint = NSMakePoint(rect.origin.x-20, i-20);
45            endPoint = NSMakePoint(rect.origin.x+2*rect.size.height+20, i+2*rect.size.height+20);
46        }
47        NSAssert(endPoint.x-startPoint.x == endPoint.y-startPoint.y, @"Bad points!");
48        [NSBezierPath strokeLineFromPoint:startPoint toPoint:endPoint];
49        i+=33;
50    }
51    [NSBezierPath setDefaultLineWidth:oldWidth];
52    [[NSGraphicsContext currentContext] setShouldAntialias:oldShouldAntialias];
53}
54
55- (void)drawRect:(NSRect)rect withinRect:(NSRect)wholeRect
56{
57#ifdef __COCOA__
58    [backColor set];
59#else
60    [[backWell color] set];
61#endif
62
63    NSRectFill(wholeRect);
64    [self drawBackgroundLinesInRect:wholeRect];
65}
66
67@end
68