1//
2//  PXCrosshair.m
3//  Pixen-XCode
4//
5//  Created by Ian Henderson on Fri Jun 11 2004.
6//  Copyright (c) 2004 Open Sword Group. All rights reserved.
7//
8
9#import "PXCrosshair.h"
10#ifndef __COCOA__
11#import <AppKit/NSGraphicsContext.h>
12#import <AppKit/NSBezierPath.h>
13#import <AppKit/NSColor.h>
14#endif
15
16@implementation PXCrosshair
17
18
19- (void)drawRect:(NSRect)drawingRect
20{
21	if (![self shouldDraw]) { return; }
22	NSSize dimensions = drawingRect.size;
23	float lineWidth;
24    BOOL oldShouldAntialias = [[NSGraphicsContext currentContext] shouldAntialias];
25	[[NSGraphicsContext currentContext] setShouldAntialias:NO];
26	lineWidth = [NSBezierPath defaultLineWidth];
27	[NSBezierPath setDefaultLineWidth:0];
28	[[self color] set];
29	[NSBezierPath strokeLineFromPoint:NSMakePoint(cursorPosition.x, 0) toPoint:NSMakePoint(cursorPosition.x, dimensions.height)];
30	[NSBezierPath strokeLineFromPoint:NSMakePoint(0, cursorPosition.y) toPoint:NSMakePoint(dimensions.width, cursorPosition.y)];
31	[NSBezierPath strokeLineFromPoint:NSMakePoint(cursorPosition.x+1, 0) toPoint:NSMakePoint(cursorPosition.x+1, dimensions.height)];
32	[NSBezierPath strokeLineFromPoint:NSMakePoint(0, cursorPosition.y+1) toPoint:NSMakePoint(dimensions.width, cursorPosition.y+1)];
33	[NSBezierPath setDefaultLineWidth:lineWidth];
34	[[NSGraphicsContext currentContext] setShouldAntialias:oldShouldAntialias];
35}
36
37- color
38{
39	NSData *colorData = [[NSUserDefaults standardUserDefaults] objectForKey:@"PXCrosshairColor"];
40	if (colorData == nil) {
41		colorData = [NSArchiver archivedDataWithRootObject:[NSColor redColor]];
42		[[NSUserDefaults standardUserDefaults] setObject:colorData forKey:@"PXCrosshairColor"];
43	}
44	return [NSUnarchiver unarchiveObjectWithData:colorData];
45}
46- (BOOL)shouldDraw
47{
48	return [[NSUserDefaults standardUserDefaults] boolForKey:@"PXCrosshairEnabled"];
49}
50
51- (NSPoint)cursorPosition
52{
53	return cursorPosition;
54}
55
56- (void)setCursorPosition:(NSPoint)position
57{
58	cursorPosition = position;
59}
60
61@end
62