//  Created by Joe Becker on 3/7/05.
//  Copyright 2005 __MyCompanyName__. All rights reserved.

#import "Tick.h"

@implementation Tick

const float halfWidthInPixels = 3.;

- initFrom:(NSPoint)theStart to:(NSPoint)theEnd view:(id)theView record:(GmtShipTrackRecord *)obj
{
	[super initFrom:theStart to:theEnd view:theView record:obj];
	
	NSSize tmp2 = [view convertSize:NSMakeSize(halfWidthInPixels, halfWidthInPixels) fromView:nil];
	dx = tmp2.width;
	dy = tmp2.height;
	
	return self;
}

- (NSRect)bounds
{
	NSSize tmp2 = [view convertSize:NSMakeSize(halfWidthInPixels, halfWidthInPixels) fromView:nil];
	dx = tmp2.width;
	dy = tmp2.height;
	
	NSPoint origin = [self end];
	NSRect tmp = NSMakeRect(origin.x, origin.y, dx, dy);
	
	const float sloppyCoding = -1.; //FIXME: AppKit(???) has an "off by one" bug, leaves turds...
	
	return NSIntegralRect(
						  NSInsetRect(tmp, sloppyCoding, sloppyCoding)
						  );
}

- (void)stroke
{	
	NSPoint origin = [self end];
	//FIXME: need to use NSString to draw ticks...
	NSPoint left = NSMakePoint(origin.x-dx, origin.y-dy);
	NSPoint right= NSMakePoint(origin.x+dx, origin.y+dy);
	NSPoint top  = NSMakePoint(origin.x-dx, origin.y+dy);
	NSPoint bot  = NSMakePoint(origin.x+dx, origin.y-dy);
	
	[color set];
	[NSBezierPath strokeLineFromPoint:top  toPoint:bot];
	[NSBezierPath strokeLineFromPoint:left toPoint:right];
}

@synthesize dy;
@synthesize dx;
@end
